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 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 23 | BenchTimer::BenchTimer(SkGLContextHelper* 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 | |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 49 | void BenchTimer::start(double durationScale) { |
| 50 | fDurationScale = durationScale; |
| 51 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 52 | fSysTimer->startWall(); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 53 | fTruncatedSysTimer->startWall(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 54 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 55 | if (fGpuTimer) { |
| 56 | fGpuTimer->startGpu(); |
| 57 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 58 | #endif |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 59 | fSysTimer->startCpu(); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 60 | fTruncatedSysTimer->startCpu(); |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void BenchTimer::end() { |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 64 | fCpu = fSysTimer->endCpu() * fDurationScale; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 65 | #if SK_SUPPORT_GPU |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 66 | //It is important to stop the cpu clocks first, |
| 67 | //as the following will cpu wait for the gpu to finish. |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 68 | if (fGpuTimer) { |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 69 | fGpu = fGpuTimer->endGpu() * fDurationScale; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 70 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 71 | #endif |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 72 | fWall = fSysTimer->endWall() * fDurationScale; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 73 | } |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 74 | |
| 75 | void BenchTimer::truncatedEnd() { |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 76 | fTruncatedCpu = fTruncatedSysTimer->endCpu() * fDurationScale; |
| 77 | fTruncatedWall = fTruncatedSysTimer->endWall() * fDurationScale; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 78 | } |