Index: tools/VisualBench/TimingStateMachine.h |
diff --git a/tools/VisualBench/VisualLightweightBenchModule.h b/tools/VisualBench/TimingStateMachine.h |
similarity index 55% |
copy from tools/VisualBench/VisualLightweightBenchModule.h |
copy to tools/VisualBench/TimingStateMachine.h |
index 1a30875c61b0d52f588eef1e56d138fa39243ed9..69ea24337fb752894d32da698946285da862179c 100644 |
--- a/tools/VisualBench/VisualLightweightBenchModule.h |
+++ b/tools/VisualBench/TimingStateMachine.h |
@@ -6,35 +6,56 @@ |
* |
*/ |
-#ifndef VisualLightweightBenchModule_DEFINED |
-#define VisualLightweightBenchModule_DEFINED |
+#ifndef TimingStateMachine_DEFINED |
+#define TimingStateMachine_DEFINED |
-#include "VisualModule.h" |
- |
-#include "ResultsWriter.h" |
-#include "SkPicture.h" |
+#include "Benchmark.h" |
+#include "SkTArray.h" |
#include "Timer.h" |
-#include "VisualBench.h" |
-#include "VisualBenchmarkStream.h" |
class SkCanvas; |
/* |
- * This module is designed to be a minimal overhead timing module for VisualBench |
+ * Manages a timer via a state machine. Can be used by modules to time benchmarks |
+ * |
+ * Clients call nextFrame, and must handle any requests from the timing state machine, specifically |
+ * to reset. When kTimingFinished_ParentEvents is returned, then lastMeasurement() will return the |
+ * timing and loops() will return the number of loops used to time. |
+ * |
+ * A client may continue timing the same benchmark indefinitely. To advance to the next |
+ * benchmark, the client should call nextBenchmark. |
*/ |
-class VisualLightweightBenchModule : public VisualModule { |
+class TimingStateMachine { |
public: |
- // TODO get rid of backpointer |
- VisualLightweightBenchModule(VisualBench* owner); |
+ TimingStateMachine(); |
- void draw(SkCanvas* canvas) override; |
+ enum ParentEvents { |
+ kReset_ParentEvents, |
+ kTiming_ParentEvents, |
+ kTimingFinished_ParentEvents,// This implies parent can read lastMeasurement() and must |
+ // reset |
+ }; |
- bool onHandleChar(SkUnichar c) override; |
+ ParentEvents nextFrame(SkCanvas* canvas, Benchmark* benchmark); |
+ |
+ /* |
+ * The caller should call this when they are ready to move to the next benchmark. The caller |
+ * must call this with the *last* benchmark so post draw hooks can be invoked |
+ */ |
+ void nextBenchmark(SkCanvas*, Benchmark*); |
+ |
+ |
+ /* |
+ * When TimingStateMachine returns kTimingFinished_ParentEvents, then the owner can call |
+ * lastMeasurement() to get the time |
+ */ |
+ double lastMeasurement() const { return fLastMeasurement; } |
+ |
+ int loops() const { return fLoops; } |
private: |
/* |
- * The heart of visual bench is an event driven timing loop. |
- * kWarmup_State: We run a dummy bench to let things settle on startup |
+ * The heart of the timing state machine is an event driven timing loop. |
* kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks have a hook to |
* access the canvas. Then we prewarm before the autotune |
* loops step. |
@@ -54,7 +75,6 @@ private: |
* In either case we reset the context. |
*/ |
enum State { |
- kWarmup_State, |
kPreWarmLoopsPerCanvasPreDraw_State, |
kPreWarmLoops_State, |
kTuneLoops_State, |
@@ -62,41 +82,22 @@ private: |
kPreWarmTiming_State, |
kTiming_State, |
}; |
- void setTitle(); |
- bool setupBackend(); |
- void setupRenderTarget(); |
- void printStats(); |
- bool advanceRecordIfNecessary(SkCanvas*); |
- inline void renderFrame(SkCanvas*); |
+ |
inline void nextState(State); |
- void perCanvasPreDraw(SkCanvas*, State); |
- void preWarm(State nextState); |
- inline void tuneLoops(); |
- inline void timing(SkCanvas*); |
+ ParentEvents perCanvasPreDraw(SkCanvas*, Benchmark*, State); |
+ ParentEvents preWarm(State nextState); |
+ inline ParentEvents tuneLoops(); |
+ inline ParentEvents timing(SkCanvas*, Benchmark*); |
inline double elapsed(); |
void resetTimingState(); |
- void postDraw(SkCanvas*); |
+ void postDraw(SkCanvas*, Benchmark*); |
void recordMeasurement(); |
- void warmup(SkCanvas* canvas); |
- struct Record { |
- SkTArray<double> fMeasurements; |
- }; |
- |
- int fCurrentSample; |
int fCurrentFrame; |
int fLoops; |
- SkTArray<Record> fRecords; |
+ double fLastMeasurement; |
WallTimer fTimer; |
State fState; |
- SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; |
- SkAutoTUnref<Benchmark> fBenchmark; |
- |
- // support framework |
- SkAutoTUnref<VisualBench> fOwner; |
- SkAutoTDelete<ResultsWriter> fResults; |
- |
- typedef VisualModule INHERITED; |
}; |
#endif |