2011-07-28 18:26:00 +04: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 23:16:02 +04: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 17:08:29 +04:00
|
|
|
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
|
2011-06-07 23:16:02 +04:00
|
|
|
#include "BenchSysTimer_posix.h"
|
|
|
|
#else
|
|
|
|
#include "BenchSysTimer_c.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-02 18:03:32 +04:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-20 00:43:20 +04:00
|
|
|
#include "BenchGpuTimer_gl.h"
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|
2011-06-07 23:16:02 +04:00
|
|
|
|
2011-10-20 00:43:20 +04:00
|
|
|
BenchTimer::BenchTimer(SkGLContext* gl)
|
2011-06-07 23:16:02 +04:00
|
|
|
: fCpu(-1.0)
|
|
|
|
, fWall(-1.0)
|
2012-08-28 16:18:40 +04:00
|
|
|
, fTruncatedCpu(-1.0)
|
|
|
|
, fTruncatedWall(-1.0)
|
2011-06-07 23:16:02 +04:00
|
|
|
, fGpu(-1.0)
|
|
|
|
{
|
2011-10-20 00:43:20 +04:00
|
|
|
fSysTimer = new BenchSysTimer();
|
2012-08-28 16:18:40 +04:00
|
|
|
fTruncatedSysTimer = new BenchSysTimer();
|
2012-08-02 18:03:32 +04:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-20 00:43:20 +04:00
|
|
|
if (gl) {
|
|
|
|
fGpuTimer = new BenchGpuTimer(gl);
|
|
|
|
} else {
|
|
|
|
fGpuTimer = NULL;
|
|
|
|
}
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|
2011-06-07 23:16:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BenchTimer::~BenchTimer() {
|
2011-10-20 00:43:20 +04:00
|
|
|
delete fSysTimer;
|
2012-08-28 16:18:40 +04:00
|
|
|
delete fTruncatedSysTimer;
|
2012-08-02 18:03:32 +04:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-20 00:43:20 +04:00
|
|
|
delete fGpuTimer;
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|
2011-06-07 23:16:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BenchTimer::start() {
|
2011-10-20 00:43:20 +04:00
|
|
|
fSysTimer->startWall();
|
2012-08-28 16:18:40 +04:00
|
|
|
fTruncatedSysTimer->startWall();
|
2012-08-02 18:03:32 +04:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-20 00:43:20 +04:00
|
|
|
if (fGpuTimer) {
|
|
|
|
fGpuTimer->startGpu();
|
|
|
|
}
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|
2011-10-20 00:43:20 +04:00
|
|
|
fSysTimer->startCpu();
|
2012-08-28 16:18:40 +04:00
|
|
|
fTruncatedSysTimer->startCpu();
|
2011-06-07 23:16:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BenchTimer::end() {
|
2011-10-20 00:43:20 +04:00
|
|
|
fCpu = fSysTimer->endCpu();
|
2012-08-02 18:03:32 +04:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-06-07 23:16:02 +04:00
|
|
|
//It is important to stop the cpu clocks first,
|
|
|
|
//as the following will cpu wait for the gpu to finish.
|
2011-10-20 00:43:20 +04:00
|
|
|
if (fGpuTimer) {
|
|
|
|
fGpu = fGpuTimer->endGpu();
|
|
|
|
}
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|
2011-10-20 00:43:20 +04:00
|
|
|
fWall = fSysTimer->endWall();
|
2011-06-07 23:16:02 +04:00
|
|
|
}
|
2012-08-28 16:18:40 +04:00
|
|
|
|
|
|
|
void BenchTimer::truncatedEnd() {
|
|
|
|
fTruncatedCpu = fTruncatedSysTimer->endCpu();
|
|
|
|
fTruncatedWall = fTruncatedSysTimer->endWall();
|
|
|
|
}
|