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