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

Side by Side Diff: tools/VisualBench/TimingStateMachine.cpp

Issue 1427033003: DM+VB: WallTimer -> SkTime::GetNSecs(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « tools/VisualBench/TimingStateMachine.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "TimingStateMachine.h" 8 #include "TimingStateMachine.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkCommandLineFlags.h" 11 #include "SkCommandLineFlags.h"
12 12
13 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU is al lowed to lag."); 13 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU is al lowed to lag.");
14 DEFINE_int32(frames, 5, "Number of frames of each skp to render per sample."); 14 DEFINE_int32(frames, 5, "Number of frames of each skp to render per sample.");
15 DEFINE_double(loopMs, 5, "Each benchmark will be tuned until it takes loopsMs mi llseconds."); 15 DEFINE_double(loopMs, 5, "Each benchmark will be tuned until it takes loopsMs mi llseconds.");
16 16
17 static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
18
17 TimingStateMachine::TimingStateMachine() 19 TimingStateMachine::TimingStateMachine()
18 : fCurrentFrame(0) 20 : fCurrentFrame(0)
19 , fLoops(1) 21 , fLoops(1)
20 , fLastMeasurement(0.) 22 , fLastMeasurement(0.)
21 , fState(kPreWarm_State) 23 , fState(kPreWarm_State)
22 , fInnerState(kTuning_InnerState) { 24 , fInnerState(kTuning_InnerState) {
23 } 25 }
24 26
25 TimingStateMachine::ParentEvents TimingStateMachine::nextFrame(bool preWarmBetwe enSamples) { 27 TimingStateMachine::ParentEvents TimingStateMachine::nextFrame(bool preWarmBetwe enSamples) {
26 ParentEvents parentEvent = kTiming_ParentEvents; 28 ParentEvents parentEvent = kTiming_ParentEvents;
27 switch (fState) { 29 switch (fState) {
28 case kPreWarm_State: { 30 case kPreWarm_State: {
29 if (fCurrentFrame >= FLAGS_gpuFrameLag) { 31 if (fCurrentFrame >= FLAGS_gpuFrameLag) {
30 fCurrentFrame = 0; 32 fCurrentFrame = 0;
31 fTimer.start(); 33 fStartTime = now_ms();
32 fState = kTiming_State; 34 fState = kTiming_State;
33 } else { 35 } else {
34 fCurrentFrame++; 36 fCurrentFrame++;
35 } 37 }
36 break; 38 break;
37 } 39 }
38 case kTiming_State: { 40 case kTiming_State: {
39 switch (fInnerState) { 41 switch (fInnerState) {
40 case kTuning_InnerState: { 42 case kTuning_InnerState: {
41 if (1 << 30 == fLoops) { 43 if (1 << 30 == fLoops) {
(...skipping 14 matching lines...) Expand all
56 break; 58 break;
57 } 59 }
58 case kTiming_InnerState: { 60 case kTiming_InnerState: {
59 if (fCurrentFrame >= FLAGS_frames) { 61 if (fCurrentFrame >= FLAGS_frames) {
60 this->recordMeasurement(); 62 this->recordMeasurement();
61 this->resetTimingState(); 63 this->resetTimingState();
62 parentEvent = kTimingFinished_ParentEvents; 64 parentEvent = kTimingFinished_ParentEvents;
63 if (preWarmBetweenSamples) { 65 if (preWarmBetweenSamples) {
64 fState = kPreWarm_State; 66 fState = kPreWarm_State;
65 } else { 67 } else {
66 fTimer.start(); // start timing again, don't change state 68 fStartTime = now_ms();
67 } 69 }
68 } else { 70 } else {
69 fCurrentFrame++; 71 fCurrentFrame++;
70 } 72 }
71 break; 73 break;
72 } 74 }
73 } 75 }
74 } 76 }
75 break; 77 break;
76 } 78 }
77 return parentEvent; 79 return parentEvent;
78 } 80 }
79 81
80 inline double TimingStateMachine::elapsed() { 82 inline double TimingStateMachine::elapsed() {
81 fTimer.end(); 83 return now_ms() - fStartTime;
82 return fTimer.fWall;
83 } 84 }
84 85
85 void TimingStateMachine::resetTimingState() { 86 void TimingStateMachine::resetTimingState() {
86 fCurrentFrame = 0; 87 fCurrentFrame = 0;
87 fTimer = WallTimer();
88 } 88 }
89 89
90 void TimingStateMachine::recordMeasurement() { 90 void TimingStateMachine::recordMeasurement() {
91 fLastMeasurement = this->elapsed() / (FLAGS_frames * fLoops); 91 fLastMeasurement = this->elapsed() / (FLAGS_frames * fLoops);
92 } 92 }
93 93
94 void TimingStateMachine::nextBenchmark() { 94 void TimingStateMachine::nextBenchmark() {
95 fLoops = 1; 95 fLoops = 1;
96 fInnerState = kTuning_InnerState; 96 fInnerState = kTuning_InnerState;
97 fState = kPreWarm_State; 97 fState = kPreWarm_State;
98 } 98 }
OLDNEW
« no previous file with comments | « tools/VisualBench/TimingStateMachine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698