Home | History | Annotate | Download | only in bench
      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 #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
     25 
     26 class BenchTimer;
     27 
     28 class TimerData {
     29 public:
     30     /**
     31      * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
     32      **/
     33     explicit TimerData(int maxNumTimings);
     34 
     35     /**
     36      * Collect times from the BenchTimer for an iteration. It will fail if called more often than
     37      * indicated in the constructor.
     38      *
     39      * @param BenchTimer Must not be null.
     40      */
     41     bool appendTimes(BenchTimer*);
     42 
     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);
     71     Json::Value getJSON(uint32_t timerFlags,
     72                         Result result,
     73                         int itersPerTiming = 1);
     74 
     75 private:
     76     int fMaxNumTimings;
     77     int fCurrTiming;
     78 
     79     SkAutoTArray<double> fWallTimes;
     80     SkAutoTArray<double> fTruncatedWallTimes;
     81     SkAutoTArray<double> fCpuTimes;
     82     SkAutoTArray<double> fTruncatedCpuTimes;
     83     SkAutoTArray<double> fGpuTimes;
     84 };
     85 
     86 #endif // TimerData_DEFINED
     87