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" 13 #include "SkTemplates.h" 14 15 16 class BenchTimer; 17 18 class TimerData { 19 public: 20 /** 21 * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values. 22 **/ 23 explicit TimerData(int maxNumTimings); 24 25 /** 26 * Collect times from the BenchTimer for an iteration. It will fail if called more often than 27 * indicated in the constructor. 28 * 29 * @param BenchTimer Must not be null. 30 */ 31 bool appendTimes(BenchTimer*); 32 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; 71 }; 72 73 #endif // TimerData_DEFINED 74