OLD | NEW |
(Empty) | |
| 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 */ |
| 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" |
| 13 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) |
| 14 #include "BenchSysTimer_posix.h" |
| 15 #else |
| 16 #include "BenchSysTimer_c.h" |
| 17 #endif |
| 18 |
| 19 #if SK_SUPPORT_GPU |
| 20 #include "BenchGpuTimer_gl.h" |
| 21 #endif |
| 22 |
| 23 BenchTimer::BenchTimer(SkGLContextHelper* gl) |
| 24 : fCpu(-1.0) |
| 25 , fWall(-1.0) |
| 26 , fTruncatedCpu(-1.0) |
| 27 , fTruncatedWall(-1.0) |
| 28 , fGpu(-1.0) |
| 29 { |
| 30 fSysTimer = new BenchSysTimer(); |
| 31 fTruncatedSysTimer = new BenchSysTimer(); |
| 32 #if SK_SUPPORT_GPU |
| 33 if (gl) { |
| 34 fGpuTimer = new BenchGpuTimer(gl); |
| 35 } else { |
| 36 fGpuTimer = NULL; |
| 37 } |
| 38 #endif |
| 39 } |
| 40 |
| 41 BenchTimer::~BenchTimer() { |
| 42 delete fSysTimer; |
| 43 delete fTruncatedSysTimer; |
| 44 #if SK_SUPPORT_GPU |
| 45 delete fGpuTimer; |
| 46 #endif |
| 47 } |
| 48 |
| 49 void BenchTimer::start(double durationScale) { |
| 50 fDurationScale = durationScale; |
| 51 |
| 52 fSysTimer->startWall(); |
| 53 fTruncatedSysTimer->startWall(); |
| 54 #if SK_SUPPORT_GPU |
| 55 if (fGpuTimer) { |
| 56 fGpuTimer->startGpu(); |
| 57 } |
| 58 #endif |
| 59 fSysTimer->startCpu(); |
| 60 fTruncatedSysTimer->startCpu(); |
| 61 } |
| 62 |
| 63 void BenchTimer::end() { |
| 64 fCpu = fSysTimer->endCpu() * fDurationScale; |
| 65 #if SK_SUPPORT_GPU |
| 66 //It is important to stop the cpu clocks first, |
| 67 //as the following will cpu wait for the gpu to finish. |
| 68 if (fGpuTimer) { |
| 69 fGpu = fGpuTimer->endGpu() * fDurationScale; |
| 70 } |
| 71 #endif |
| 72 fWall = fSysTimer->endWall() * fDurationScale; |
| 73 } |
| 74 |
| 75 void BenchTimer::truncatedEnd() { |
| 76 fTruncatedCpu = fTruncatedSysTimer->endCpu() * fDurationScale; |
| 77 fTruncatedWall = fTruncatedSysTimer->endWall() * fDurationScale; |
| 78 } |
| 79 |
| 80 WallTimer::WallTimer() : fWall(-1.0), fSysTimer(new BenchSysTimer) {} |
| 81 |
| 82 WallTimer::~WallTimer() { |
| 83 delete fSysTimer; |
| 84 } |
| 85 |
| 86 void WallTimer::start(double durationScale) { |
| 87 fDurationScale = durationScale; |
| 88 fSysTimer->startWall(); |
| 89 } |
| 90 |
| 91 void WallTimer::end() { |
| 92 fWall = fSysTimer->endWall() * fDurationScale; |
| 93 } |
| 94 |
OLD | NEW |