OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 * | 6 * |
7 * Classes for writing out bench results in various formats. | 7 * Classes for writing out bench results in various formats. |
8 */ | 8 */ |
9 | 9 |
10 #ifndef SkResultsWriter_DEFINED | 10 #ifndef SkResultsWriter_DEFINED |
11 #define SkResultsWriter_DEFINED | 11 #define SkResultsWriter_DEFINED |
12 | 12 |
13 #include "BenchLogger.h" | 13 #include "BenchLogger.h" |
14 #include "SkJSONCPP.h" | 14 #include "SkJSONCPP.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 #include "SkString.h" | 16 #include "SkString.h" |
17 #include "SkTArray.h" | 17 #include "SkTArray.h" |
18 #include "SkTypes.h" | 18 #include "SkTypes.h" |
19 | 19 |
20 /** | 20 /** |
21 * Base class for writing out the bench results. | 21 * Base class for writing out the bench results. |
22 * | 22 * |
23 * TODO(jcgregorio) Add info if tests fail to converge? | 23 * TODO(jcgregorio) Add info if tests fail to converge? |
24 */ | 24 */ |
25 class ResultsWriter : SkNoncopyable { | 25 class ResultsWriter : SkNoncopyable { |
26 public: | 26 public: |
27 virtual ~ResultsWriter() {}; | 27 virtual ~ResultsWriter() {}; |
28 | 28 |
| 29 // Records one key value pair that makes up a unique identifier for this run
. |
| 30 // All keys must be set before calling bench(). |
| 31 virtual void key(const char name[], const char value[]) = 0; |
| 32 |
29 // Records one option set for this run. All options must be set before | 33 // Records one option set for this run. All options must be set before |
30 // calling bench(). | 34 // calling bench(). |
31 virtual void option(const char name[], const char value[]) = 0; | 35 virtual void option(const char name[], const char value[]) = 0; |
32 | 36 |
33 // Denotes the start of a specific benchmark. Once bench is called, | 37 // Denotes the start of a specific benchmark. Once bench is called, |
34 // then config and timer can be called multiple times to record runs. | 38 // then config and timer can be called multiple times to record runs. |
35 virtual void bench(const char name[], int32_t x, int32_t y) = 0; | 39 virtual void bench(const char name[], int32_t x, int32_t y) = 0; |
36 | 40 |
37 // Records the specific configuration a bench is run under, such as "8888". | 41 // Records the specific configuration a bench is run under, such as "8888". |
38 virtual void config(const char name[]) = 0; | 42 virtual void config(const char name[]) = 0; |
39 | 43 |
40 // Records a single test metric. | 44 // Records a single test metric. |
41 virtual void timer(const char name[], double ms) = 0; | 45 virtual void timer(const char name[], double ms) = 0; |
42 | 46 |
43 // Call when all results are finished. | 47 // Call when all results are finished. |
44 virtual void end() = 0; | 48 virtual void end() = 0; |
45 }; | 49 }; |
46 | 50 |
47 /** | 51 /** |
48 * This ResultsWriter handles writing out the human readable format of the | 52 * This ResultsWriter handles writing out the human readable format of the |
49 * bench results. | 53 * bench results. |
50 */ | 54 */ |
51 class LoggerResultsWriter : public ResultsWriter { | 55 class LoggerResultsWriter : public ResultsWriter { |
52 public: | 56 public: |
53 explicit LoggerResultsWriter(BenchLogger& logger, const char* timeFormat) | 57 explicit LoggerResultsWriter(BenchLogger& logger, const char* timeFormat) |
54 : fLogger(logger) | 58 : fLogger(logger) |
55 , fTimeFormat(timeFormat) { | 59 , fTimeFormat(timeFormat) { |
56 fLogger.logProgress("skia bench:"); | 60 fLogger.logProgress("skia bench:"); |
57 } | 61 } |
| 62 virtual void key(const char name[], const char value[]) { |
| 63 // Don't log keys to keep microbench output unchanged. |
| 64 } |
58 virtual void option(const char name[], const char value[]) { | 65 virtual void option(const char name[], const char value[]) { |
59 fLogger.logProgress(SkStringPrintf(" %s=%s", name, value)); | 66 fLogger.logProgress(SkStringPrintf(" %s=%s", name, value)); |
60 } | 67 } |
61 virtual void bench(const char name[], int32_t x, int32_t y) { | 68 virtual void bench(const char name[], int32_t x, int32_t y) { |
62 fLogger.logProgress(SkStringPrintf( | 69 fLogger.logProgress(SkStringPrintf( |
63 "\nrunning bench [%3d %3d] %40s", x, y, name)); | 70 "\nrunning bench [%3d %3d] %40s", x, y, name)); |
64 } | 71 } |
65 virtual void config(const char name[]) { | 72 virtual void config(const char name[]) { |
66 fLogger.logProgress(SkStringPrintf(" %s:", name)); | 73 fLogger.logProgress(SkStringPrintf(" %s:", name)); |
67 } | 74 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 113 |
107 class JSONResultsWriter : public ResultsWriter { | 114 class JSONResultsWriter : public ResultsWriter { |
108 public: | 115 public: |
109 explicit JSONResultsWriter(const char filename[]) | 116 explicit JSONResultsWriter(const char filename[]) |
110 : fFilename(filename) | 117 : fFilename(filename) |
111 , fRoot() | 118 , fRoot() |
112 , fResults(fRoot["results"]) | 119 , fResults(fRoot["results"]) |
113 , fBench(NULL) | 120 , fBench(NULL) |
114 , fConfig(NULL) { | 121 , fConfig(NULL) { |
115 } | 122 } |
| 123 virtual void key(const char name[], const char value[]) { |
| 124 } |
116 virtual void option(const char name[], const char value[]) { | 125 virtual void option(const char name[], const char value[]) { |
117 fRoot["options"][name] = value; | 126 fRoot["options"][name] = value; |
118 } | 127 } |
119 virtual void bench(const char name[], int32_t x, int32_t y) { | 128 virtual void bench(const char name[], int32_t x, int32_t y) { |
120 SkString sk_name(name); | 129 SkString sk_name(name); |
121 sk_name.append("_"); | 130 sk_name.append("_"); |
122 sk_name.appendS32(x); | 131 sk_name.appendS32(x); |
123 sk_name.append("_"); | 132 sk_name.append("_"); |
124 sk_name.appendS32(y); | 133 sk_name.appendS32(y); |
125 Json::Value* bench_node = SkFindNamedNode(&fResults, sk_name.c_str()); | 134 Json::Value* bench_node = SkFindNamedNode(&fResults, sk_name.c_str()); |
(...skipping 15 matching lines...) Expand all Loading... |
141 private: | 150 private: |
142 | 151 |
143 SkString fFilename; | 152 SkString fFilename; |
144 Json::Value fRoot; | 153 Json::Value fRoot; |
145 Json::Value& fResults; | 154 Json::Value& fResults; |
146 Json::Value* fBench; | 155 Json::Value* fBench; |
147 Json::Value* fConfig; | 156 Json::Value* fConfig; |
148 }; | 157 }; |
149 | 158 |
150 /** | 159 /** |
| 160 NanoJSONResultsWriter writes the test results out in the following |
| 161 format: |
| 162 |
| 163 { |
| 164 "key": { |
| 165 "arch": "Arm7", |
| 166 "gpu": "SGX540", |
| 167 "os": "Android", |
| 168 "model": "GalaxyNexus", |
| 169 } |
| 170 "options": { |
| 171 "GL_Version": "3.1", |
| 172 ... |
| 173 }, |
| 174 "gitHash": "d1830323662ae8ae06908b97f15180fd25808894", |
| 175 "results" : { |
| 176 "Xfermode_Luminosity_640_480" : { |
| 177 "8888" : { |
| 178 "median_ms" : 143.188128906250, |
| 179 "min_ms" : 143.835957031250, |
| 180 ... |
| 181 }, |
| 182 ... |
| 183 */ |
| 184 class NanoJSONResultsWriter : public ResultsWriter { |
| 185 public: |
| 186 explicit NanoJSONResultsWriter(const char filename[], const char gitHash[]) |
| 187 : fFilename(filename) |
| 188 , fRoot() |
| 189 , fResults(fRoot["results"]) |
| 190 , fBench(NULL) |
| 191 , fConfig(NULL) { |
| 192 fRoot["gitHash"] = gitHash; |
| 193 } |
| 194 virtual void key(const char name[], const char value[]) { |
| 195 fRoot["key"][name] = value; |
| 196 } |
| 197 virtual void option(const char name[], const char value[]) { |
| 198 fRoot["options"][name] = value; |
| 199 } |
| 200 virtual void bench(const char name[], int32_t x, int32_t y) { |
| 201 SkString id = SkStringPrintf( "%s_%d_%d", name, x, y); |
| 202 fResults[id.c_str()] = Json::Value(Json::objectValue); |
| 203 fBench = &fResults[id.c_str()]; |
| 204 } |
| 205 virtual void config(const char name[]) { |
| 206 SkASSERT(NULL != fBench); |
| 207 fConfig = &(*fBench)[name]; |
| 208 } |
| 209 virtual void timer(const char name[], double ms) { |
| 210 // Don't record if nan, or -nan. |
| 211 if (sk_double_isnan(ms)) { |
| 212 return; |
| 213 } |
| 214 SkASSERT(NULL != fConfig); |
| 215 (*fConfig)[name] = ms; |
| 216 } |
| 217 virtual void end() { |
| 218 SkFILEWStream stream(fFilename.c_str()); |
| 219 stream.writeText(Json::FastWriter().write(fRoot).c_str()); |
| 220 stream.flush(); |
| 221 } |
| 222 private: |
| 223 |
| 224 SkString fFilename; |
| 225 Json::Value fRoot; |
| 226 Json::Value& fResults; |
| 227 Json::Value* fBench; |
| 228 Json::Value* fConfig; |
| 229 }; |
| 230 |
| 231 |
| 232 /** |
151 * This ResultsWriter writes out to multiple ResultsWriters. | 233 * This ResultsWriter writes out to multiple ResultsWriters. |
152 */ | 234 */ |
153 class MultiResultsWriter : public ResultsWriter { | 235 class MultiResultsWriter : public ResultsWriter { |
154 public: | 236 public: |
155 MultiResultsWriter() : writers() { | 237 MultiResultsWriter() : writers() { |
156 }; | 238 }; |
157 void add(ResultsWriter* writer) { | 239 void add(ResultsWriter* writer) { |
158 writers.push_back(writer); | 240 writers.push_back(writer); |
159 } | 241 } |
| 242 virtual void key(const char name[], const char value[]) { |
| 243 for (int i = 0; i < writers.count(); ++i) { |
| 244 writers[i]->key(name, value); |
| 245 } |
| 246 } |
160 virtual void option(const char name[], const char value[]) { | 247 virtual void option(const char name[], const char value[]) { |
161 for (int i = 0; i < writers.count(); ++i) { | 248 for (int i = 0; i < writers.count(); ++i) { |
162 writers[i]->option(name, value); | 249 writers[i]->option(name, value); |
163 } | 250 } |
164 } | 251 } |
165 virtual void bench(const char name[], int32_t x, int32_t y) { | 252 virtual void bench(const char name[], int32_t x, int32_t y) { |
166 for (int i = 0; i < writers.count(); ++i) { | 253 for (int i = 0; i < writers.count(); ++i) { |
167 writers[i]->bench(name, x, y); | 254 writers[i]->bench(name, x, y); |
168 } | 255 } |
169 } | 256 } |
(...skipping 21 matching lines...) Expand all Loading... |
191 */ | 278 */ |
192 template <typename T> class CallEnd : SkNoncopyable { | 279 template <typename T> class CallEnd : SkNoncopyable { |
193 public: | 280 public: |
194 CallEnd(T& obj) : fObj(obj) {} | 281 CallEnd(T& obj) : fObj(obj) {} |
195 ~CallEnd() { fObj.end(); } | 282 ~CallEnd() { fObj.end(); } |
196 private: | 283 private: |
197 T& fObj; | 284 T& fObj; |
198 }; | 285 }; |
199 | 286 |
200 #endif | 287 #endif |
OLD | NEW |