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