epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 8 | #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.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 13 | #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 14 | #include "BenchSysTimer_posix.h" |
| 15 | #else |
| 16 | #include "BenchSysTimer_c.h" |
| 17 | #endif |
| 18 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 19 | #include "BenchGpuTimer_gl.h" |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 20 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 21 | BenchTimer::BenchTimer(SkGLContext* gl) |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 22 | : fCpu(-1.0) |
| 23 | , fWall(-1.0) |
| 24 | , fGpu(-1.0) |
| 25 | { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 26 | fSysTimer = new BenchSysTimer(); |
| 27 | if (gl) { |
| 28 | fGpuTimer = new BenchGpuTimer(gl); |
| 29 | } else { |
| 30 | fGpuTimer = NULL; |
| 31 | } |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | BenchTimer::~BenchTimer() { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 35 | delete fSysTimer; |
| 36 | delete fGpuTimer; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void BenchTimer::start() { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 40 | fSysTimer->startWall(); |
| 41 | if (fGpuTimer) { |
| 42 | fGpuTimer->startGpu(); |
| 43 | } |
| 44 | fSysTimer->startCpu(); |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void BenchTimer::end() { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 48 | fCpu = fSysTimer->endCpu(); |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 49 | //It is important to stop the cpu clocks first, |
| 50 | //as the following will cpu wait for the gpu to finish. |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 51 | if (fGpuTimer) { |
| 52 | fGpu = fGpuTimer->endGpu(); |
| 53 | } |
| 54 | fWall = fSysTimer->endWall(); |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 55 | } |