1999-09-24 23:30:54 +04:00
|
|
|
#ifndef __STOPWATCH_H
|
|
|
|
#define __STOPWATCH_H
|
1999-09-20 12:21:01 +04:00
|
|
|
#include "nscore.h"
|
1999-09-24 12:39:43 +04:00
|
|
|
#include "prlog.h"
|
1999-10-09 03:27:09 +04:00
|
|
|
#include "nsDeque.h"
|
1999-09-20 12:21:01 +04:00
|
|
|
|
1999-10-20 01:12:14 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#define R__MAC
|
|
|
|
#endif
|
|
|
|
|
1999-10-21 06:32:01 +04:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#define R__UNIX
|
|
|
|
#endif
|
|
|
|
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
1999-09-15 04:27:56 +04:00
|
|
|
# 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-09-24 12:39:43 +04:00
|
|
|
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
1999-09-24 12:39:43 +04:00
|
|
|
|
1999-09-24 23:30:54 +04:00
|
|
|
static PRLogModuleInfo* gLogStopwatchModule = PR_NewLogModule("timing");
|
|
|
|
|
|
|
|
#if 0
|
1999-09-24 12:39:43 +04:00
|
|
|
#define RAPTOR_TRACE_STOPWATCHES 0x1
|
|
|
|
|
|
|
|
#define RAPTOR_STOPWATCH_TRACE(_args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
PR_LOG(gLogStopwatchModule, RAPTOR_TRACE_STOPWATCHES, _args); \
|
|
|
|
PR_END_MACRO
|
1999-09-24 23:30:54 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RAPTOR_STOPWATCH_TRACE(_args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
printf _args ; \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
1999-09-24 12:39:43 +04:00
|
|
|
#else
|
|
|
|
#define RAPTOR_TRACE_STOPWATCHES
|
|
|
|
#define RAPTOR_STOPWATCH_TRACE(_args)
|
|
|
|
#endif
|
|
|
|
|
1999-10-12 03:30:45 +04:00
|
|
|
#ifdef DEBUG_STOPWATCH
|
|
|
|
#define RAPTOR_STOPWATCH_DEBUGTRACE(_args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
printf _args ; \
|
|
|
|
PR_END_MACRO
|
|
|
|
#else
|
|
|
|
#define RAPTOR_STOPWATCH_DEBUGTRACE(_args)
|
|
|
|
#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-10-09 03:27:09 +04:00
|
|
|
nsDeque* mSavedStates; //stack of saved states
|
|
|
|
PRBool mCreatedStack; //Initially false. Set to true in first SaveState() call.
|
1999-08-05 09:07:58 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
Stopwatch();
|
1999-10-09 03:27:09 +04:00
|
|
|
virtual ~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();
|
2000-02-18 21:50:28 +03:00
|
|
|
double RealTimeInMilliseconds();
|
1999-08-05 09:07:58 +04:00
|
|
|
void Reset() { ResetCpuTime(); ResetRealTime(); }
|
1999-10-21 06:32:01 +04:00
|
|
|
void ResetCpuTime(double aTime = 0) { Stop(); fTotalCpuTime = aTime; }
|
|
|
|
void ResetRealTime(double aTime = 0) { Stop(); fTotalRealTime = aTime; }
|
1999-08-05 09:07:58 +04:00
|
|
|
double CpuTime();
|
|
|
|
void Print(void);
|
|
|
|
static double GetRealTime();
|
|
|
|
static double GetCPUTime();
|
|
|
|
|
|
|
|
};
|
1999-09-25 01:47:16 +04:00
|
|
|
#endif
|