skia2/tools/VisualBench/TimingStateMachine.h
joshualitt a3b8c67ea6 Revert of small tidy of benchmarkstream (patchset #2 id:20001 of https://codereview.chromium.org/1395703002/ )
Reason for revert:
Breaks visualbench

Original issue's description:
> small tidy of benchmarkstream
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/691b6af907e55250a29a7a2a346b63c2026011c3

TBR=robertphillips@google.com,joshualitt@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1392833006
2015-10-14 14:45:07 -07:00

77 lines
2.0 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef TimingStateMachine_DEFINED
#define TimingStateMachine_DEFINED
#include "Benchmark.h"
#include "SkTArray.h"
#include "Timer.h"
class SkCanvas;
/*
* 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 TimingStateMachine {
public:
TimingStateMachine();
enum ParentEvents {
kReset_ParentEvents,
kTiming_ParentEvents,
kTimingFinished_ParentEvents,// This implies parent can read lastMeasurement() and must
// reset
};
ParentEvents nextFrame(bool preWarmBetweenSamples);
/*
* 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:
enum State {
kPreWarm_State,
kTiming_State,
};
enum InnerState {
kTuning_InnerState,
kTiming_InnerState,
};
inline double elapsed();
void resetTimingState();
void recordMeasurement();
int fCurrentFrame;
int fLoops;
double fLastMeasurement;
WallTimer fTimer;
State fState;
InnerState fInnerState;
};
#endif