Index: tools/VisualBench/TimingStateMachine.cpp |
diff --git a/tools/VisualBench/TimingStateMachine.cpp b/tools/VisualBench/TimingStateMachine.cpp |
index d7e4cf4a77a409e7cef1b028efa91df94d81ccef..acd01a1074928f08baf208a3d177dbb59aa3d1f5 100644 |
--- a/tools/VisualBench/TimingStateMachine.cpp |
+++ b/tools/VisualBench/TimingStateMachine.cpp |
@@ -18,53 +18,63 @@ TimingStateMachine::TimingStateMachine() |
: fCurrentFrame(0) |
, fLoops(1) |
, fLastMeasurement(0.) |
- , fState(kPreWarmLoopsPerCanvasPreDraw_State) { |
+ , fState(kPreWarm_State) |
+ , fInnerState(kTuning_InnerState) { |
} |
-TimingStateMachine::ParentEvents TimingStateMachine::nextFrame(SkCanvas* canvas, |
- Benchmark* benchmark) { |
+TimingStateMachine::ParentEvents TimingStateMachine::nextFrame(bool preWarmBetweenSamples) { |
+ ParentEvents parentEvent = kTiming_ParentEvents; |
switch (fState) { |
- case kPreWarmLoopsPerCanvasPreDraw_State: |
- return this->perCanvasPreDraw(canvas, benchmark, kPreWarmLoops_State); |
- case kPreWarmLoops_State: |
- return this->preWarm(kTuneLoops_State); |
- case kTuneLoops_State: |
- return this->tuneLoops(); |
- case kPreWarmTimingPerCanvasPreDraw_State: |
- return this->perCanvasPreDraw(canvas, benchmark, kPreWarmTiming_State); |
- case kPreWarmTiming_State: |
- return this->preWarm(kTiming_State); |
- case kTiming_State: |
- return this->timing(canvas, benchmark); |
- } |
- SkFAIL("Incomplete switch\n"); |
- return kTiming_ParentEvents; |
-} |
- |
-inline void TimingStateMachine::nextState(State nextState) { |
- fState = nextState; |
-} |
- |
-TimingStateMachine::ParentEvents TimingStateMachine::perCanvasPreDraw(SkCanvas* canvas, |
- Benchmark* benchmark, |
- State nextState) { |
- benchmark->perCanvasPreDraw(canvas); |
- benchmark->preDraw(canvas); |
- fCurrentFrame = 0; |
- this->nextState(nextState); |
- return kTiming_ParentEvents; |
-} |
- |
-TimingStateMachine::ParentEvents TimingStateMachine::preWarm(State nextState) { |
- if (fCurrentFrame >= FLAGS_gpuFrameLag) { |
- // we currently time across all frames to make sure we capture all GPU work |
- this->nextState(nextState); |
- fCurrentFrame = 0; |
- fTimer.start(); |
- } else { |
- fCurrentFrame++; |
+ case kPreWarm_State: { |
+ if (fCurrentFrame >= FLAGS_gpuFrameLag) { |
+ fCurrentFrame = 0; |
+ fTimer.start(); |
+ fState = kTiming_State; |
+ } else { |
+ fCurrentFrame++; |
+ } |
+ break; |
+ } |
+ case kTiming_State: { |
+ switch (fInnerState) { |
+ case kTuning_InnerState: { |
+ if (1 << 30 == fLoops) { |
+ // We're about to wrap. Something's wrong with the bench. |
+ SkDebugf("InnerLoops wrapped\n"); |
+ fLoops = 1; |
+ } else { |
+ double elapsedMs = this->elapsed(); |
+ if (elapsedMs < FLAGS_loopMs) { |
+ fLoops *= 2; |
+ } else { |
+ fInnerState = kTiming_InnerState; |
+ fState = kPreWarm_State; |
+ } |
+ this->resetTimingState(); |
+ parentEvent = kReset_ParentEvents; |
+ } |
+ break; |
+ } |
+ case kTiming_InnerState: { |
+ if (fCurrentFrame >= FLAGS_frames) { |
+ this->recordMeasurement(); |
+ this->resetTimingState(); |
+ parentEvent = kTimingFinished_ParentEvents; |
+ if (preWarmBetweenSamples) { |
+ fState = kPreWarm_State; |
+ } else { |
+ fTimer.start(); // start timing again, don't change state |
+ } |
+ } else { |
+ fCurrentFrame++; |
+ } |
+ break; |
+ } |
+ } |
+ } |
+ break; |
} |
- return kTiming_ParentEvents; |
+ return parentEvent; |
} |
inline double TimingStateMachine::elapsed() { |
@@ -77,52 +87,14 @@ void TimingStateMachine::resetTimingState() { |
fTimer = WallTimer(); |
} |
-inline TimingStateMachine::ParentEvents TimingStateMachine::tuneLoops() { |
- if (1 << 30 == fLoops) { |
- // We're about to wrap. Something's wrong with the bench. |
- SkDebugf("InnerLoops wrapped\n"); |
- fLoops = 1; |
- return kTiming_ParentEvents; |
- } else { |
- double elapsedMs = this->elapsed(); |
- if (elapsedMs > FLAGS_loopMs) { |
- this->nextState(kPreWarmTimingPerCanvasPreDraw_State); |
- } else { |
- fLoops *= 2; |
- this->nextState(kPreWarmLoops_State); |
- } |
- this->resetTimingState(); |
- return kReset_ParentEvents; |
- } |
-} |
- |
void TimingStateMachine::recordMeasurement() { |
fLastMeasurement = this->elapsed() / (FLAGS_frames * fLoops); |
} |
-inline TimingStateMachine::ParentEvents TimingStateMachine::timing(SkCanvas* canvas, |
- Benchmark* benchmark) { |
- if (fCurrentFrame >= FLAGS_frames) { |
- this->recordMeasurement(); |
- this->resetTimingState(); |
- return kTimingFinished_ParentEvents; |
- } else { |
- fCurrentFrame++; |
- return kTiming_ParentEvents; |
- } |
-} |
- |
void TimingStateMachine::nextBenchmark(SkCanvas* canvas, Benchmark* benchmark) { |
benchmark->postDraw(canvas); |
benchmark->perCanvasPostDraw(canvas); |
fLoops = 1; |
- this->nextState(kPreWarmLoopsPerCanvasPreDraw_State); |
-} |
- |
-void TimingStateMachine::nextSampleWithPrewarm() { |
- this->nextState(kPreWarmTimingPerCanvasPreDraw_State); |
-} |
- |
-void TimingStateMachine::nextSample() { |
- fTimer.start(); |
+ fInnerState = kTuning_InnerState; |
+ fState = kPreWarm_State; |
} |