Home | History | Annotate | Download | only in timer
      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"
     12 #include "SkTemplates.h"
     13 
     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
     24 
     25 class Timer;
     26 
     27 class TimerData {
     28 public:
     29     /**
     30      * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
     31      **/
     32     explicit TimerData(int maxNumTimings);
     33 
     34     /**
     35      * Collect times from the Timer for an iteration. It will fail if called more often than
     36      * indicated in the constructor.
     37      *
     38      * @param Timer Must not be null.
     39      */
     40     bool appendTimes(Timer*);
     41 
     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);
     70     Json::Value getJSON(uint32_t timerFlags,
     71                         Result result,
     72                         int itersPerTiming = 1);
     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;
     83 };
     84 
     85 #endif // TimerData_DEFINED
     86