| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 #ifndef SkBenchTimer_DEFINED | 7 #ifndef Timer_DEFINED |
| 9 #define SkBenchTimer_DEFINED | 8 #define Timer_DEFINED |
| 10 | 9 |
| 11 #include <SkTypes.h> | 10 #include "SkTypes.h" |
| 12 | 11 |
| 12 #if defined(SK_BUILD_FOR_WIN32) |
| 13 #include "SysTimer_windows.h" |
| 14 #elif defined(SK_BUILD_FOR_MAC) |
| 15 #include "SysTimer_mach.h" |
| 16 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) |
| 17 #include "SysTimer_posix.h" |
| 18 #endif |
| 13 | 19 |
| 14 class BenchSysTimer; | 20 #if SK_SUPPORT_GPU |
| 15 class BenchGpuTimer; | 21 #include "GpuTimer.h" |
| 22 #endif |
| 16 | 23 |
| 17 class SkGLContextHelper; | 24 class SkGLContextHelper; |
| 18 | 25 |
| 19 /** | 26 /** |
| 20 * SysTimers and GpuTimers are implemented orthogonally. | 27 * SysTimers and GpuTimers are implemented orthogonally. |
| 21 * This class combines 2 SysTimers and a GpuTimer into one single, | 28 * This class combines 2 SysTimers and a GpuTimer into one single, |
| 22 * platform specific Timer with a simple interface. The truncated | 29 * platform specific Timer with a simple interface. The truncated |
| 23 * timer doesn't include the time required for the GPU to finish | 30 * timer doesn't include the time required for the GPU to finish |
| 24 * its rendering. It should always be <= the un-truncated system | 31 * its rendering. It should always be <= the un-truncated system |
| 25 * times and (for GPU configurations) can be used to roughly (very | 32 * times and (for GPU configurations) can be used to roughly (very |
| 26 * roughly) gauge the GPU load/backlog. | 33 * roughly) gauge the GPU load/backlog. |
| 27 */ | 34 */ |
| 28 class BenchTimer { | 35 class Timer { |
| 29 public: | 36 public: |
| 30 BenchTimer(SkGLContextHelper* gl = NULL); | 37 explicit Timer(SkGLContextHelper* gl = NULL); |
| 31 ~BenchTimer(); | 38 |
| 32 void start(double durationScale = 1); | 39 void start(); |
| 40 void truncatedEnd(); |
| 33 void end(); | 41 void end(); |
| 34 void truncatedEnd(); | 42 |
| 43 // All times in milliseconds. |
| 35 double fCpu; | 44 double fCpu; |
| 36 double fWall; | 45 double fWall; |
| 37 double fTruncatedCpu; | 46 double fTruncatedCpu; |
| 38 double fTruncatedWall; | 47 double fTruncatedWall; |
| 39 double fGpu; | 48 double fGpu; |
| 40 | 49 |
| 41 private: | 50 private: |
| 42 BenchSysTimer* fSysTimer; | 51 SysTimer fSysTimer; |
| 43 BenchSysTimer* fTruncatedSysTimer; | 52 SysTimer fTruncatedSysTimer; |
| 44 #if SK_SUPPORT_GPU | 53 #if SK_SUPPORT_GPU |
| 45 BenchGpuTimer* fGpuTimer; | 54 GpuTimer fGpuTimer; |
| 46 #endif | 55 #endif |
| 47 double fDurationScale; // for this start/end session | |
| 48 }; | 56 }; |
| 49 | 57 |
| 50 // Same as BenchTimer above, supporting only fWall but with much lower overhead. | 58 // Same as Timer above, supporting only fWall but with much lower overhead. |
| 51 // (Typically, ~30ns instead of BenchTimer's ~1us.) | 59 // (Typically, ~30ns instead of Timer's ~1us.) |
| 52 class WallTimer { | 60 class WallTimer { |
| 53 public: | 61 public: |
| 54 WallTimer(); | 62 WallTimer(); |
| 55 ~WallTimer(); | |
| 56 | 63 |
| 57 void start(double durationScale = 1); | 64 void start(); |
| 58 void end(); | 65 void end(); |
| 59 | 66 |
| 60 double fWall; | 67 double fWall; // Milliseconds. |
| 61 | 68 |
| 62 private: | 69 private: |
| 63 BenchSysTimer* fSysTimer; | 70 SysTimer fSysTimer; |
| 64 double fDurationScale; | |
| 65 }; | 71 }; |
| 66 | 72 |
| 67 #endif | 73 #endif |
| OLD | NEW |