b=450088 backing out (new reftest failed)
[wine-gecko.git] / modules / libutil / public / stopwatch.h
blob5aad0b8e226d7b9071529ce1fbc0b7f655789890
1 #ifndef __STOPWATCH_H
2 #define __STOPWATCH_H
3 #include "nscore.h"
4 #include "prlog.h"
5 #include "nsDeque.h"
7 #ifdef XP_MAC
8 #define R__MAC
9 #endif
11 #ifdef XP_UNIX
12 #define R__UNIX
13 #endif
15 #ifdef MOZ_PERF_METRICS
16 # define NS_RESET_AND_START_STOPWATCH(_sw) \
17 _sw.Start(PR_TRUE);
19 # define NS_START_STOPWATCH(_sw) \
20 _sw.Start(PR_FALSE);
22 # define NS_STOP_STOPWATCH(_sw) \
23 _sw.Stop();
25 # define NS_SAVE_STOPWATCH_STATE(_sw) \
26 _sw.SaveState();
28 # define NS_RESTORE_STOPWATCH_STATE(_sw) \
29 _sw.RestoreState();
31 #else
32 # define NS_RESET_AND_START_STOPWATCH(_sw)
33 # define NS_START_STOPWATCH(_sw)
34 # define NS_STOP_STOPWATCH(_sw)
35 # define NS_SAVE_STOPWATCH_STATE(_sw)
36 # define NS_RESTORE_STOPWATCH_STATE(_sw)
37 #endif
40 #ifdef MOZ_PERF_METRICS
42 static PRLogModuleInfo* gLogStopwatchModule = PR_NewLogModule("timing");
44 #if 0
45 #define RAPTOR_TRACE_STOPWATCHES 0x1
47 #define RAPTOR_STOPWATCH_TRACE(_args) \
48 PR_BEGIN_MACRO \
49 PR_LOG(gLogStopwatchModule, RAPTOR_TRACE_STOPWATCHES, _args); \
50 PR_END_MACRO
51 #endif
53 #define RAPTOR_STOPWATCH_TRACE(_args) \
54 PR_BEGIN_MACRO \
55 printf _args ; \
56 PR_END_MACRO
58 #else
59 #define RAPTOR_TRACE_STOPWATCHES
60 #define RAPTOR_STOPWATCH_TRACE(_args)
61 #endif
63 #ifdef DEBUG_STOPWATCH
64 #define RAPTOR_STOPWATCH_DEBUGTRACE(_args) \
65 PR_BEGIN_MACRO \
66 printf _args ; \
67 PR_END_MACRO
68 #else
69 #define RAPTOR_STOPWATCH_DEBUGTRACE(_args)
70 #endif
72 class Stopwatch {
74 private:
75 enum EState { kUndefined, kStopped, kRunning };
77 double fStartRealTime; //wall clock start time
78 double fStopRealTime; //wall clock stop time
79 double fStartCpuTime; //cpu start time
80 double fStopCpuTime; //cpu stop time
81 double fTotalCpuTime; //total cpu time
82 double fTotalRealTime; //total real time
83 EState fState; //stopwatch state
84 nsDeque* mSavedStates; //stack of saved states
85 PRBool mCreatedStack; //Initially false. Set to true in first SaveState() call.
87 public:
88 Stopwatch();
89 virtual ~Stopwatch();
91 void Start(PRBool reset = PR_TRUE);
92 void Stop();
93 void Continue();
94 void SaveState(); // record current state of stopwatch
95 void RestoreState(); // restore last recored state of stopwatch
96 double RealTime();
97 double RealTimeInMilliseconds();
98 void Reset() { ResetCpuTime(); ResetRealTime(); }
99 void ResetCpuTime(double aTime = 0) { Stop(); fTotalCpuTime = aTime; }
100 void ResetRealTime(double aTime = 0) { Stop(); fTotalRealTime = aTime; }
101 double CpuTime();
102 void Print(void);
103 static double GetRealTime();
104 static double GetCPUTime();
107 #endif