scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 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 | |
| 9 | #ifndef TimerData_DEFINED |
| 10 | #define TimerData_DEFINED |
| 11 | |
| 12 | #include "SkString.h" |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 13 | #include "SkTemplates.h" |
| 14 | |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame^] | 15 | #ifdef SK_BUILD_FOR_WIN |
| 16 | #pragma warning(push) |
| 17 | #pragma warning(disable : 4530) |
| 18 | #endif |
| 19 | |
| 20 | #include "SkJSONCPP.h" |
| 21 | |
| 22 | #ifdef SK_BUILD_FOR_WIN |
| 23 | #pragma warning(pop) |
| 24 | #endif |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 25 | |
| 26 | class BenchTimer; |
| 27 | |
| 28 | class TimerData { |
| 29 | public: |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values. |
| 32 | **/ |
| 33 | explicit TimerData(int maxNumTimings); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 36 | * Collect times from the BenchTimer for an iteration. It will fail if called more often than |
| 37 | * indicated in the constructor. |
| 38 | * |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 39 | * @param BenchTimer Must not be null. |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 40 | */ |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 41 | bool appendTimes(BenchTimer*); |
commit-bot@chromium.org | 47fad70 | 2013-07-25 20:01:20 +0000 | [diff] [blame] | 42 | |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 43 | enum Result { |
| 44 | kMin_Result, |
| 45 | kAvg_Result, |
| 46 | kPerIter_Result |
| 47 | }; |
| 48 | |
| 49 | enum TimerFlags { |
| 50 | kWall_Flag = 0x1, |
| 51 | kTruncatedWall_Flag = 0x2, |
| 52 | kCpu_Flag = 0x4, |
| 53 | kTruncatedCpu_Flag = 0x8, |
| 54 | kGpu_Flag = 0x10 |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * Gets the timer data results as a string. |
| 59 | * @param doubleFormat printf-style format for doubles (e.g. "%02d") |
| 60 | * @param result the type of result desired |
| 61 | * @param the name of the config being timed (prepended to results string) |
| 62 | * @param timerFlags bitfield of TimerFlags values indicating which timers should be reported. |
| 63 | * @param itersPerTiming the number of test/bench iterations that correspond to each |
| 64 | * appendTimes() call, 1 when appendTimes is called for each iteration. |
| 65 | */ |
| 66 | SkString getResult(const char* doubleFormat, |
| 67 | Result result, |
| 68 | const char* configName, |
| 69 | uint32_t timerFlags, |
| 70 | int itersPerTiming = 1); |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame^] | 71 | #ifdef SK_BUILD_JSON_WRITER |
| 72 | Json::Value getJSON(uint32_t timerFlags, |
| 73 | Result result, |
| 74 | int itersPerTiming = 1); |
| 75 | #endif // SK_BUILD_JSON_WRITER |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | int fMaxNumTimings; |
| 79 | int fCurrTiming; |
| 80 | |
| 81 | SkAutoTArray<double> fWallTimes; |
| 82 | SkAutoTArray<double> fTruncatedWallTimes; |
| 83 | SkAutoTArray<double> fCpuTimes; |
| 84 | SkAutoTArray<double> fTruncatedCpuTimes; |
| 85 | SkAutoTArray<double> fGpuTimes; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | #endif // TimerData_DEFINED |