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

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

Issue 1375363003: Factor out VisualBench timing code into a helper class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc 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 unified diff | Download patch
« no previous file with comments | « tools/BigPathBench.inc ('k') | tools/VisualBench/TimingStateMachine.cpp » ('j') | 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 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
20 *
21 * Clients call nextFrame, and must handle any requests from the timing state ma chine, specifically
22 * to reset. When kTimingFinished_ParentEvents is returned, then lastMeasuremen t() will return the
23 * timing and loops() will return the number of loops used to time.
24 *
25 * A client may continue timing the same benchmark indefinitely. To advance to the next
26 * benchmark, the client should call nextBenchmark.
24 */ 27 */
25 class VisualLightweightBenchModule : public VisualModule { 28 class TimingStateMachine {
26 public: 29 public:
27 // TODO get rid of backpointer 30 TimingStateMachine();
28 VisualLightweightBenchModule(VisualBench* owner);
29 31
30 void draw(SkCanvas* canvas) override; 32 enum ParentEvents {
33 kReset_ParentEvents,
34 kTiming_ParentEvents,
35 kTimingFinished_ParentEvents,// This implies parent can read lastMeasure ment() and must
36 // reset
37 };
31 38
32 bool onHandleChar(SkUnichar c) override; 39 ParentEvents nextFrame(SkCanvas* canvas, Benchmark* benchmark);
40
41 /*
42 * The caller should call this when they are ready to move to the next bench mark. The caller
43 * must call this with the *last* benchmark so post draw hooks can be invoke d
44 */
45 void nextBenchmark(SkCanvas*, Benchmark*);
46
47
48 /*
49 * When TimingStateMachine returns kTimingFinished_ParentEvents, then the ow ner can call
50 * lastMeasurement() to get the time
51 */
52 double lastMeasurement() const { return fLastMeasurement; }
53
54 int loops() const { return fLoops; }
33 55
34 private: 56 private:
35 /* 57 /*
36 * The heart of visual bench is an event driven timing loop. 58 * 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 59 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks have a hook to
39 * access the canvas. Then we prewarm before the autotune 60 * access the canvas. Then we prewarm before the autotune
40 * loops step. 61 * loops step.
41 * kPreWarmLoops_State: We prewarm the gpu before auto tuni ng to enter a steady 62 * kPreWarmLoops_State: We prewarm the gpu before auto tuni ng to enter a steady
42 * work state 63 * work state
43 * kTuneLoops_State: Then we tune the loops of the bench mark to ensure we 64 * kTuneLoops_State: Then we tune the loops of the bench mark to ensure we
44 * are doing a measurable amount of wo rk 65 * are doing a measurable amount of wo rk
45 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun ing loops to ensure 66 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun ing loops to ensure
46 * coherent state, we need to give the benchmark 67 * coherent state, we need to give the benchmark
47 * another hook 68 * another hook
48 * kPreWarmTiming_State: We prewarm the gpu again to enter a steady state 69 * kPreWarmTiming_State: We prewarm the gpu again to enter a steady state
49 * kTiming_State: Finally we time the benchmark. Whe n finished timing 70 * kTiming_State: Finally we time the benchmark. Whe n finished timing
50 * if we have enough samples then we'l l start the next 71 * if we have enough samples then we'l l start the next
51 * benchmark in the kPreWarmLoopsPerCa nvasPreDraw_State. 72 * benchmark in the kPreWarmLoopsPerCa nvasPreDraw_State.
52 * otherwise, we enter the 73 * otherwise, we enter the
53 * kPreWarmTimingPerCanvasPreDraw_Stat e for another sample 74 * kPreWarmTimingPerCanvasPreDraw_Stat e for another sample
54 * In either case we reset the context . 75 * In either case we reset the context .
55 */ 76 */
56 enum State { 77 enum State {
57 kWarmup_State,
58 kPreWarmLoopsPerCanvasPreDraw_State, 78 kPreWarmLoopsPerCanvasPreDraw_State,
59 kPreWarmLoops_State, 79 kPreWarmLoops_State,
60 kTuneLoops_State, 80 kTuneLoops_State,
61 kPreWarmTimingPerCanvasPreDraw_State, 81 kPreWarmTimingPerCanvasPreDraw_State,
62 kPreWarmTiming_State, 82 kPreWarmTiming_State,
63 kTiming_State, 83 kTiming_State,
64 }; 84 };
65 void setTitle(); 85
66 bool setupBackend();
67 void setupRenderTarget();
68 void printStats();
69 bool advanceRecordIfNecessary(SkCanvas*);
70 inline void renderFrame(SkCanvas*);
71 inline void nextState(State); 86 inline void nextState(State);
72 void perCanvasPreDraw(SkCanvas*, State); 87 ParentEvents perCanvasPreDraw(SkCanvas*, Benchmark*, State);
73 void preWarm(State nextState); 88 ParentEvents preWarm(State nextState);
74 inline void tuneLoops(); 89 inline ParentEvents tuneLoops();
75 inline void timing(SkCanvas*); 90 inline ParentEvents timing(SkCanvas*, Benchmark*);
76 inline double elapsed(); 91 inline double elapsed();
77 void resetTimingState(); 92 void resetTimingState();
78 void postDraw(SkCanvas*); 93 void postDraw(SkCanvas*, Benchmark*);
79 void recordMeasurement(); 94 void recordMeasurement();
80 void warmup(SkCanvas* canvas);
81 95
82 struct Record {
83 SkTArray<double> fMeasurements;
84 };
85
86 int fCurrentSample;
87 int fCurrentFrame; 96 int fCurrentFrame;
88 int fLoops; 97 int fLoops;
89 SkTArray<Record> fRecords; 98 double fLastMeasurement;
90 WallTimer fTimer; 99 WallTimer fTimer;
91 State fState; 100 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 }; 101 };
101 102
102 #endif 103 #endif
OLDNEW
« no previous file with comments | « tools/BigPathBench.inc ('k') | tools/VisualBench/TimingStateMachine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698