]>
Commit | Line | Data |
---|---|---|
87932dab | 1 | #ifndef ALICODETIMER_H |
2 | #define ALICODETIMER_H | |
3 | ||
4 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * See cxx source for full Copyright notice */ | |
6 | ||
7 | // $Id$ | |
8 | ||
9 | /// | |
10 | /// A class to organize TStopwatch timers used to time our code | |
11 | /// | |
12 | // Author Laurent Aphecetche | |
13 | ||
14 | #ifndef ROOT_TString | |
15 | # include "TString.h" | |
16 | #endif | |
17 | #ifndef ROOT_TObjString | |
18 | # include "TObjString.h" | |
19 | #endif | |
20 | #ifndef ALILOG_H | |
21 | # include "AliLog.h" | |
22 | #endif | |
23 | ||
24 | class TStopwatch; | |
25 | class TMap; | |
26 | ||
27 | class AliCodeTimer : public TObject | |
28 | { | |
29 | public: | |
30 | ||
31 | AliCodeTimer(); | |
32 | virtual ~AliCodeTimer(); | |
33 | ||
34 | /// Unique instance of this class, which is a singleton | |
35 | static AliCodeTimer* Instance(); | |
36 | ||
37 | /// Continue timer(classname,methodname,message) | |
38 | void Continue(const char* classname, const char* methodname, const char* message=""); | |
39 | ||
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; | |
42 | ||
43 | /// Print the list of timers we manage | |
44 | void Print(Option_t* opt="") const; | |
45 | ||
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; | |
48 | ||
49 | /// Reset all our timers | |
50 | void Reset(); | |
51 | ||
52 | /// Start timer(classname,methodname,message) | |
53 | void Start(const char* classname, const char* methodname, const char* message=""); | |
54 | ||
55 | /// Stop timer(classname,methodname,message) | |
56 | void Stop(const char* classname, const char* methodname, const char* message=""); | |
57 | ||
58 | public: | |
59 | ||
60 | class AliPair : public TObject | |
61 | { | |
62 | public: | |
63 | AliPair() : TObject(),fName(0), fTimer(0) {} | |
64 | // ctor | |
65 | AliPair(TObjString* name, TStopwatch* timer) : TObject(), fName(name), fTimer(timer) {} | |
66 | virtual ~AliPair() { delete fName; } | |
67 | ||
68 | /// get name | |
69 | TString Name() const { return fName->String(); } | |
70 | /// get timer | |
71 | TStopwatch* Timer() const { return fTimer; } | |
72 | ||
73 | /// we are sortable (by name) | |
74 | virtual Bool_t IsSortable() const { return kTRUE; } | |
75 | /// compare the names | |
76 | virtual Int_t Compare(const TObject* object) const | |
77 | { return fName->Compare(((const AliPair*)(object))->fName); } | |
78 | ||
79 | virtual void Print(Option_t* opt="") const; | |
80 | ||
81 | private: | |
82 | AliPair(const AliPair&); | |
83 | AliPair& operator=(const AliPair&); | |
84 | ||
85 | TObjString* fName; // name of the timer | |
86 | TStopwatch* fTimer; // actual timer | |
87 | ||
88 | ClassDef(AliPair,1) // internal class to hold (string,TStopwatch*) AliPair | |
89 | }; | |
90 | ||
91 | class AliAutoPtr | |
92 | { | |
93 | public: | |
94 | ||
95 | /// ctor | |
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); } | |
99 | ||
100 | /// dtor | |
101 | ~AliAutoPtr() { AliCodeTimer::Instance()->Stop(fA.Data(),fB.Data(),fC.Data()); } | |
102 | ||
103 | private: | |
104 | TString fA; // first id | |
105 | TString fB; // second id | |
106 | TString fC; // third id | |
107 | }; | |
108 | ||
109 | private: | |
110 | ||
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; | |
116 | ||
117 | private: | |
118 | ||
119 | AliCodeTimer(const AliCodeTimer& rhs); | |
120 | AliCodeTimer& operator=(const AliCodeTimer& rhs); | |
121 | ||
122 | static AliCodeTimer* fgInstance; //< unique instance | |
123 | ||
124 | TMap* fTimers; //< internal timers | |
125 | ||
126 | ClassDef(AliCodeTimer,1) // A timer holder | |
127 | }; | |
128 | ||
129 | #ifndef LOG_NO_DEBUG | |
130 | ||
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); | |
134 | ||
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); | |
138 | ||
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); | |
142 | ||
143 | #else | |
144 | ||
145 | #define AliCodeTimerStartClass(message) | |
146 | #define AliCodeTimerStopClass(message) | |
147 | #define AliCodeTimerAutoClass(message) | |
148 | ||
149 | #define AliCodeTimerStart(message) | |
150 | #define AliCodeTimerStop(message) | |
151 | #define AliCodeTimerAuto(message) | |
152 | ||
153 | #define AliCodeTimerStartGeneral(message) | |
154 | #define AliCodeTimerStopGeneral(message) | |
155 | #define AliCodeTimerAutoGeneral(message) | |
156 | ||
157 | #endif | |
158 | ||
159 | #endif |