blob: c3a1190a8c379e4dd03e0bfa78f10304ede6dbfc [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"
djsollen@google.com58629292011-11-03 13:08:29 +000013#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000014 #include "BenchSysTimer_posix.h"
15#else
16 #include "BenchSysTimer_c.h"
17#endif
18
bsalomon@google.com373a6632011-10-19 20:43:20 +000019#include "BenchGpuTimer_gl.h"
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000020
bsalomon@google.com373a6632011-10-19 20:43:20 +000021BenchTimer::BenchTimer(SkGLContext* gl)
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000022 : fCpu(-1.0)
23 , fWall(-1.0)
24 , fGpu(-1.0)
25{
bsalomon@google.com373a6632011-10-19 20:43:20 +000026 fSysTimer = new BenchSysTimer();
27 if (gl) {
28 fGpuTimer = new BenchGpuTimer(gl);
29 } else {
30 fGpuTimer = NULL;
31 }
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000032}
33
34BenchTimer::~BenchTimer() {
bsalomon@google.com373a6632011-10-19 20:43:20 +000035 delete fSysTimer;
36 delete fGpuTimer;
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000037}
38
39void BenchTimer::start() {
bsalomon@google.com373a6632011-10-19 20:43:20 +000040 fSysTimer->startWall();
41 if (fGpuTimer) {
42 fGpuTimer->startGpu();
43 }
44 fSysTimer->startCpu();
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000045}
46
47void BenchTimer::end() {
bsalomon@google.com373a6632011-10-19 20:43:20 +000048 fCpu = fSysTimer->endCpu();
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000049 //It is important to stop the cpu clocks first,
50 //as the following will cpu wait for the gpu to finish.
bsalomon@google.com373a6632011-10-19 20:43:20 +000051 if (fGpuTimer) {
52 fGpu = fGpuTimer->endGpu();
53 }
54 fWall = fSysTimer->endWall();
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000055}