// @(#)root/base:$Name: $:$Id: TTStopwatch.h,v 1.4 2004/04/26 14:41:31 brun Exp $ // Author: Fons Rademakers 11/10/95 /************************************************************************* * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #ifndef _TStopwatch #define _TStopwatch ////////////////////////////////////////////////////////////////////////// // // // TTStopwatch // // // // TStopwatch class. This class returns the real and cpu time between // // the start and stop events. // // // ////////////////////////////////////////////////////////////////////////// class TStopwatch { private: enum EState { kUndefined, kStopped, kRunning }; double fStartRealTime; //wall clock start time double fStopRealTime; //wall clock stop time double fStartCpuTime; //cpu start time double fStopCpuTime; //cpu stop time double fTotalCpuTime; //total cpu time double fTotalRealTime; //total real time EState fState; //stopwatch state int fCounter; //number of times the stopwatch was started inline static double GetRealTime(); inline static double GetCPUTime(); public: inline TStopwatch(); inline void Start(int reset = 1); inline void Stop(); inline void Continue(); inline int Counter() const { return fCounter; } inline double RealTime(); inline void Reset() { ResetCpuTime(); ResetRealTime(); } inline void ResetCpuTime(double time = 0) { Stop(); fTotalCpuTime = time; } inline void ResetRealTime(double time = 0) { Stop(); fTotalRealTime = time; } inline double CpuTime(); }; //______________________________________________________________________________ #define R__UNIX #if defined(R__UNIX) # include # include # include static double gTicks = 0; #elif defined(R__VMS) # include # include static double gTicks = 1000; #elif defined(WIN32) # include "TError.h" const double gTicks = 1.0e-7; # include "Windows4Root.h" #endif inline TStopwatch::TStopwatch() { // Create a stopwatch and start it. #ifdef R__UNIX if (!gTicks) gTicks = (double)sysconf(_SC_CLK_TCK); #endif // cout << gTicks << endl; Start(); } //______________________________________________________________________________ inline void TStopwatch::Start(int reset) { // Start the stopwatch. If reset is kTRUE reset the stopwatch before // starting it (including the stopwatch counter). // Use kFALSE to continue timing after a Stop() without // resetting the stopwatch. if (reset) { fState = kUndefined; fTotalCpuTime = 0; fTotalRealTime = 0; fCounter = 0; } if (fState != kRunning) { fStartRealTime = GetRealTime(); fStartCpuTime = GetCPUTime(); } fState = kRunning; fCounter++; } //______________________________________________________________________________ inline void TStopwatch::Stop() { // Stop the stopwatch. fStopRealTime = GetRealTime(); fStopCpuTime = GetCPUTime(); if (fState == kRunning) { fTotalCpuTime += fStopCpuTime - fStartCpuTime; fTotalRealTime += fStopRealTime - fStartRealTime; } fState = kStopped; } //______________________________________________________________________________ inline void TStopwatch::Continue() { // Resume a stopped stopwatch. The stopwatch continues counting from the last // Start() onwards (this is like the laptimer function). if (fState == kUndefined){ //cout<< "stopwatch not started"<