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 | 8 |
9 #ifndef VisualLightweightBenchModule_DEFINED | 9 #ifndef TimingStateMachine_DEFINED |
10 #define VisualLightweightBenchModule_DEFINED | 10 #define TimingStateMachine_DEFINED |
11 | 11 |
12 #include "VisualModule.h" | 12 #include "Benchmark.h" |
13 | 13 #include "SkTArray.h" |
14 #include "ResultsWriter.h" | |
15 #include "SkPicture.h" | |
16 #include "Timer.h" | 14 #include "Timer.h" |
17 #include "VisualBench.h" | |
18 #include "VisualBenchmarkStream.h" | |
19 | 15 |
20 class SkCanvas; | 16 class SkCanvas; |
21 | 17 |
22 /* | 18 /* |
23 * This module is designed to be a minimal overhead timing module for VisualBenc h | 19 * Manages a timer via a state machine. Can be used by modules to time benchmar ks |
robertphillips
2015/10/05 13:05:01
// The normal calling pattern for a client is:
//
| |
24 */ | 20 */ |
25 class VisualLightweightBenchModule : public VisualModule { | 21 class TimingStateMachine { |
26 public: | 22 public: |
27 // TODO get rid of backpointer | 23 TimingStateMachine(); |
28 VisualLightweightBenchModule(VisualBench* owner); | |
29 | 24 |
30 void draw(SkCanvas* canvas) override; | 25 enum ParentEvents { |
26 kReset_ParentEvents, | |
27 kTiming_ParentEvents, | |
28 kTimingFinished_ParentEvents,// This implies parent can read lastMeasure ment() and must | |
29 // reset | |
30 }; | |
31 | 31 |
32 bool onHandleChar(SkUnichar c) override; | 32 ParentEvents nextFrame(SkCanvas* canvas, Benchmark* benchmark); |
33 | |
34 /* | |
robertphillips
2015/10/05 13:05:01
They -> The ?
| |
35 * The caller should call this when they are ready to move to the next bench mark. They caller | |
36 * must call this with the *last* benchmark so post draw hooks can be invoke d | |
37 */ | |
38 void nextBenchmark(SkCanvas*, Benchmark*); | |
39 | |
40 | |
41 /* | |
robertphillips
2015/10/05 13:05:01
kTimingFinished_ParentEvents not kNext... ?
| |
42 * When TimingStateMachine returns kNextBenchmark_ParentEvents, then the own er can call | |
robertphillips
2015/10/05 13:05:01
lastMeasur_e_ment ?
| |
43 * lastMeasurment() to get the time | |
44 */ | |
45 double lastMeasurement() const { return fLastMeasurement; } | |
46 | |
47 int loops() const { return fLoops; } | |
33 | 48 |
34 private: | 49 private: |
35 /* | 50 /* |
36 * The heart of visual bench is an event driven timing loop. | 51 * The heart of the timing state machine is an event driven timing loop. |
37 * kWarmup_State: We run a dummy bench to let things settle on startup | |
38 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks have a hook to | 52 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks have a hook to |
39 * access the canvas. Then we prewarm before the autotune | 53 * access the canvas. Then we prewarm before the autotune |
40 * loops step. | 54 * loops step. |
41 * kPreWarmLoops_State: We prewarm the gpu before auto tuni ng to enter a steady | 55 * kPreWarmLoops_State: We prewarm the gpu before auto tuni ng to enter a steady |
42 * work state | 56 * work state |
43 * kTuneLoops_State: Then we tune the loops of the bench mark to ensure we | 57 * kTuneLoops_State: Then we tune the loops of the bench mark to ensure we |
44 * are doing a measurable amount of wo rk | 58 * are doing a measurable amount of wo rk |
45 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun ing loops to ensure | 59 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun ing loops to ensure |
46 * coherent state, we need to give the benchmark | 60 * coherent state, we need to give the benchmark |
47 * another hook | 61 * another hook |
48 * kPreWarmTiming_State: We prewarm the gpu again to enter a steady state | 62 * kPreWarmTiming_State: We prewarm the gpu again to enter a steady state |
49 * kTiming_State: Finally we time the benchmark. Whe n finished timing | 63 * kTiming_State: Finally we time the benchmark. Whe n finished timing |
50 * if we have enough samples then we'l l start the next | 64 * if we have enough samples then we'l l start the next |
51 * benchmark in the kPreWarmLoopsPerCa nvasPreDraw_State. | 65 * benchmark in the kPreWarmLoopsPerCa nvasPreDraw_State. |
52 * otherwise, we enter the | 66 * otherwise, we enter the |
53 * kPreWarmTimingPerCanvasPreDraw_Stat e for another sample | 67 * kPreWarmTimingPerCanvasPreDraw_Stat e for another sample |
54 * In either case we reset the context . | 68 * In either case we reset the context . |
55 */ | 69 */ |
56 enum State { | 70 enum State { |
57 kWarmup_State, | |
58 kPreWarmLoopsPerCanvasPreDraw_State, | 71 kPreWarmLoopsPerCanvasPreDraw_State, |
59 kPreWarmLoops_State, | 72 kPreWarmLoops_State, |
60 kTuneLoops_State, | 73 kTuneLoops_State, |
61 kPreWarmTimingPerCanvasPreDraw_State, | 74 kPreWarmTimingPerCanvasPreDraw_State, |
62 kPreWarmTiming_State, | 75 kPreWarmTiming_State, |
63 kTiming_State, | 76 kTiming_State, |
64 }; | 77 }; |
65 void setTitle(); | 78 |
66 bool setupBackend(); | |
67 void setupRenderTarget(); | |
68 void printStats(); | |
69 bool advanceRecordIfNecessary(SkCanvas*); | |
70 inline void renderFrame(SkCanvas*); | |
71 inline void nextState(State); | 79 inline void nextState(State); |
72 void perCanvasPreDraw(SkCanvas*, State); | 80 ParentEvents perCanvasPreDraw(SkCanvas*, Benchmark*, State); |
73 void preWarm(State nextState); | 81 ParentEvents preWarm(State nextState); |
74 inline void tuneLoops(); | 82 inline ParentEvents tuneLoops(); |
75 inline void timing(SkCanvas*); | 83 inline ParentEvents timing(SkCanvas*, Benchmark*); |
76 inline double elapsed(); | 84 inline double elapsed(); |
77 void resetTimingState(); | 85 void resetTimingState(); |
78 void postDraw(SkCanvas*); | 86 void postDraw(SkCanvas*, Benchmark*); |
79 void recordMeasurement(); | 87 void recordMeasurement(); |
80 void warmup(SkCanvas* canvas); | |
81 | 88 |
82 struct Record { | |
83 SkTArray<double> fMeasurements; | |
84 }; | |
85 | |
86 int fCurrentSample; | |
87 int fCurrentFrame; | 89 int fCurrentFrame; |
88 int fLoops; | 90 int fLoops; |
89 SkTArray<Record> fRecords; | 91 double fLastMeasurement; |
90 WallTimer fTimer; | 92 WallTimer fTimer; |
91 State fState; | 93 State fState; |
92 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; | |
93 SkAutoTUnref<Benchmark> fBenchmark; | |
94 | |
95 // support framework | |
96 SkAutoTUnref<VisualBench> fOwner; | |
97 SkAutoTDelete<ResultsWriter> fResults; | |
98 | |
99 typedef VisualModule INHERITED; | |
100 }; | 94 }; |
101 | 95 |
102 #endif | 96 #endif |
OLD | NEW |