4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
10 /// A class to organize TStopwatch timers used to time our code
12 // Author Laurent Aphecetche
17 #ifndef ROOT_TObjString
18 # include "TObjString.h"
27 class AliCodeTimer : public TObject
32 virtual ~AliCodeTimer();
34 /// Unique instance of this class, which is a singleton
35 static AliCodeTimer* Instance();
37 /// Continue timer(classname,methodname,message)
38 void Continue(const char* classname, const char* methodname, const char* message="");
40 /// Return the cpu time spent in timer(classname,methodname,message)
41 Double_t CpuTime(const char* classname, const char* methodname, const char* message="") const;
43 /// Print the list of timers we manage
44 void Print(Option_t* opt="") const;
46 /// Return the real time spent in timer(classname,methodname,message)
47 Double_t RealTime(const char* classname, const char* methodname, const char* message="") const;
49 /// Reset all our timers
52 /// Start timer(classname,methodname,message)
53 void Start(const char* classname, const char* methodname, const char* message="");
55 /// Stop timer(classname,methodname,message)
56 void Stop(const char* classname, const char* methodname, const char* message="");
60 class AliPair : public TObject
63 AliPair() : TObject(),fName(0), fTimer(0) {}
65 AliPair(TObjString* name, TStopwatch* timer) : TObject(), fName(name), fTimer(timer) {}
66 virtual ~AliPair() { delete fName; }
69 TString Name() const { return fName->String(); }
71 TStopwatch* Timer() const { return fTimer; }
73 /// we are sortable (by name)
74 virtual Bool_t IsSortable() const { return kTRUE; }
76 virtual Int_t Compare(const TObject* object) const
77 { return fName->Compare(((const AliPair*)(object))->fName); }
79 virtual void Print(Option_t* opt="") const;
82 AliPair(const AliPair&);
83 AliPair& operator=(const AliPair&);
85 TObjString* fName; // name of the timer
86 TStopwatch* fTimer; // actual timer
88 ClassDef(AliPair,1) // internal class to hold (string,TStopwatch*) AliPair
96 AliAutoPtr(const char* classname, const char* methodname, const char* message="")
97 : fA(classname), fB(methodname), fC(message)
98 { AliCodeTimer::Instance()->Start(classname,methodname,message); }
101 ~AliAutoPtr() { AliCodeTimer::Instance()->Stop(fA.Data(),fB.Data(),fC.Data()); }
104 TString fA; // first id
105 TString fB; // second id
106 TString fC; // third id
111 TMap* MethodMap(const char* classname) const;
112 TObjArray* MessageArray(const char* classname, const char* methodname) const;
113 TStopwatch* Stopwatch(const char* classname, const char* methodname, const char* message="") const;
114 void PrintClass(const char* classname) const;
115 void PrintMethod(const char* classname, const char* methodname) const;
119 AliCodeTimer(const AliCodeTimer& rhs);
120 AliCodeTimer& operator=(const AliCodeTimer& rhs);
122 static AliCodeTimer* fgInstance; //< unique instance
124 TMap* fTimers; //< internal timers
126 ClassDef(AliCodeTimer,1) // A timer holder
131 #define AliCodeTimerStartClass(message) AliCodeTimer::Instance()->Start(Class()->GetName(),FUNCTIONNAME(),message);
132 #define AliCodeTimerStopClass(message) AliCodeTimer::Instance()->Stop(Class()->GetName(),FUNCTIONNAME(),message);
133 #define AliCodeTimerAutoClass(message) AliCodeTimer::AliAutoPtr aliCodeTimerAliAutoPtrVariable(Class()->GetName(),FUNCTIONNAME(),message);
135 #define AliCodeTimerStart(message) AliCodeTimer::Instance()->Start(ClassName(),FUNCTIONNAME(),message);
136 #define AliCodeTimerStop(message) AliCodeTimer::Instance()->Stop(ClassName(),FUNCTIONNAME(),message);
137 #define AliCodeTimerAuto(message) AliCodeTimer::AliAutoPtr aliCodeTimerAliAutoPtrVariable(ClassName(),FUNCTIONNAME(),message);
139 #define AliCodeTimerStartGeneral(message) AliCodeTimer::Instance()->Start("General",FUNCTIONNAME(),message);
140 #define AliCodeTimerStopGeneral(message) AliCodeTimer::Instance()->Stop("General",FUNCTIONNAME(),message);
141 #define AliCodeTimerAutoGeneral(message) AliCodeTimer::AliAutoPtr aliCodeTimerAliAutoPtrVariable("General",FUNCTIONNAME(),message);
145 #define AliCodeTimerStartClass(message)
146 #define AliCodeTimerStopClass(message)
147 #define AliCodeTimerAutoClass(message)
149 #define AliCodeTimerStart(message)
150 #define AliCodeTimerStop(message)
151 #define AliCodeTimerAuto(message)
153 #define AliCodeTimerStartGeneral(message)
154 #define AliCodeTimerStopGeneral(message)
155 #define AliCodeTimerAutoGeneral(message)