1999-08-05 09:07:58 +04:00
|
|
|
const double gTicks = 1.0e-7;
|
|
|
|
|
1999-09-15 04:27:56 +04:00
|
|
|
#ifdef RAPTOR_PERF_METRICS
|
|
|
|
# define NS_RESET_AND_START_STOPWATCH(_sw) \
|
|
|
|
_sw.Start(PR_TRUE);
|
|
|
|
|
|
|
|
# define NS_START_STOPWATCH(_sw) \
|
|
|
|
_sw.Start(PR_FALSE);
|
|
|
|
|
|
|
|
# define NS_STOP_STOPWATCH(_sw) \
|
|
|
|
_sw.Stop();
|
|
|
|
|
|
|
|
# define NS_SAVE_STOPWATCH_STATE(_sw) \
|
|
|
|
_sw.SaveState();
|
|
|
|
|
|
|
|
# define NS_RESTORE_STOPWATCH_STATE(_sw) \
|
|
|
|
_sw.RestoreState();
|
|
|
|
|
|
|
|
#else
|
|
|
|
# define NS_RESET_AND_START_STOPWATCH(_sw)
|
|
|
|
# define NS_START_STOPWATCH(_sw)
|
|
|
|
# define NS_STOP_STOPWATCH(_sw)
|
|
|
|
# define NS_SAVE_STOPWATCH_STATE(_sw)
|
|
|
|
# define NS_RESTORE_STOPWATCH_STATE(_sw)
|
|
|
|
#endif
|
|
|
|
|
1999-08-05 09:07:58 +04:00
|
|
|
class Stopwatch {
|
|
|
|
|
|
|
|
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
|
1999-09-14 18:32:42 +04:00
|
|
|
EState fSavedState; //last saved state
|
1999-08-05 09:07:58 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
Stopwatch();
|
1999-09-17 02:58:02 +04:00
|
|
|
void Start(PRBool reset = PR_TRUE);
|
1999-08-05 09:07:58 +04:00
|
|
|
void Stop();
|
|
|
|
void Continue();
|
1999-09-14 18:32:42 +04:00
|
|
|
void SaveState(); // record current state of stopwatch
|
|
|
|
void RestoreState(); // restore last recored state of stopwatch
|
1999-08-05 09:07:58 +04:00
|
|
|
double RealTime();
|
|
|
|
void Reset() { ResetCpuTime(); ResetRealTime(); }
|
|
|
|
void ResetCpuTime(double time = 0) { Stop(); fTotalCpuTime = time; }
|
|
|
|
void ResetRealTime(double time = 0) { Stop(); fTotalRealTime = time; }
|
|
|
|
double CpuTime();
|
|
|
|
void Print(void);
|
|
|
|
static double GetRealTime();
|
|
|
|
static double GetCPUTime();
|
|
|
|
|
|
|
|
};
|