Commit 9ac68ee2 authored by mtklein's avatar mtklein Committed by Commit bot
Browse files

Move BenchTimer to tools as Timer

This breaks a bunch of circular dependencies between tools and gm and bench.

BUG=skia:

Committed: https://skia.googlesource.com/skia/+/4ed75287aed6371c6e4a41ffcc78c8a49c9810ed

CQ_EXTRA_TRYBOTS=tryserver.skia:Build-Mac10.7-Clang-Arm7-Debug-iOS-Trybot,Test-Ubuntu12-ShuttleA-GTX660-x86-Debug-Trybot
R=tfarina@chromium.org, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/344213003
parent 24480bc7
......@@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "BenchTimer.h"
#include "Timer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
......@@ -42,13 +42,13 @@ void PictureBenchmark::setTimersToShow(bool wall,
fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0;
}
BenchTimer* PictureBenchmark::setupTimer(bool useGLTimer) {
Timer* PictureBenchmark::setupTimer(bool useGLTimer) {
#if SK_SUPPORT_GPU
if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) {
return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext()));
return SkNEW_ARGS(Timer, (fRenderer->getGLContext()));
}
#endif
return SkNEW_ARGS(BenchTimer, (NULL));
return SkNEW_ARGS(Timer, (NULL));
}
PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) {
......@@ -147,11 +147,11 @@ void PictureBenchmark::run(SkPicture* pict) {
// seems to cause problems (i.e., INVALID_OPERATIONs) on several
// platforms. To work around this, we disable the gpu timer on the
// long running timer.
SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer());
SkAutoTDelete<Timer> longRunningTimer(this->setupTimer());
TimerData longRunningTimerData(numOuterLoops);
for (int outer = 0; outer < numOuterLoops; ++outer) {
SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer(false));
SkAutoTDelete<Timer> perTileTimer(this->setupTimer(false));
TimerData perTileTimerData(numInnerLoops);
longRunningTimer->start();
......@@ -201,11 +201,11 @@ void PictureBenchmark::run(SkPicture* pict) {
numInnerLoops);
}
} else {
SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer());
SkAutoTDelete<Timer> longRunningTimer(this->setupTimer());
TimerData longRunningTimerData(numOuterLoops);
for (int outer = 0; outer < numOuterLoops; ++outer) {
SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false));
SkAutoTDelete<Timer> perRunTimer(this->setupTimer(false));
TimerData perRunTimerData(numInnerLoops);
longRunningTimer->start();
......
......@@ -13,8 +13,8 @@
#include "SkTypes.h"
#include "TimerData.h"
class BenchTimer;
class SkPicture;
class Timer;
namespace sk_tools {
......@@ -67,7 +67,7 @@ private:
PictureResultsWriter* fWriter;
BenchTimer* setupTimer(bool useGLTimer = true);
Timer* setupTimer(bool useGLTimer = true);
};
}
......
......@@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "BenchTimer.h"
#include "Timer.h"
#include "Benchmark.h"
#include "LazyDecodeBitmap.h"
#include "PictureBenchmark.h"
......@@ -64,7 +64,7 @@ static void do_benchmark_work(sk_tools::PictureRenderer* renderer,
BBoxType bBoxType,
SkPicture* pic,
const int numRepeats,
BenchTimer* timer) {
Timer* timer) {
renderer->setBBoxHierarchyType(bBoxType);
renderer->setGridSize(FLAGS_tilesize, FLAGS_tilesize);
renderer->init(pic, NULL, NULL, NULL, false);
......@@ -106,14 +106,14 @@ int tool_main(int argc, char** argv) {
if (!includeBBoxType[bBoxType]) { continue; }
if (FLAGS_playback > 0) {
sk_tools::TiledPictureRenderer playbackRenderer;
BenchTimer playbackTimer;
Timer playbackTimer;
do_benchmark_work(&playbackRenderer, (BBoxType)bBoxType,
picture, FLAGS_playback, &playbackTimer);
measurement.fPlaybackAverage[bBoxType] = playbackTimer.fCpu;
}
if (FLAGS_record > 0) {
sk_tools::RecordPictureRenderer recordRenderer;
BenchTimer recordTimer;
Timer recordTimer;
do_benchmark_work(&recordRenderer, (BBoxType)bBoxType,
picture, FLAGS_record, &recordTimer);
measurement.fRecordAverage[bBoxType] = recordTimer.fCpu;
......
......@@ -6,7 +6,7 @@
*/
#include "BenchLogger.h"
#include "BenchTimer.h"
#include "Timer.h"
#include "CopyTilesRenderer.h"
#include "CrashHandler.h"
#include "LazyDecodeBitmap.h"
......
......@@ -16,10 +16,8 @@
#include "../include/record/SkRecording.h"
#include "BenchTimer.h"
#include "Stats.h"
typedef WallTimer Timer;
#include "Timer.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
......@@ -78,15 +76,16 @@ static void bench(SkPMColor* scratch, SkPicture& src, const char* name) {
// Draw once to warm any caches. The first sample otherwise can be very noisy.
draw(*record, *picture, canvas.get());
Timer timer;
WallTimer timer;
const double scale = timescale();
SkAutoTMalloc<double> samples(FLAGS_samples);
for (int i = 0; i < FLAGS_samples; i++) {
// We assume timer overhead (typically, ~30ns) is insignificant
// compared to draw runtime (at least ~100us, usually several ms).
timer.start(timescale());
timer.start();
draw(*record, *picture, canvas.get());
timer.end();
samples[i] = timer.fWall;
samples[i] = timer.fWall * scale;
}
Stats stats(samples.get(), FLAGS_samples);
......
......@@ -14,11 +14,9 @@
#include "SkStream.h"
#include "SkString.h"
#include "BenchTimer.h"
#include "LazyDecodeBitmap.h"
#include "Stats.h"
typedef WallTimer Timer;
#include "Timer.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
......@@ -81,12 +79,13 @@ static void bench_record(const SkPicture& src,
rerecord(src, bbhFactory);
// Rerecord once to see how many times we should loop to make timer overhead insignificant.
Timer timer;
WallTimer timer;
const double scale = timescale();
do {
timer.start(timescale());
timer.start();
rerecord(src, bbhFactory);
timer.end();
} while (timer.fWall < timerOverhead); // Loop just in case something bizarre happens.
} while (timer.fWall * scale < timerOverhead); // Loop just in case something bizarre happens.
// We want (timer overhead / measurement) to be less than FLAGS_overheadGoal.
// So in each sample, we'll loop enough times to have made that true for our first measurement.
......@@ -94,12 +93,12 @@ static void bench_record(const SkPicture& src,
SkAutoTMalloc<double> samples(FLAGS_samples);
for (int i = 0; i < FLAGS_samples; i++) {
timer.start(timescale());
timer.start();
for (int j = 0; j < loops; j++) {
rerecord(src, bbhFactory);
}
timer.end();
samples[i] = timer.fWall / loops;
samples[i] = timer.fWall * scale / loops;
}
Stats stats(samples.get(), FLAGS_samples);
......@@ -132,12 +131,13 @@ int tool_main(int argc, char** argv) {
// Each run will use this timer overhead estimate to guess how many times it should run.
static const int kOverheadLoops = 10000000;
Timer timer;
WallTimer timer;
double overheadEstimate = 0.0;
const double scale = timescale();
for (int i = 0; i < kOverheadLoops; i++) {
timer.start(timescale());
timer.start();
timer.end();
overheadEstimate += timer.fWall;
overheadEstimate += timer.fWall * scale;
}
overheadEstimate /= kOverheadLoops;
......
......@@ -83,7 +83,7 @@ const char* cl_error_to_string(cl_int err) {
}
#endif
// TODO refactor BenchTimer to be used here
// TODO refactor Timer to be used here
double get_seconds() {
#if SK_BUILD_FOR_WIN32
LARGE_INTEGER currentTime;
......
......@@ -5,34 +5,37 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "BenchGpuTimer_gl.h"
#include "GpuTimer.h"
#include "gl/SkGLContextHelper.h"
#include "gl/GrGLUtil.h"
BenchGpuTimer::BenchGpuTimer(const SkGLContextHelper* glctx) {
fContext = glctx;
glctx->ref();
glctx->makeCurrent();
fStarted = false;
fSupported = GrGLGetVersion(glctx->gl()) > GR_GL_VER(3,3) ||
glctx->hasExtension("GL_ARB_timer_query") ||
glctx->hasExtension("GL_EXT_timer_query");
GpuTimer::GpuTimer(const SkGLContextHelper* glctx) : fContext(glctx) {
if (fContext) {
fContext->ref();
fContext->makeCurrent();
fStarted = false;
fSupported = GrGLGetVersion(fContext->gl()) > GR_GL_VER(3,3) ||
fContext->hasExtension("GL_ARB_timer_query") ||
fContext->hasExtension("GL_EXT_timer_query");
if (fSupported) {
SK_GL(*glctx, GenQueries(1, &fQuery));
if (fSupported) {
SK_GL(*fContext, GenQueries(1, &fQuery));
}
}
}
BenchGpuTimer::~BenchGpuTimer() {
if (fSupported) {
fContext->makeCurrent();
SK_GL(*fContext, DeleteQueries(1, &fQuery));
GpuTimer::~GpuTimer() {
if (fContext) {
if (fSupported) {
fContext->makeCurrent();
SK_GL(*fContext, DeleteQueries(1, &fQuery));
}
fContext->unref();
}
fContext->unref();
}
void BenchGpuTimer::startGpu() {
if (fSupported) {
void GpuTimer::start() {
if (fContext && fSupported) {
fContext->makeCurrent();
fStarted = true;
SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery));
......@@ -43,8 +46,8 @@ void BenchGpuTimer::startGpu() {
* It is important to stop the cpu clocks first,
* as this will cpu wait for the gpu to finish.
*/
double BenchGpuTimer::endGpu() {
if (fSupported) {
double GpuTimer::end() {
if (fContext && fSupported) {
fStarted = false;
fContext->makeCurrent();
SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED));
......@@ -52,8 +55,8 @@ double BenchGpuTimer::endGpu() {
GrGLint available = 0;
while (!available) {
SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery,
GR_GL_QUERY_RESULT_AVAILABLE,
&available));
GR_GL_QUERY_RESULT_AVAILABLE,
&available));
// If GetQueryObjectiv is erroring out we need some alternative
// means of breaking out of this loop
GrGLenum error;
......
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBenchGpuTimer_DEFINED
#define SkBenchGpuTimer_DEFINED
#ifndef GpuTimer_DEFINED
#define GpuTimer_DEFINED
class SkGLContextHelper;
class BenchGpuTimer {
class GpuTimer {
public:
BenchGpuTimer(const SkGLContextHelper* glctx);
~BenchGpuTimer();
void startGpu();
double endGpu();
GpuTimer(const SkGLContextHelper*);
~GpuTimer();
void start();
double end();
private:
unsigned fQuery;
int fStarted;
......
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "BenchSysTimer_mach.h"
//Time
#include <mach/mach.h>
#include <mach/mach_time.h>
#include "SysTimer_mach.h"
static time_value_t macCpuTime() {
static time_value_t mac_cpu_time() {
mach_port_t task = mach_task_self();
if (task == MACH_PORT_NULL) {
time_value_t none = {0, 0};
......@@ -21,10 +16,9 @@ static time_value_t macCpuTime() {
task_thread_times_info thread_info_data;
mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
if (KERN_SUCCESS != task_info(task,
TASK_THREAD_TIMES_INFO,
reinterpret_cast<task_info_t>(&thread_info_data),
&thread_info_count))
{
TASK_THREAD_TIMES_INFO,
reinterpret_cast<task_info_t>(&thread_info_data),
&thread_info_count)) {
time_value_t none = {0, 0};
return none;
}
......@@ -33,44 +27,40 @@ static time_value_t macCpuTime() {
return thread_info_data.user_time;
}
static double intervalInMSec(const time_value_t start_clock
, const time_value_t end_clock)
{
static double interval_in_ms(time_value_t start_clock, time_value_t end_clock) {
double duration_clock;
if ((end_clock.microseconds - start_clock.microseconds) < 0) {
duration_clock = (end_clock.seconds - start_clock.seconds-1)*1000;
duration_clock += (1000000
+ end_clock.microseconds
- start_clock.microseconds) / 1000.0;
duration_clock = (end_clock.seconds - start_clock.seconds-1) * 1000;
duration_clock += (1000000 + end_clock.microseconds - start_clock.microseconds) / 1000.0;
} else {
duration_clock = (end_clock.seconds - start_clock.seconds)*1000;
duration_clock += (end_clock.microseconds - start_clock.microseconds)
/ 1000.0;
duration_clock = (end_clock.seconds - start_clock.seconds) * 1000;
duration_clock += (end_clock.microseconds - start_clock.microseconds) / 1000.0;
}
return duration_clock;
}
void BenchSysTimer::startWall() {
this->fStartWall = mach_absolute_time();
void SysTimer::startWall() {
fStartWall = mach_absolute_time();
}
void BenchSysTimer::startCpu() {
this->fStartCpu = macCpuTime();
void SysTimer::startCpu() {
fStartCpu = mac_cpu_time();
}
double BenchSysTimer::endCpu() {
time_value_t end_cpu = macCpuTime();
return intervalInMSec(this->fStartCpu, end_cpu);
double SysTimer::endCpu() {
time_value_t end_cpu = mac_cpu_time();
return interval_in_ms(fStartCpu, end_cpu);
}
double BenchSysTimer::endWall() {
double SysTimer::endWall() {
uint64_t end_wall = mach_absolute_time();
uint64_t elapsed = end_wall - this->fStartWall;
uint64_t elapsed = end_wall - fStartWall;
mach_timebase_info_data_t sTimebaseInfo;
if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) {
return 0;
} else {
uint64_t elapsedNano = elapsed * sTimebaseInfo.numer
/ sTimebaseInfo.denom;
uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom;
return elapsedNano / 1000000.0;
}
}
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBenchSysTimer_DEFINED
#define SkBenchSysTimer_DEFINED
#ifndef SysTimer_DEFINED
#define SysTimer_DEFINED
//Time
#include <mach/mach.h>
#include <mach/mach_time.h>
class BenchSysTimer {
class SysTimer {
public:
void startWall();
void startCpu();
......
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "BenchSysTimer_posix.h"
//Time
#include <time.h>
#include "SysTimer_posix.h"
static double intervalInMSec(const timespec start_clock
, const timespec end_clock)
static double interval_in_ms(timespec start_clock, timespec end_clock)
{
double duration_clock;
if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) {
duration_clock = (end_clock.tv_sec - start_clock.tv_sec-1)*1000;
duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec)
/ 1000000.0;
duration_clock = (end_clock.tv_sec - start_clock.tv_sec - 1) * 1000;
duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
} else {
duration_clock = (end_clock.tv_sec - start_clock.tv_sec)*1000;
duration_clock = (end_clock.tv_sec - start_clock.tv_sec) * 1000;
duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
}
return duration_clock;
}
void BenchSysTimer::startWall() {
if (-1 == clock_gettime(CLOCK_MONOTONIC, &this->fWall)) {
void SysTimer::startWall() {
if (-1 == clock_gettime(CLOCK_MONOTONIC, &fWall)) {
timespec none = {0, 0};
this->fWall = none;
fWall = none;
}
}
void BenchSysTimer::startCpu() {
if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &this->fCpu)) {
void SysTimer::startCpu() {
if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &fCpu)) {
timespec none = {0, 0};
this->fCpu = none;
fCpu = none;
}
}
double BenchSysTimer::endCpu() {
double SysTimer::endCpu() {
timespec end_cpu;
if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) {
timespec none = {0, 0};
end_cpu = none;
}
return intervalInMSec(this->fCpu, end_cpu);
return interval_in_ms(fCpu, end_cpu);
}
double BenchSysTimer::endWall() {
double SysTimer::endWall() {
timespec end_wall;
if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) {
timespec none = {0, 0};
end_wall = none;
}
return intervalInMSec(this->fWall, end_wall);
return interval_in_ms(fWall, end_wall);
}
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBenchSysTimer_DEFINED
#define SkBenchSysTimer_DEFINED
#ifndef SysTimer_DEFINED
#define SysTimer_DEFINED
//Time
#include <time.h>
class BenchSysTimer {
class SysTimer {
public:
void startWall();
void startCpu();
......
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "BenchSysTimer_windows.h"
//Time
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include "SysTimer_windows.h"
static ULONGLONG winCpuTime() {
static ULONGLONG win_cpu_time() {
FILETIME createTime;
FILETIME exitTime;
FILETIME usrTime;
FILETIME sysTime;
if (0 == GetProcessTimes(GetCurrentProcess()
, &createTime, &exitTime
, &sysTime, &usrTime))
{
if (0 == GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTime, &usrTime)) {
return 0;
}
ULARGE_INTEGER start_cpu_sys;
......@@ -31,27 +23,27 @@ static ULONGLONG winCpuTime() {
return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart;
}
void BenchSysTimer::startWall() {
if (0 == ::QueryPerformanceCounter(&this->fStartWall)) {
this->fStartWall.QuadPart = 0;
void SysTimer::startWall() {
if (0 == ::QueryPerformanceCounter(&fStartWall)) {
fStartWall.QuadPart = 0;
}
}
void BenchSysTimer::startCpu() {
this->fStartCpu = winCpuTime();
void SysTimer::startCpu() {
fStartCpu = win_cpu_time();
}
double BenchSysTimer::endCpu() {
ULONGLONG end_cpu = winCpuTime();
return static_cast<double>((end_cpu - this->fStartCpu)) / 10000.0L;
double SysTimer::endCpu() {
ULONGLONG end_cpu = win_cpu_time();
return static_cast<double>(end_cpu - fStartCpu) / 10000.0L;
}
double BenchSysTimer::endWall() {
double SysTimer::endWall() {
LARGE_INTEGER end_wall;
if (0 == ::QueryPerformanceCounter(&end_wall)) {
end_wall.QuadPart = 0;
}
LARGE_INTEGER ticks_elapsed;
ticks_elapsed.QuadPart = end_wall.QuadPart - this->fStartWall.QuadPart;
ticks_elapsed.QuadPart = end_wall.QuadPart - fStartWall.QuadPart;
LARGE_INTEGER frequency;
if (0 == ::QueryPerformanceFrequency(&frequency)) {
......
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBenchSysTimer_DEFINED
#define SkBenchSysTimer_DEFINED
#ifndef SysTimer_DEFINED
#define SysTimer_DEFINED
//Time
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
class BenchSysTimer {
class SysTimer {
public:
void startWall();
void startCpu();
......
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Timer.h"
Timer::Timer(SkGLContextHelper* gl)
: fCpu(-1.0)
, fWall(-1.0)
, fTruncatedCpu(-1.0)
, fTruncatedWall(-1.0)
, fGpu(-1.0)
#if SK_SUPPORT_GPU
, fGpuTimer(gl)
#endif
{}
void Timer::start() {
fSysTimer.startWall();
fTruncatedSysTimer.startWall();
#if SK_SUPPORT_GPU
fGpuTimer.start();
#endif
fSysTimer.startCpu();
fTruncatedSysTimer.startCpu();
}
void Timer::end() {
fCpu = fSysTimer.endCpu();
#if SK_SUPPORT_GPU
//It is important to stop the cpu clocks first,
//as the following will cpu wait for the gpu to finish.
fGpu = fGpuTimer.end();
#endif
fWall = fSysTimer.endWall();
}
void Timer::truncatedEnd() {
fTruncatedCpu = fTruncatedSysTimer.endCpu();
fTruncatedWall = fTruncatedSysTimer.endWall();
}
WallTimer::WallTimer() : fWall(-1.0) {}
void WallTimer::start() {
fSysTimer.startWall();
}
void WallTimer::end() {
fWall = fSysTimer.endWall();
}
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBenchTimer_DEFINED
#define SkBenchTimer_DEFINED
#ifndef Timer_DEFINED
#define Timer_DEFINED
#include <SkTypes.h>
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SysTimer_windows.h"
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#include "SysTimer_mach.h"
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
#include "SysTimer_posix.h"
#endif
class BenchSysTimer;
class BenchGpuTimer;
#if SK_SUPPORT_GPU
#include "GpuTimer.h"
#endif
class SkGLContextHelper;
......@@ -25,13 +32,15 @@ class SkGLContextHelper;
* times and (for GPU configurations) can be used to roughly (very
* roughly) gauge the GPU load/backlog.
*/
class BenchTimer {
class Timer {
public:
BenchTimer(SkGLContextHelper* gl = NULL);
~BenchTimer();
void start(double durationScale = 1);
void end();
explicit Timer(SkGLContextHelper* gl = NULL);
void start();
void truncatedEnd();
void end();
// All times in milliseconds.
double fCpu;
double fWall;
double fTruncatedCpu;
......@@ -39,29 +48,26 @@ public:
double fGpu;
private:
BenchSysTimer* fSysTimer;
BenchSysTimer* fTruncatedSysTimer;
SysTimer fSysTimer;
SysTimer fTruncatedSysTimer;
#if SK_SUPPORT_GPU
BenchGpuTimer* fGpuTimer;
GpuTimer fGpuTimer;
#endif
double fDurationScale; // for this start/end session
};
// Same as BenchTimer above, supporting only fWall but with much lower overhead.
// (Typically, ~30ns instead of BenchTimer's ~1us.)
// Same as Timer above, supporting only fWall but with much lower overhead.
// (Typically, ~30ns instead of Timer's ~1us.)
class WallTimer {
public:
WallTimer();
~WallTimer();
void start(double durationScale = 1);
void start();
void end();
double fWall;
double fWall; // Milliseconds.
private:
BenchSysTimer* fSysTimer;
double fDurationScale;
SysTimer fSysTimer;
};
#endif
/*
* Copyright 2012 Google Inc.
*
......@@ -7,22 +6,19 @@
*/
#include "TimerData.h"
#include "BenchTimer.h"
#include "Timer.h"
#include <limits>
using namespace std;
TimerData::TimerData(int maxNumTimings)
: fMaxNumTimings(maxNumTimings)
, fCurrTiming(0)
, fWallTimes(maxNumTimings)
, fTruncatedWallTimes(maxNumTimings)
, fCpuTimes(maxNumTimings)
, fTruncatedCpuTimes(maxNumTimings)
, fGpuTimes(maxNumTimings){
}
bool TimerData::appendTimes(BenchTimer* timer) {
: fMaxNumTimings(maxNumTimings)
, fCurrTiming(0)
, fWallTimes(maxNumTimings)
, fTruncatedWallTimes(maxNumTimings)
, fCpuTimes(maxNumTimings)
, fTruncatedCpuTimes(maxNumTimings)
, fGpuTimes(maxNumTimings) {}
bool TimerData::appendTimes(Timer* timer) {
SkASSERT(timer != NULL);
if (fCurrTiming >= fMaxNumTimings) {
return false;
......
/*
* Copyright 2012 Google Inc.
*
......@@ -23,7 +22,7 @@
#pragma warning(pop)
#endif
class BenchTimer;
class Timer;
class TimerData {
public:
......@@ -33,12 +32,12 @@ public:
explicit TimerData(int maxNumTimings);
/**
* Collect times from the BenchTimer for an iteration. It will fail if called more often than
* Collect times from the Timer for an iteration. It will fail if called more often than
* indicated in the constructor.
*
* @param BenchTimer Must not be null.
* @param Timer Must not be null.
*/
bool appendTimes(BenchTimer*);
bool appendTimes(Timer*);
enum Result {
kMin_Result,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment