Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RooFit.h"
30
31#include "RooTrace.h"
32#include "RooAbsArg.h"
33#include "Riostream.h"
34#include "RooMsgService.h"
35
36#include <iomanip>
37#include "TClass.h"
38
39
40using namespace std;
41
43;
44
46
47
48////////////////////////////////////////////////////////////////////////////////
49
51{
52 if (_instance==0) _instance = new RooTrace() ;
53 return *_instance ;
54}
55
56
57////////////////////////////////////////////////////////////////////////////////
58
59RooTrace::RooTrace() : _active(kFALSE), _verbose(kFALSE)
60{
61}
62
63
64
65////////////////////////////////////////////////////////////////////////////////
66/// Register creation of object 'obj'
67
68void RooTrace::create(const TObject* obj)
69{
71 if (instance._active) {
72 instance.create3(obj) ;
73 }
74
75}
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// Register deletion of object 'obj'
80
81void RooTrace::destroy(const TObject* obj)
82{
84 if (instance._active) {
85 instance.destroy3(obj) ;
86 }
87}
88
89
90////////////////////////////////////////////////////////////////////////////////
91
92void RooTrace::createSpecial(const char* name, int size)
93{
95 if (instance._active) {
97 }
98}
99
100
101////////////////////////////////////////////////////////////////////////////////
102
104{
106 if (instance._active) {
108 }
109}
110
111
112////////////////////////////////////////////////////////////////////////////////
113
114void RooTrace::createSpecial3(const char* name, int size)
115{
117 _specialSize[name] = size ;
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122
124{
126}
127
128
129
130////////////////////////////////////////////////////////////////////////////////
131/// If flag is true, memory tracing is activated
132
134{
135 RooTrace::instance()._active = flag ;
136}
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// If flag is true, a message will be printed at each
141/// object creation or deletion
142
144{
145 RooTrace::instance()._verbose = flag ;
146}
147
148
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Back end function of create(), register creation of object 'obj'
154
155void RooTrace::create2(const TObject* obj)
156{
157 _list.Add((RooAbsArg*)obj) ;
158 if (_verbose) {
159 cout << "RooTrace::create: object " << obj << " of type " << obj->ClassName()
160 << " created " << endl ;
161 }
162}
163
164
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Back end function of destroy(), register deletion of object 'obj'
169
171{
172 if (!_list.Remove((RooAbsArg*)obj)) {
173 } else if (_verbose) {
174 cout << "RooTrace::destroy: object " << obj << " of type " << obj->ClassName()
175 << " destroyed [" << obj->GetTitle() << "]" << endl ;
176 }
177}
178
179
180
181//_____________________________________________________________________________
182
183void RooTrace::create3(const TObject* obj)
184{
185 // Back end function of create(), register creation of object 'obj'
186 _objectCount[obj->IsA()]++ ;
187}
188
189
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Back end function of destroy(), register deletion of object 'obj'
194
196{
197 _objectCount[obj->IsA()]-- ;
198}
199
200
201
202////////////////////////////////////////////////////////////////////////////////
203/// Put marker in object list, that allows to dump contents of list
204/// relative to this marker
205
207{
209}
210
211
212
213////////////////////////////////////////////////////////////////////////////////
214/// Put marker in object list, that allows to dump contents of list
215/// relative to this marker
216
218{
219 _markList = _list ;
220}
221
222
223
224////////////////////////////////////////////////////////////////////////////////
225/// Dump contents of object registry to stdout
226
228{
230}
231
232
233////////////////////////////////////////////////////////////////////////////////
234
235void RooTrace::dump(ostream& os, Bool_t sinceMarked)
236{
237 RooTrace::instance().dump3(os,sinceMarked) ;
238}
239
240
241////////////////////////////////////////////////////////////////////////////////
242/// Dump contents of object register to stream 'os'. If sinceMarked is
243/// true, only object created after the last call to mark() are shown.
244
245void RooTrace::dump3(ostream& os, Bool_t sinceMarked)
246{
247 os << "List of RooFit objects allocated while trace active:" << endl ;
248
249
250 Int_t i, nMarked(0) ;
251 for(i=0 ; i<_list.GetSize() ; i++) {
252 if (!sinceMarked || _markList.IndexOf(_list.At(i)) == -1) {
253 os << hex << setw(10) << _list.At(i) << dec << " : " << setw(20) << _list.At(i)->ClassName() << setw(0) << " - " << _list.At(i)->GetName() << endl ;
254 } else {
255 nMarked++ ;
256 }
257 }
258 if (sinceMarked) os << nMarked << " marked objects suppressed" << endl ;
259}
260
261
262////////////////////////////////////////////////////////////////////////////////
263
265{
267}
268
269////////////////////////////////////////////////////////////////////////////////
270
272{
273 Double_t total(0) ;
274 for (map<TClass*,int>::iterator iter = _objectCount.begin() ; iter != _objectCount.end() ; ++iter) {
275 Double_t tot= 1.0*(iter->first->Size()*iter->second)/(1024*1024) ;
276 cout << " class " << iter->first->GetName() << " count = " << iter->second << " sizeof = " << iter->first->Size() << " total memory = " << Form("%5.2f",tot) << " Mb" << endl ;
277 total+=tot ;
278 }
279
280 for (map<string,int>::iterator iter = _specialCount.begin() ; iter != _specialCount.end() ; ++iter) {
281 int size = _specialSize[iter->first] ;
282 Double_t tot=1.0*(size*iter->second)/(1024*1024) ;
283 cout << " speeial " << iter->first << " count = " << iter->second << " sizeof = " << size << " total memory = " << Form("%5.2f",tot) << " Mb" << endl ;
284 total+=tot ;
285 }
286 cout << "Grand total memory = " << Form("%5.2f",total) << " Mb" << endl ;
287
288}
289
290
291////////////////////////////////////////////////////////////////////////////////
292/// Utility function to trigger zeroing of callgrind counters.
293///
294/// Note that this function does _not_ do anything, other than optionally printing this message
295/// To trigger callgrind zero counter action, run callgrind with
296/// argument '--zero-before=RooTrace::callgrind_zero()' (include single quotes in cmdline)
297
299{
300 ooccoutD((TObject*)0,Tracing) << "RooTrace::callgrind_zero()" << endl ;
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Utility function to trigger dumping of callgrind counters.
305///
306/// Note that this function does _not_ do anything, other than optionally printing this message
307/// To trigger callgrind dumping action, run callgrind with
308/// argument '--dump-before=RooTrace::callgrind_dump()' (include single quotes in cmdline)
309
311{
312 ooccoutD((TObject*)0,Tracing) << "RooTrace::callgrind_dump()" << endl ;
313}
#define ooccoutD(o, a)
const Bool_t kFALSE
Definition RtypesCore.h:92
#define ClassImp(name)
Definition Rtypes.h:364
static unsigned int total
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
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
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
Int_t IndexOf(const char *name) const
Return position of given object in list.
Class RooTrace controls the memory tracing hooks in all RooFit objects.
Definition RooTrace.h:26
static void destroySpecial(const char *name)
Definition RooTrace.cxx:103
static void active(Bool_t flag)
If flag is true, memory tracing is activated.
Definition RooTrace.cxx:133
static void dump()
Dump contents of object registry to stdout.
Definition RooTrace.cxx:227
std::map< TClass *, int > _objectCount
Definition RooTrace.h:80
static RooTrace * _instance
Definition RooTrace.h:57
void dump3(std::ostream &, Bool_t sinceMarked)
Dump contents of object register to stream 'os'.
Definition RooTrace.cxx:245
Bool_t _active
Definition RooTrace.h:76
static void callgrind_zero()
Utility function to trigger zeroing of callgrind counters.
Definition RooTrace.cxx:298
std::map< std::string, int > _specialSize
Definition RooTrace.h:82
static void printObjectCounts()
Definition RooTrace.cxx:264
static void createSpecial(const char *name, int size)
Definition RooTrace.cxx:92
static void destroy(const TObject *obj)
Register deletion of object 'obj'.
Definition RooTrace.cxx:81
static RooTrace & instance()
Definition RooTrace.cxx:50
static void mark()
Put marker in object list, that allows to dump contents of list relative to this marker.
Definition RooTrace.cxx:206
void mark3()
Put marker in object list, that allows to dump contents of list relative to this marker.
Definition RooTrace.cxx:217
Bool_t _verbose
Definition RooTrace.h:77
void create2(const TObject *obj)
Back end function of create(), register creation of object 'obj'.
Definition RooTrace.cxx:155
std::map< std::string, int > _specialCount
Definition RooTrace.h:81
void create3(const TObject *obj)
Definition RooTrace.cxx:183
void destroySpecial3(const char *name)
Definition RooTrace.cxx:123
static void create(const TObject *obj)
Register creation of object 'obj'.
Definition RooTrace.cxx:68
void printObjectCounts3()
Definition RooTrace.cxx:271
RooLinkedList _markList
Definition RooTrace.h:79
void destroy2(const TObject *obj)
Back end function of destroy(), register deletion of object 'obj'.
Definition RooTrace.cxx:170
static void callgrind_dump()
Utility function to trigger dumping of callgrind counters.
Definition RooTrace.cxx:310
static void verbose(Bool_t flag)
If flag is true, a message will be printed at each object creation or deletion.
Definition RooTrace.cxx:143
void destroy3(const TObject *obj)
Back end function of destroy(), register deletion of object 'obj'.
Definition RooTrace.cxx:195
void createSpecial3(const char *name, int size)
Definition RooTrace.cxx:114
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