3 // Author: C. Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3Stopwatch.h"
10 #include "AliL3StandardIncludes.h"
17 /** \class AliL3Stopwatch
19 //----------------------------------------------------
22 // Stopwatch class. This class returns the real and cpu time between
23 // the start and stop events (taken from Root)
28 ClassImp(AliL3Stopwatch)
30 clock_t AliL3Stopwatch::gTicks = 0;
32 AliL3Stopwatch::AliL3Stopwatch()
34 // Create a stopwatch and start it.
35 if (!gTicks) gTicks = (clock_t)sysconf(_SC_CLK_TCK);
43 AliL3Stopwatch::~AliL3Stopwatch()
47 void AliL3Stopwatch::Start(Bool_t reset)
49 // Start the stopwatch. If reset is kTRUE reset the stopwatch before
50 // starting it (including the stopwatch counter).
51 // Use kFALSE to continue timing after a Stop() without
52 // resetting the stopwatch.
59 if (fState != kRunning) {
60 fStartRealTime = GetRealTime();
61 fStartCpuTime = GetCPUTime();
67 void AliL3Stopwatch::Stop()
69 // Stop the stopwatch.
70 fStopRealTime = GetRealTime();
71 fStopCpuTime = GetCPUTime();
72 if (fState == kRunning) {
73 fTotalCpuTime += fStopCpuTime - fStartCpuTime;
74 fTotalRealTime += fStopRealTime - fStartRealTime;
79 void AliL3Stopwatch::Continue()
81 // Resume a stopped stopwatch. The stopwatch continues counting from the last
82 // Start() onwards (this is like the laptimer function).
84 if (fState == kUndefined){
85 cerr << "Error in AliL3Stopwatch::Continue! Stopwatch not started." << endl;
89 if (fState == kStopped) {
90 fTotalCpuTime -= fStopCpuTime - fStartCpuTime;
91 fTotalRealTime -= fStopRealTime - fStartRealTime;
97 Double_t AliL3Stopwatch::RealTime()
99 // Return the realtime passed between the start and stop events. If the
100 // stopwatch was still running stop it first.
102 if (fState == kUndefined){
103 cerr << "Error in AliL3Stopwatch::RealTime! Stopwatch not started." << endl;
107 if (fState == kRunning)
110 return fTotalRealTime;
113 Double_t AliL3Stopwatch::CpuTime()
115 // Return the cputime passed between the start and stop events. If the
116 // stopwatch was still running stop it first.
118 if (fState == kUndefined){
119 cerr << "Error in AliL3Stopwatch::CpuTime! Stopwatch not started." << endl;
122 if (fState == kRunning)
125 return fTotalCpuTime;
128 Double_t AliL3Stopwatch::GetRealTime()
131 Double_t trt = (Double_t)times(&cpt);
132 return trt / (Double_t)gTicks;
135 Double_t AliL3Stopwatch::GetCPUTime()
139 return (Double_t)(cpt.tms_utime+cpt.tms_stime) / gTicks;
142 //______________________________________________________________________________
143 void AliL3Stopwatch::Print(Char_t *opt) const
145 // Print the real and cpu time passed between the start and stop events.
146 // and the number of times (slices) this TStopwatch was called
147 // (if this number > 1)
149 Double_t realt = ((AliL3Stopwatch*)(this))->RealTime();
151 Int_t hours = Int_t(realt / 3600);
152 realt -= hours * 3600;
153 Int_t min = Int_t(realt / 60);
155 Int_t sec = Int_t(realt);
156 Int_t counter = Counter();
158 printf("Real time %d:%d:%d, CP time %.3f", hours, min, sec, ((AliL3Stopwatch*)(this))->CpuTime());
160 printf("Real time %d:%d:%d, CP time %.3f, %d slices", hours, min, sec, ((AliL3Stopwatch*)(this))->CpuTime(),counter);