blob: 2297a560720cbbfed639b514e99ae96995dfa961 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
bungeman@google.combe9ad4e2011-06-07 19:16:02 +00008#include "BenchTimer.h"
9#if defined(SK_BUILD_FOR_WIN32)
10 #include "BenchSysTimer_windows.h"
11#elif defined(SK_BUILD_FOR_MAC)
12 #include "BenchSysTimer_mach.h"
13#elif defined(SK_BUILD_FOR_UNIX)
14 #include "BenchSysTimer_posix.h"
15#else
16 #include "BenchSysTimer_c.h"
17#endif
18
19#if defined(SK_MESA) || \
20 defined(SK_BUILD_FOR_WIN32) || \
21 defined(SK_BUILD_FOR_MAC) || \
22 defined(SK_BUILD_FOR_UNIX)
23 #include "BenchGpuTimer_gl.h"
24
25#else
26 #include "BenchGpuTimer_none.h"
27#endif
28
29BenchTimer::BenchTimer()
30 : fCpu(-1.0)
31 , fWall(-1.0)
32 , fGpu(-1.0)
33{
34 this->fSysTimer = new BenchSysTimer();
35 this->fGpuTimer = new BenchGpuTimer();
36}
37
38BenchTimer::~BenchTimer() {
39 delete this->fSysTimer;
40 delete this->fGpuTimer;
41}
42
43void BenchTimer::start() {
44 this->fSysTimer->startWall();
45 this->fGpuTimer->startGpu();
46 this->fSysTimer->startCpu();
47}
48
49void BenchTimer::end() {
50 this->fCpu = this->fSysTimer->endCpu();
51 //It is important to stop the cpu clocks first,
52 //as the following will cpu wait for the gpu to finish.
53 this->fGpu = this->fGpuTimer->endGpu();
54 this->fWall = this->fSysTimer->endWall();
55}