DM+VB: WallTimer -> SkTime::GetNSecs().
The same timer with a simpler interface.
BUG=skia:
Review URL: https://codereview.chromium.org/1427033003
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 2723103..236b100 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -75,6 +75,8 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
+
SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
static SkTArray<SkString> gFailures;
@@ -830,8 +832,7 @@
}
SkString log;
- WallTimer timer;
- timer.start();
+ auto timerStart = now_ms();
if (!FLAGS_dryRun && note.isEmpty()) {
SkBitmap bitmap;
SkDynamicMemoryWStream stream;
@@ -841,7 +842,7 @@
start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
if (!err.isEmpty()) {
- timer.end();
+ auto elapsed = now_ms() - timerStart;
if (err.isFatal()) {
fail(SkStringPrintf("%s %s %s %s: %s",
task->sink.tag,
@@ -852,7 +853,7 @@
} else {
note.appendf(" (skipped: %s)", err.c_str());
}
- done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
+ done(elapsed, task->sink.tag, task->src.tag, task->src.options,
name, note, log);
return;
}
@@ -906,9 +907,8 @@
}
}
}
- timer.end();
- done(timer.fWall, task->sink.tag, task->src.tag.c_str(), task->src.options.c_str(), name,
- note, log);
+ done(now_ms()-timerStart, task->sink.tag, task->src.tag.c_str(), task->src.options.c_str(),
+ name, note, log);
}
static void WriteToDisk(const Task& task,
@@ -1032,8 +1032,7 @@
note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
}
- WallTimer timer;
- timer.start();
+ auto timerStart = now_ms();
if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
start("unit", "test", "", test->name);
GrContextFactory factory;
@@ -1042,8 +1041,7 @@
}
test->proc(&reporter, &factory);
}
- timer.end();
- done(timer.fWall, "unit", "test", "", test->name, note, "");
+ done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
diff --git a/tools/VisualBench/TimingStateMachine.cpp b/tools/VisualBench/TimingStateMachine.cpp
index 85aab42..4dfa3f5 100644
--- a/tools/VisualBench/TimingStateMachine.cpp
+++ b/tools/VisualBench/TimingStateMachine.cpp
@@ -14,6 +14,8 @@
DEFINE_int32(frames, 5, "Number of frames of each skp to render per sample.");
DEFINE_double(loopMs, 5, "Each benchmark will be tuned until it takes loopsMs millseconds.");
+static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
+
TimingStateMachine::TimingStateMachine()
: fCurrentFrame(0)
, fLoops(1)
@@ -28,7 +30,7 @@
case kPreWarm_State: {
if (fCurrentFrame >= FLAGS_gpuFrameLag) {
fCurrentFrame = 0;
- fTimer.start();
+ fStartTime = now_ms();
fState = kTiming_State;
} else {
fCurrentFrame++;
@@ -63,7 +65,7 @@
if (preWarmBetweenSamples) {
fState = kPreWarm_State;
} else {
- fTimer.start(); // start timing again, don't change state
+ fStartTime = now_ms();
}
} else {
fCurrentFrame++;
@@ -78,13 +80,11 @@
}
inline double TimingStateMachine::elapsed() {
- fTimer.end();
- return fTimer.fWall;
+ return now_ms() - fStartTime;
}
void TimingStateMachine::resetTimingState() {
fCurrentFrame = 0;
- fTimer = WallTimer();
}
void TimingStateMachine::recordMeasurement() {
diff --git a/tools/VisualBench/TimingStateMachine.h b/tools/VisualBench/TimingStateMachine.h
index 3f40b6d..322c333 100644
--- a/tools/VisualBench/TimingStateMachine.h
+++ b/tools/VisualBench/TimingStateMachine.h
@@ -67,7 +67,7 @@
int fCurrentFrame;
int fLoops;
double fLastMeasurement;
- WallTimer fTimer;
+ double fStartTime;
State fState;
InnerState fInnerState;
};