26 #ifndef _TIMEMEASURE_H_261946892_
27 #define _TIMEMEASURE_H_261946892_
32 # define _WIN32_WINNT 0x0501 // Windows XP for GetSystemTimes
33 # endif // _WIN32_WINNT
36 # include <Base/Common/W32Compat.hh>
48 # include <sys/time.h>
49 # include <sys/times.h>
88 __forceinline __int64 __fastcall GetTSC(){
return __rdtsc(); };
90 __forceinline __int64 __fastcall GetTSC(){ __asm rdtsc };
96 inline __int64 GetTSCTicks(__int64 start, __int64 end)
97 {
return ((end - start) & 0xFFFFFFFFFFFF);};
133 void Print(std::ostream& os=std::cout)
const;
142 double GetRealTime()
const;
149 double GetUserTime()
const;
155 double GetKernelTime()
const;
160 double GetIdleTime()
const;
163 double GetFreq()
const;
166 double GetUserFreq()
const;
171 void PrintRealTime(std::ostream& os=std::cout,
172 const bool &verbose=
true)
const;
177 void PrintUserTime(std::ostream& os=std::cout,
178 const bool &verbose=
true)
const;
183 void PrintKernelTime(std::ostream& os=std::cout,
184 const bool &verbose=
true)
const;
189 void PrintIdleTime(std::ostream& os=std::cout,
190 const bool & verbose=
true)
const;
192 bool IsRunning()
const;
194 void SetTimerFile(
const std::string &file);
195 void LogToFileAndReset(
const std::string &comment);
196 void CloseTimerFile();
201 double GetCycleCount()
const;
206 void PrintCycleCount(std::ostream& os=std::cout)
const ;
211 inline void ReadCycleCounter(
unsigned int *hi,
unsigned int *lo);
217 double MeasureOverhead();
221 double MeasureProcessorFrequency();
230 static void MSecondsToHumanReadable(
const unsigned long & msIN,
231 int & msecOUT,
int & seconds,
232 int & minutes,
int & hours,
233 int & days,
int & weeks );
237 static std::ostream & PrintMsecHumanReadable(
const unsigned long msecIN,
238 std::ostream &os=std::cout);
246 static std::string GetCurrentTimeAsString();
254 static std::string GetDateAsString();
262 struct tms startstruct, stopstruct;
266 FILETIME _UserTimeStart, _UserTimeStop;
267 FILETIME _KernelTimeStart, _KernelTimeStop;
268 FILETIME _IdleTimeStart, _IdleTimeStop;
276 __int64 _tscStart, _tscEnd, _tscTicks;
279 unsigned int _uiHiStart, _uiLoStart, _uiHiStop, _uiLoStop;
297 if(
running) BIASERR(
"clock already started");
298 # endif // BIAS_DEBUG
302 gettimeofday(&
rtLast,NULL);
303 if (times(&startstruct) == (clock_t)(-1))
304 BIASERR(
"error starting user timer "<<errno);
322 BIASERR(
"error stopping user timer "<<errno);
345 if (_uiLoStop>_uiLoStart)
346 count = ((double)_uiHiStop-(
double)_uiHiStart)*(
double)UINT_MAX+
347 (double)_uiLoStop-(
double)_uiLoStart;
349 count = ((double)_uiHiStop-(
double)_uiHiStart-1)*(
double)UINT_MAX+
350 (double)_uiLoStop+(
double)UINT_MAX-(double)_uiLoStart;
356 BIASERR(
"cannot stop clock befor starting it");
367 asm(
"rdtsc; movl %%edx,%0; movl %%eax,%1"
368 :
"=r" (*hi),
"=r" (*lo)
376 #endif // _TIMEMEASURE_H_261946892_
~TimeMeasure()
print the output when the desctructor is called ?
struct tms startstruct stopstruct
void ReadCycleCounter(unsigned int *hi, unsigned int *lo)
static std::ofstream TimerStream_
class TimeMeasure contains functions for timing real time and cpu time.