Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
|
robertphillips
2015/10/05 13:05:01
extra line here ?
| |
| 6 * | |
| 7 */ | |
| 8 | |
| 9 #include "TimingStateMachine.h" | |
| 10 | |
| 11 #include "SkCanvas.h" | |
| 12 #include "SkCommandLineFlags.h" | |
| 13 | |
|
robertphillips
2015/10/05 13:05:01
allows -> allowed ?
| |
| 14 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); | |
| 15 DEFINE_int32(frames, 5, "Number of frames of each skp to render per sample."); | |
|
robertphillips
2015/10/05 13:05:01
// Each test will be tuned so that it consumes at
| |
| 16 DEFINE_double(loopMs, 5, "Target loop time in millseconds."); | |
| 17 | |
| 18 TimingStateMachine::TimingStateMachine() | |
| 19 : fCurrentFrame(0) | |
| 20 , fLoops(1) | |
| 21 , fLastMeasurement(0.) | |
| 22 , fState(kPreWarmLoopsPerCanvasPreDraw_State) { | |
| 23 } | |
| 24 | |
| 25 TimingStateMachine::ParentEvents TimingStateMachine::nextFrame(SkCanvas* canvas, | |
| 26 Benchmark* benchm ark) { | |
| 27 switch (fState) { | |
| 28 case kPreWarmLoopsPerCanvasPreDraw_State: | |
| 29 return this->perCanvasPreDraw(canvas, benchmark, kPreWarmLoops_State ); | |
| 30 case kPreWarmLoops_State: | |
| 31 return this->preWarm(kTuneLoops_State); | |
| 32 case kTuneLoops_State: | |
| 33 return this->tuneLoops(); | |
| 34 case kPreWarmTimingPerCanvasPreDraw_State: | |
| 35 return this->perCanvasPreDraw(canvas, benchmark, kPreWarmTiming_Stat e); | |
| 36 case kPreWarmTiming_State: | |
| 37 return this->preWarm(kTiming_State); | |
| 38 case kTiming_State: | |
| 39 return this->timing(canvas, benchmark); | |
| 40 } | |
| 41 SkFAIL("Incomplete switch\n"); | |
| 42 return kTiming_ParentEvents; | |
| 43 } | |
| 44 | |
| 45 inline void TimingStateMachine::nextState(State nextState) { | |
| 46 fState = nextState; | |
| 47 } | |
| 48 | |
| 49 TimingStateMachine::ParentEvents TimingStateMachine::perCanvasPreDraw(SkCanvas* canvas, | |
| 50 Benchmark* benchmark, | |
| 51 State next State) { | |
| 52 benchmark->perCanvasPreDraw(canvas); | |
| 53 benchmark->preDraw(canvas); | |
| 54 fCurrentFrame = 0; | |
| 55 this->nextState(nextState); | |
| 56 return kTiming_ParentEvents; | |
| 57 } | |
| 58 | |
| 59 TimingStateMachine::ParentEvents TimingStateMachine::preWarm(State nextState) { | |
| 60 if (fCurrentFrame >= FLAGS_gpuFrameLag) { | |
| 61 // we currently time across all frames to make sure we capture all GPU w ork | |
| 62 this->nextState(nextState); | |
| 63 fCurrentFrame = 0; | |
| 64 fTimer.start(); | |
| 65 } else { | |
| 66 fCurrentFrame++; | |
| 67 } | |
| 68 return kTiming_ParentEvents; | |
| 69 } | |
| 70 | |
| 71 inline double TimingStateMachine::elapsed() { | |
| 72 fTimer.end(); | |
| 73 return fTimer.fWall; | |
| 74 } | |
| 75 | |
| 76 void TimingStateMachine::resetTimingState() { | |
| 77 fCurrentFrame = 0; | |
| 78 fTimer = WallTimer(); | |
| 79 } | |
| 80 | |
| 81 inline TimingStateMachine::ParentEvents TimingStateMachine::tuneLoops() { | |
| 82 if (1 << 30 == fLoops) { | |
| 83 // We're about to wrap. Something's wrong with the bench. | |
| 84 SkDebugf("InnerLoops wrapped\n"); | |
| 85 fLoops = 1; | |
| 86 return kTiming_ParentEvents; | |
| 87 } else { | |
| 88 double elapsedMs = this->elapsed(); | |
| 89 if (elapsedMs > FLAGS_loopMs) { | |
| 90 this->nextState(kPreWarmTimingPerCanvasPreDraw_State); | |
| 91 } else { | |
| 92 fLoops *= 2; | |
| 93 this->nextState(kPreWarmLoops_State); | |
| 94 } | |
| 95 this->resetTimingState(); | |
| 96 return kReset_ParentEvents; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 void TimingStateMachine::recordMeasurement() { | |
| 101 fLastMeasurement = this->elapsed() / (FLAGS_frames * fLoops); | |
| 102 } | |
| 103 | |
| 104 void TimingStateMachine::nextBenchmark(SkCanvas* canvas, Benchmark* benchmark) { | |
| 105 benchmark->postDraw(canvas); | |
| 106 benchmark->perCanvasPostDraw(canvas); | |
| 107 fLoops = 1; | |
| 108 this->nextState(kPreWarmLoopsPerCanvasPreDraw_State); | |
| 109 } | |
| 110 | |
| 111 inline TimingStateMachine::ParentEvents TimingStateMachine::timing(SkCanvas* can vas, | |
| 112 Benchmark* be nchmark) { | |
| 113 if (fCurrentFrame >= FLAGS_frames) { | |
| 114 this->recordMeasurement(); | |
| 115 this->resetTimingState(); | |
| 116 this->nextState(kPreWarmTimingPerCanvasPreDraw_State); | |
| 117 return kTimingFinished_ParentEvents; | |
| 118 } else { | |
| 119 fCurrentFrame++; | |
| 120 return kTiming_ParentEvents; | |
| 121 } | |
| 122 } | |
| 123 | |
| OLD | NEW |