OLD | NEW |
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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 break; | 38 break; |
39 } | 39 } |
40 case kTiming_State: { | 40 case kTiming_State: { |
41 switch (fInnerState) { | 41 switch (fInnerState) { |
42 case kTuning_InnerState: { | 42 case kTuning_InnerState: { |
43 if (1 << 30 == fLoops) { | 43 if (1 << 30 == fLoops) { |
44 // We're about to wrap. Something's wrong with the benc
h. | 44 // We're about to wrap. Something's wrong with the benc
h. |
45 SkDebugf("InnerLoops wrapped\n"); | 45 SkDebugf("InnerLoops wrapped\n"); |
46 fLoops = 1; | 46 fLoops = 1; |
47 } else { | 47 } else { |
48 double elapsedMs = this->elapsed(); | 48 double elapsedMs = now_ms() - fStartTime; |
49 if (elapsedMs < FLAGS_loopMs) { | 49 if (elapsedMs < FLAGS_loopMs) { |
50 fLoops *= 2; | 50 fLoops *= 2; |
51 } else { | 51 } else { |
52 fInnerState = kTiming_InnerState; | 52 fInnerState = kTiming_InnerState; |
53 } | 53 } |
54 fState = kPreWarm_State; | 54 fState = kPreWarm_State; |
55 this->resetTimingState(); | 55 fCurrentFrame = 0; |
56 parentEvent = kReset_ParentEvents; | 56 parentEvent = kReset_ParentEvents; |
57 } | 57 } |
58 break; | 58 break; |
59 } | 59 } |
60 case kTiming_InnerState: { | 60 case kTiming_InnerState: { |
61 if (fCurrentFrame >= FLAGS_frames) { | 61 if (fCurrentFrame >= FLAGS_frames) { |
62 this->recordMeasurement(); | 62 double now = now_ms(); |
63 this->resetTimingState(); | 63 fLastMeasurement = (now - fStartTime) / (FLAGS_frames *
fLoops); |
| 64 fCurrentFrame = 0; |
64 parentEvent = kTimingFinished_ParentEvents; | 65 parentEvent = kTimingFinished_ParentEvents; |
65 if (preWarmBetweenSamples) { | 66 if (preWarmBetweenSamples) { |
66 fState = kPreWarm_State; | 67 fState = kPreWarm_State; |
67 } else { | 68 } else { |
68 fStartTime = now_ms(); | 69 fStartTime = now; |
69 } | 70 } |
70 } else { | 71 } else { |
71 fCurrentFrame++; | 72 fCurrentFrame++; |
72 } | 73 } |
73 break; | 74 break; |
74 } | 75 } |
75 } | 76 } |
76 } | 77 } |
77 break; | 78 break; |
78 } | 79 } |
79 return parentEvent; | 80 return parentEvent; |
80 } | 81 } |
81 | 82 |
82 inline double TimingStateMachine::elapsed() { | |
83 return now_ms() - fStartTime; | |
84 } | |
85 | |
86 void TimingStateMachine::resetTimingState() { | |
87 fCurrentFrame = 0; | |
88 } | |
89 | |
90 void TimingStateMachine::recordMeasurement() { | |
91 fLastMeasurement = this->elapsed() / (FLAGS_frames * fLoops); | |
92 } | |
93 | |
94 void TimingStateMachine::nextBenchmark() { | 83 void TimingStateMachine::nextBenchmark() { |
95 fLoops = 1; | 84 fLoops = 1; |
96 fInnerState = kTuning_InnerState; | 85 fInnerState = kTuning_InnerState; |
97 fState = kPreWarm_State; | 86 fState = kPreWarm_State; |
98 } | 87 } |
OLD | NEW |