Diana Software
QModuleTimeProfiling.cc
Go to the documentation of this file.
2 
3 #include <ctime>
4 #include <sstream>
5 #include <TString.h>
6 
8  : fTimeProfilingOn(false),
9  fProcessCalls(0),
10  fProcessTime(0),
11  fTimerStartTime(0)
12 {}
13 
15  fTimerStartTime = clock();
16 }
17 
19  return ((double)((clock_t)(clock() - fTimerStartTime)))/CLOCKS_PER_SEC;
20 }
21 
23  ResetTimer();
24 }
25 
27  fProcessTime += GetTimer();
28  fProcessCalls++;
29 }
30 
33 }
34 
35 std::string QModuleTimeProfiling::GetTimeProfileReport(const std::string &prefix) const {
36  std::stringstream msg;
37  if(prefix != "")
38  msg << prefix << ": ";
39  msg << Form("Avg load per event: %.0f mus (calls: %llu)",1e6*GetProcessCallTime(),GetProcessCalls());
40  return msg.str();
41 }
42 
void ResetTimer()
Reset the timer to now.
double GetProcessCallTime() const
Return the average time of a single process call.
unsigned long long int fProcessCalls
NUmber of calls to the process.
double fProcessTime
Total time spent running the process.
virtual void EndProcessCall()
End a process call and increment time and calls.
virtual void StartProcessCall()
Start of a process call.
QModuleTimeProfiling()
ctor initialized internal variables
double GetTimer() const
return the time since the last reset
unsigned long long GetProcessCalls() const
Return the total number of process calls.
std::string GetTimeProfileReport(const std::string &prefix="") const
Report the time profiling.
clock_t fTimerStartTime
CLock time of the last timer reset.