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

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: tweaks 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 | « no previous file | tools/VisualBench/TimingStateMachine.cpp » ('j') | tools/VisualBench/TimingStateMachine.cpp » ('J')
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 60%
copy from tools/VisualBench/VisualLightweightBenchModule.h
copy to tools/VisualBench/TimingStateMachine.h
index 1a30875c61b0d52f588eef1e56d138fa39243ed9..b77d32bec14b48a11b2be335609333969a0cb720 100644
--- a/tools/VisualBench/VisualLightweightBenchModule.h
+++ b/tools/VisualBench/TimingStateMachine.h
@@ -6,35 +6,49 @@
*
*/
-#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
robertphillips 2015/10/05 13:05:01 // The normal calling pattern for a client is: //
*/
-class VisualLightweightBenchModule : public VisualModule {
+class TimingStateMachine {
public:
- // TODO get rid of backpointer
- VisualLightweightBenchModule(VisualBench* owner);
+ TimingStateMachine();
+
+ enum ParentEvents {
+ kReset_ParentEvents,
+ kTiming_ParentEvents,
+ kTimingFinished_ParentEvents,// This implies parent can read lastMeasurement() and must
+ // reset
+ };
+
+ ParentEvents nextFrame(SkCanvas* canvas, Benchmark* benchmark);
- void draw(SkCanvas* canvas) override;
+ /*
robertphillips 2015/10/05 13:05:01 They -> The ?
+ * The caller should call this when they are ready to move to the next benchmark. They caller
+ * must call this with the *last* benchmark so post draw hooks can be invoked
+ */
+ void nextBenchmark(SkCanvas*, Benchmark*);
- bool onHandleChar(SkUnichar c) override;
+
+ /*
robertphillips 2015/10/05 13:05:01 kTimingFinished_ParentEvents not kNext... ?
+ * When TimingStateMachine returns kNextBenchmark_ParentEvents, then the owner can call
robertphillips 2015/10/05 13:05:01 lastMeasur_e_ment ?
+ * lastMeasurment() 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 +68,6 @@ private:
* In either case we reset the context.
*/
enum State {
- kWarmup_State,
kPreWarmLoopsPerCanvasPreDraw_State,
kPreWarmLoops_State,
kTuneLoops_State,
@@ -62,41 +75,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 | « no previous file | tools/VisualBench/TimingStateMachine.cpp » ('j') | tools/VisualBench/TimingStateMachine.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698