blob: be6158bbd82f19a07f12a330735c1526c77f38fd [file] [log] [blame]
scroggo@google.com9a412522012-09-07 15:21:18 +00001
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.org55fd6122013-07-31 20:00:56 +000013#include "SkTemplates.h"
14
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000015#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
scroggo@google.com9a412522012-09-07 15:21:18 +000025
26class BenchTimer;
27
28class TimerData {
29public:
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000030 /**
31 * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
32 **/
33 explicit TimerData(int maxNumTimings);
scroggo@google.com9a412522012-09-07 15:21:18 +000034
35 /**
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000036 * Collect times from the BenchTimer for an iteration. It will fail if called more often than
37 * indicated in the constructor.
38 *
scroggo@google.com9a412522012-09-07 15:21:18 +000039 * @param BenchTimer Must not be null.
scroggo@google.com9a412522012-09-07 15:21:18 +000040 */
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000041 bool appendTimes(BenchTimer*);
commit-bot@chromium.org47fad702013-07-25 20:01:20 +000042
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000043 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);
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000071#ifdef SK_BUILD_JSON_WRITER
skia.committer@gmail.com9681eeb2014-05-30 03:06:10 +000072 Json::Value getJSON(uint32_t timerFlags,
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000073 Result result,
74 int itersPerTiming = 1);
75#endif // SK_BUILD_JSON_WRITER
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000076
77private:
78 int fMaxNumTimings;
79 int fCurrTiming;
80
81 SkAutoTArray<double> fWallTimes;
82 SkAutoTArray<double> fTruncatedWallTimes;
83 SkAutoTArray<double> fCpuTimes;
84 SkAutoTArray<double> fTruncatedCpuTimes;
85 SkAutoTArray<double> fGpuTimes;
scroggo@google.com9a412522012-09-07 15:21:18 +000086};
87
88#endif // TimerData_DEFINED