2015-10-05 14:23:30 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
2015-10-05 20:58:26 +00:00
|
|
|
ParentEvents nextFrame(bool preWarmBetweenSamples);
|
2015-10-05 20:24:55 +00:00
|
|
|
|
2015-10-05 14:23:30 +00:00
|
|
|
/*
|
2015-10-15 14:18:29 +00:00
|
|
|
* The caller should call this when they are ready to move to the next benchmark.
|
2015-10-05 14:23:30 +00:00
|
|
|
*/
|
2015-10-15 14:18:29 +00:00
|
|
|
void nextBenchmark();
|
2015-10-05 14:23:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 {
|
2015-10-05 20:58:26 +00:00
|
|
|
kPreWarm_State,
|
2015-10-05 14:23:30 +00:00
|
|
|
kTiming_State,
|
|
|
|
};
|
2015-10-05 20:58:26 +00:00
|
|
|
enum InnerState {
|
|
|
|
kTuning_InnerState,
|
|
|
|
kTiming_InnerState,
|
|
|
|
};
|
2015-10-05 14:23:30 +00:00
|
|
|
|
|
|
|
int fCurrentFrame;
|
|
|
|
int fLoops;
|
|
|
|
double fLastMeasurement;
|
2015-11-03 14:54:24 +00:00
|
|
|
double fStartTime;
|
2015-10-05 14:23:30 +00:00
|
|
|
State fState;
|
2015-10-05 20:58:26 +00:00
|
|
|
InnerState fInnerState;
|
2015-10-05 14:23:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|