blob: 35e94dca1db90459cd76685fa869c8c5b87d3ffe [file] [log] [blame]
scroggo@google.com9a412522012-09-07 15:21:18 +00001/*
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.org55fd6122013-07-31 20:00:56 +000012#include "SkTemplates.h"
13
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000014#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.com9a412522012-09-07 15:21:18 +000024
mtklein9ac68ee2014-06-20 11:29:20 -070025class Timer;
scroggo@google.com9a412522012-09-07 15:21:18 +000026
27class TimerData {
28public:
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000029 /**
30 * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
31 **/
32 explicit TimerData(int maxNumTimings);
scroggo@google.com9a412522012-09-07 15:21:18 +000033
34 /**
mtklein9ac68ee2014-06-20 11:29:20 -070035 * Collect times from the Timer for an iteration. It will fail if called more often than
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000036 * indicated in the constructor.
37 *
mtklein9ac68ee2014-06-20 11:29:20 -070038 * @param Timer Must not be null.
scroggo@google.com9a412522012-09-07 15:21:18 +000039 */
mtklein9ac68ee2014-06-20 11:29:20 -070040 bool appendTimes(Timer*);
commit-bot@chromium.org47fad702013-07-25 20:01:20 +000041
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000042 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.com9681eeb2014-05-30 03:06:10 +000070 Json::Value getJSON(uint32_t timerFlags,
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000071 Result result,
72 int itersPerTiming = 1);
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000073
74private:
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.com9a412522012-09-07 15:21:18 +000083};
84
85#endif // TimerData_DEFINED