2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-06-07 19:16:02 +00:00
|
|
|
#include "BenchTimer.h"
|
|
|
|
#if defined(SK_BUILD_FOR_WIN32)
|
|
|
|
#include "BenchSysTimer_windows.h"
|
|
|
|
#elif defined(SK_BUILD_FOR_MAC)
|
|
|
|
#include "BenchSysTimer_mach.h"
|
2011-11-03 13:08:29 +00:00
|
|
|
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
|
2011-06-07 19:16:02 +00:00
|
|
|
#include "BenchSysTimer_posix.h"
|
|
|
|
#else
|
|
|
|
#include "BenchSysTimer_c.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-19 20:43:20 +00:00
|
|
|
#include "BenchGpuTimer_gl.h"
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-06-07 19:16:02 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
BenchTimer::BenchTimer(SkGLContext* gl)
|
2011-06-07 19:16:02 +00:00
|
|
|
: fCpu(-1.0)
|
|
|
|
, fWall(-1.0)
|
2012-08-28 12:18:40 +00:00
|
|
|
, fTruncatedCpu(-1.0)
|
|
|
|
, fTruncatedWall(-1.0)
|
2011-06-07 19:16:02 +00:00
|
|
|
, fGpu(-1.0)
|
|
|
|
{
|
2011-10-19 20:43:20 +00:00
|
|
|
fSysTimer = new BenchSysTimer();
|
2012-08-28 12:18:40 +00:00
|
|
|
fTruncatedSysTimer = new BenchSysTimer();
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-19 20:43:20 +00:00
|
|
|
if (gl) {
|
|
|
|
fGpuTimer = new BenchGpuTimer(gl);
|
|
|
|
} else {
|
|
|
|
fGpuTimer = NULL;
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BenchTimer::~BenchTimer() {
|
2011-10-19 20:43:20 +00:00
|
|
|
delete fSysTimer;
|
2012-08-28 12:18:40 +00:00
|
|
|
delete fTruncatedSysTimer;
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-19 20:43:20 +00:00
|
|
|
delete fGpuTimer;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BenchTimer::start() {
|
2011-10-19 20:43:20 +00:00
|
|
|
fSysTimer->startWall();
|
2012-08-28 12:18:40 +00:00
|
|
|
fTruncatedSysTimer->startWall();
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-19 20:43:20 +00:00
|
|
|
if (fGpuTimer) {
|
|
|
|
fGpuTimer->startGpu();
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-10-19 20:43:20 +00:00
|
|
|
fSysTimer->startCpu();
|
2012-08-28 12:18:40 +00:00
|
|
|
fTruncatedSysTimer->startCpu();
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BenchTimer::end() {
|
2011-10-19 20:43:20 +00:00
|
|
|
fCpu = fSysTimer->endCpu();
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-06-07 19:16:02 +00:00
|
|
|
//It is important to stop the cpu clocks first,
|
|
|
|
//as the following will cpu wait for the gpu to finish.
|
2011-10-19 20:43:20 +00:00
|
|
|
if (fGpuTimer) {
|
|
|
|
fGpu = fGpuTimer->endGpu();
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-10-19 20:43:20 +00:00
|
|
|
fWall = fSysTimer->endWall();
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
2012-08-28 12:18:40 +00:00
|
|
|
|
|
|
|
void BenchTimer::truncatedEnd() {
|
|
|
|
fTruncatedCpu = fTruncatedSysTimer->endCpu();
|
|
|
|
fTruncatedWall = fTruncatedSysTimer->endWall();
|
|
|
|
}
|