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