blob: ed0ee473c18133e4f6a5372bccad48c0caa475f1 [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
scroggo@google.com9a412522012-09-07 15:21:18 +000015
16class BenchTimer;
17
18class TimerData {
19public:
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000020 /**
21 * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
22 **/
23 explicit TimerData(int maxNumTimings);
scroggo@google.com9a412522012-09-07 15:21:18 +000024
25 /**
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000026 * Collect times from the BenchTimer for an iteration. It will fail if called more often than
27 * indicated in the constructor.
28 *
scroggo@google.com9a412522012-09-07 15:21:18 +000029 * @param BenchTimer Must not be null.
scroggo@google.com9a412522012-09-07 15:21:18 +000030 */
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000031 bool appendTimes(BenchTimer*);
commit-bot@chromium.org47fad702013-07-25 20:01:20 +000032
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +000033 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
62private:
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;
scroggo@google.com9a412522012-09-07 15:21:18 +000071};
72
73#endif // TimerData_DEFINED