Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Unified Diff: tools/VisualBench/TimingStateMachine.cpp

Issue 1386933002: Cleanup timing state machine (Closed) Base URL: https://skia.googlesource.com/skia.git@vb2
Patch Set: rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/VisualBench/TimingStateMachine.h ('k') | tools/VisualBench/VisualInteractiveModule.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « tools/VisualBench/TimingStateMachine.h ('k') | tools/VisualBench/VisualInteractiveModule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698