forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRooTrace.cxx
More file actions
313 lines (219 loc) · 8.79 KB
/
RooTrace.cxx
File metadata and controls
313 lines (219 loc) · 8.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*****************************************************************************
* Project: RooFit *
* Package: RooFitCore *
* @(#)root/roofitcore:$Id$
* Authors: *
* WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
* DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
* *
* Copyright (c) 2000-2005, Regents of the University of California *
* and Stanford University. All rights reserved. *
* *
* Redistribution and use in source and binary forms, *
* with or without modification, are permitted according to the terms *
* listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
*****************************************************************************/
/**
\file RooTrace.cxx
\class RooTrace
\ingroup Roofitcore
Class RooTrace controls the memory tracing hooks in all RooFit
objects. When tracing is active, a table of live RooFit objects
is kept that can be queried at any time. In verbose mode, messages
are printed in addition at the construction and destruction of
each object.
**/
#include "RooFit.h"
#include "RooTrace.h"
#include "RooAbsArg.h"
#include "Riostream.h"
#include "RooMsgService.h"
#include <iomanip>
#include "TClass.h"
using namespace std;
ClassImp(RooTrace);
;
RooTrace* RooTrace::_instance=0 ;
////////////////////////////////////////////////////////////////////////////////
RooTrace& RooTrace::instance()
{
if (_instance==0) _instance = new RooTrace() ;
return *_instance ;
}
////////////////////////////////////////////////////////////////////////////////
RooTrace::RooTrace() : _active(kFALSE), _verbose(kFALSE)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Register creation of object 'obj'
void RooTrace::create(const TObject* obj)
{
RooTrace& instance = RooTrace::instance() ;
if (instance._active) {
instance.create3(obj) ;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Register deletion of object 'obj'
void RooTrace::destroy(const TObject* obj)
{
RooTrace& instance = RooTrace::instance() ;
if (instance._active) {
instance.destroy3(obj) ;
}
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::createSpecial(const char* name, int size)
{
RooTrace& instance = RooTrace::instance() ;
if (instance._active) {
instance.createSpecial3(name,size) ;
}
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::destroySpecial(const char* name)
{
RooTrace& instance = RooTrace::instance() ;
if (instance._active) {
instance.destroySpecial3(name) ;
}
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::createSpecial3(const char* name, int size)
{
_specialCount[name]++ ;
_specialSize[name] = size ;
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::destroySpecial3(const char* name)
{
_specialCount[name]-- ;
}
////////////////////////////////////////////////////////////////////////////////
/// If flag is true, memory tracing is activated
void RooTrace::active(Bool_t flag)
{
RooTrace::instance()._active = flag ;
}
////////////////////////////////////////////////////////////////////////////////
/// If flag is true, a message will be printed at each
/// object creation or deletion
void RooTrace::verbose(Bool_t flag)
{
RooTrace::instance()._verbose = flag ;
}
////////////////////////////////////////////////////////////////////////////////
/// Back end function of create(), register creation of object 'obj'
void RooTrace::create2(const TObject* obj)
{
_list.Add((RooAbsArg*)obj) ;
if (_verbose) {
cout << "RooTrace::create: object " << obj << " of type " << obj->ClassName()
<< " created " << endl ;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Back end function of destroy(), register deletion of object 'obj'
void RooTrace::destroy2(const TObject* obj)
{
if (!_list.Remove((RooAbsArg*)obj)) {
} else if (_verbose) {
cout << "RooTrace::destroy: object " << obj << " of type " << obj->ClassName()
<< " destroyed [" << obj->GetTitle() << "]" << endl ;
}
}
//_____________________________________________________________________________
void RooTrace::create3(const TObject* obj)
{
// Back end function of create(), register creation of object 'obj'
_objectCount[obj->IsA()]++ ;
}
////////////////////////////////////////////////////////////////////////////////
/// Back end function of destroy(), register deletion of object 'obj'
void RooTrace::destroy3(const TObject* obj)
{
_objectCount[obj->IsA()]-- ;
}
////////////////////////////////////////////////////////////////////////////////
/// Put marker in object list, that allows to dump contents of list
/// relative to this marker
void RooTrace::mark()
{
RooTrace::instance().mark3() ;
}
////////////////////////////////////////////////////////////////////////////////
/// Put marker in object list, that allows to dump contents of list
/// relative to this marker
void RooTrace::mark3()
{
_markList = _list ;
}
////////////////////////////////////////////////////////////////////////////////
/// Dump contents of object registry to stdout
void RooTrace::dump()
{
RooTrace::instance().dump3(cout,kFALSE) ;
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::dump(ostream& os, Bool_t sinceMarked)
{
RooTrace::instance().dump3(os,sinceMarked) ;
}
////////////////////////////////////////////////////////////////////////////////
/// Dump contents of object register to stream 'os'. If sinceMarked is
/// true, only object created after the last call to mark() are shown.
void RooTrace::dump3(ostream& os, Bool_t sinceMarked)
{
os << "List of RooFit objects allocated while trace active:" << endl ;
Int_t i, nMarked(0) ;
for(i=0 ; i<_list.GetSize() ; i++) {
if (!sinceMarked || _markList.IndexOf(_list.At(i)) == -1) {
os << hex << setw(10) << _list.At(i) << dec << " : " << setw(20) << _list.At(i)->ClassName() << setw(0) << " - " << _list.At(i)->GetName() << endl ;
} else {
nMarked++ ;
}
}
if (sinceMarked) os << nMarked << " marked objects suppressed" << endl ;
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::printObjectCounts()
{
RooTrace::instance().printObjectCounts3() ;
}
////////////////////////////////////////////////////////////////////////////////
void RooTrace::printObjectCounts3()
{
Double_t total(0) ;
for (map<TClass*,int>::iterator iter = _objectCount.begin() ; iter != _objectCount.end() ; ++iter) {
Double_t tot= 1.0*(iter->first->Size()*iter->second)/(1024*1024) ;
cout << " class " << iter->first->GetName() << " count = " << iter->second << " sizeof = " << iter->first->Size() << " total memory = " << Form("%5.2f",tot) << " Mb" << endl ;
total+=tot ;
}
for (map<string,int>::iterator iter = _specialCount.begin() ; iter != _specialCount.end() ; ++iter) {
int size = _specialSize[iter->first] ;
Double_t tot=1.0*(size*iter->second)/(1024*1024) ;
cout << " speeial " << iter->first << " count = " << iter->second << " sizeof = " << size << " total memory = " << Form("%5.2f",tot) << " Mb" << endl ;
total+=tot ;
}
cout << "Grand total memory = " << Form("%5.2f",total) << " Mb" << endl ;
}
////////////////////////////////////////////////////////////////////////////////
/// Utility function to trigger zeroing of callgrind counters.
///
/// Note that this function does _not_ do anything, other than optionally printing this message
/// To trigger callgrind zero counter action, run callgrind with
/// argument '--zero-before=RooTrace::callgrind_zero()' (include single quotes in cmdline)
void RooTrace::callgrind_zero()
{
ooccoutD((TObject*)0,Tracing) << "RooTrace::callgrind_zero()" << endl ;
}
////////////////////////////////////////////////////////////////////////////////
/// Utility function to trigger dumping of callgrind counters.
///
/// Note that this function does _not_ do anything, other than optionally printing this message
/// To trigger callgrind dumping action, run callgrind with
/// argument '--dump-before=RooTrace::callgrind_dump()' (include single quotes in cmdline)
void RooTrace::callgrind_dump()
{
ooccoutD((TObject*)0,Tracing) << "RooTrace::callgrind_dump()" << endl ;
}