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