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