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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/BigPathBench.inc ('k') | tools/VisualBench/TimingStateMachine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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