зеркало из https://github.com/mozilla/gecko-dev.git
Not currently part of the build. Added a stack behind the save/restore timing macros.
This commit is contained in:
Родитель
97c680d163
Коммит
f0ef8df8d9
|
@ -2,6 +2,7 @@
|
|||
#define __STOPWATCH_H
|
||||
#include "nscore.h"
|
||||
#include "prlog.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
const double gTicks = 1.0e-7;
|
||||
|
||||
|
@ -65,10 +66,13 @@ private:
|
|||
double fTotalCpuTime; //total cpu time
|
||||
double fTotalRealTime; //total real time
|
||||
EState fState; //stopwatch state
|
||||
EState fSavedState; //last saved state
|
||||
nsDeque* mSavedStates; //stack of saved states
|
||||
PRBool mCreatedStack; //Initially false. Set to true in first SaveState() call.
|
||||
|
||||
public:
|
||||
Stopwatch();
|
||||
virtual ~Stopwatch();
|
||||
|
||||
void Start(PRBool reset = PR_TRUE);
|
||||
void Stop();
|
||||
void Continue();
|
||||
|
|
|
@ -7,13 +7,23 @@ Stopwatch::Stopwatch() {
|
|||
#ifdef R__UNIX
|
||||
if (!gTicks) gTicks = (clock_t)sysconf(_SC_CLK_TCK);
|
||||
#endif
|
||||
fState = kUndefined;
|
||||
fSavedState = kUndefined;
|
||||
fState = kUndefined;
|
||||
fTotalCpuTime = 0;
|
||||
fTotalRealTime = 0;
|
||||
fTotalRealTime = 0;
|
||||
mCreatedStack = PR_FALSE;
|
||||
mSavedStates = nsnull;
|
||||
Start();
|
||||
}
|
||||
|
||||
Stopwatch::~Stopwatch() {
|
||||
EState* state = 0;
|
||||
if (mSavedStates) {
|
||||
while (state = (EState*) mSavedStates->Pop()) {
|
||||
delete state;
|
||||
}
|
||||
delete mSavedStates;
|
||||
}
|
||||
}
|
||||
|
||||
void Stopwatch::Start(PRBool reset) {
|
||||
if (reset) {
|
||||
|
@ -52,14 +62,28 @@ void Stopwatch::Stop() {
|
|||
|
||||
|
||||
void Stopwatch::SaveState() {
|
||||
fSavedState = fState;
|
||||
if (!mCreatedStack) {
|
||||
mSavedStates = new nsDeque(nsnull);
|
||||
mCreatedStack = PR_TRUE;
|
||||
}
|
||||
EState* state = new EState();
|
||||
*state = fState;
|
||||
mSavedStates->PushFront((void*) state);
|
||||
}
|
||||
|
||||
void Stopwatch::RestoreState() {
|
||||
if (fSavedState == kRunning && fState == kStopped)
|
||||
Start(FALSE);
|
||||
else if (fSavedState == kStopped && fState == kRunning)
|
||||
Stop();
|
||||
EState* state = nsnull;
|
||||
state = (EState*) mSavedStates->Pop();
|
||||
if (state) {
|
||||
if (*state == kRunning && fState == kStopped)
|
||||
Start(FALSE);
|
||||
else if (*state == kStopped && fState == kRunning)
|
||||
Stop();
|
||||
delete state;
|
||||
}
|
||||
else {
|
||||
PR_ASSERT("Stopwatch::RestoreState(): The saved state stack is empty.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Stopwatch::Continue() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче