OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2014 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 * Classes for writing out bench results in various formats. | |
8 */ | |
9 #ifndef SkPictureResultsWriter_DEFINED | |
10 #define SkPictureResultsWriter_DEFINED | |
11 | |
12 #include "ResultsWriter.h" | |
13 #include "SkBenchLogger.h" | |
14 #include "SkJSONCPP.h" | |
15 #include "SkStream.h" | |
16 #include "SkString.h" | |
17 #include "SkTArray.h" | |
18 | |
19 /** | |
20 * Base class for writing picture bench results. | |
21 */ | |
22 class PictureResultsWriter : SkNoncopyable { | |
23 public: | |
24 enum TileFlags {kPurging, kAvg}; | |
25 | |
26 PictureResultsWriter() {;} | |
jcgregorio
2014/05/27 19:57:16
You don't need the ;
Fix here and below.
kelvinly
2014/05/27 20:27:31
Done.
| |
27 virtual ~PictureResultsWriter() {;} | |
28 | |
29 virtual void bench(const char name[], int32_t x, int32_t y) = 0; | |
30 virtual void tileConfig(SkString configName) = 0; | |
31 virtual void tileMeta(int x, int y, int tx, int ty) = 0; | |
32 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) = 0; | |
33 virtual void tileData( | |
34 TimerData* data, | |
35 const char format[], | |
36 const TimerData::Result result, | |
37 uint32_t timerTypes, | |
38 int numInnerLoops = 1) = 0; | |
39 virtual void end() = 0; | |
40 }; | |
41 | |
42 class PictureResultsMultiWriter : public PictureResultsWriter { | |
jcgregorio
2014/05/27 19:57:16
What's the ownership model, does PictureResultsMul
kelvinly
2014/05/27 20:27:31
Done.
| |
43 public: | |
44 PictureResultsMultiWriter() : writers() {;} | |
45 void add(PictureResultsWriter* newWriter) { | |
46 writers.push_back(newWriter); | |
47 } | |
48 virtual ~PictureResultsMultiWriter() {;} | |
49 virtual void bench(const char name[], int32_t x, int32_t y) { | |
50 for(int i=0; i<writers.count(); ++i) { | |
51 writers[i]->bench(name, x, y); | |
52 } | |
53 } | |
54 virtual void tileConfig(SkString configName) { | |
55 for(int i=0; i<writers.count(); ++i) { | |
56 writers[i]->tileConfig(configName); | |
57 } | |
58 } | |
59 virtual void tileMeta(int x, int y, int tx, int ty) { | |
60 for(int i=0; i<writers.count(); ++i) { | |
61 writers[i]->tileMeta(x, y, tx, ty); | |
62 } | |
63 } | |
64 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) { | |
65 for(int i=0; i<writers.count(); ++i) { | |
66 writers[i]->addTileFlag(flag); | |
67 } | |
68 } | |
69 virtual void tileData( | |
70 TimerData* data, | |
71 const char format[], | |
72 const TimerData::Result result, | |
73 uint32_t timerTypes, | |
74 int numInnerLoops = 1) { | |
75 for(int i=0; i<writers.count(); ++i) { | |
76 writers[i]->tileData(data, format, result, timerTypes, | |
77 numInnerLoops); | |
78 } | |
79 } | |
80 virtual void end() { | |
81 for(int i=0; i<writers.count(); ++i) { | |
82 writers[i]->end(); | |
83 } | |
84 } | |
85 private: | |
86 SkTArray<PictureResultsWriter*> writers; | |
87 }; | |
88 | |
89 /** | |
90 * Writes to SkBenchLogger to mimic original behavior | |
91 */ | |
92 class PictureResultsLoggerWriter : public PictureResultsWriter { | |
93 private: | |
94 void logProgress(const char str[]) { | |
95 if(fLogger != NULL) { | |
96 fLogger->logProgress(str); | |
97 } | |
98 } | |
99 public: | |
100 PictureResultsLoggerWriter(SkBenchLogger* log) | |
101 : fLogger(log), currentLine() {;} | |
102 virtual void bench(const char name[], int32_t x, int32_t y) { | |
103 SkString result; | |
104 result.printf("running bench [%i %i] %s ", x, y, name); | |
105 this->logProgress(result.c_str()); | |
106 } | |
107 virtual void tileConfig(SkString configName) { | |
108 currentLine = configName; | |
109 } | |
110 virtual void tileMeta(int x, int y, int tx, int ty) { | |
111 currentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty); | |
112 } | |
113 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) { | |
114 if(flag == PictureResultsWriter::kPurging) { | |
115 currentLine.append(" <withPurging>"); | |
116 } else if(flag == PictureResultsWriter::kAvg) { | |
117 currentLine.append(" <averaged>"); | |
118 } | |
119 } | |
120 virtual void tileData( | |
121 TimerData* data, | |
122 const char format[], | |
123 const TimerData::Result result, | |
124 uint32_t timerTypes, | |
125 int numInnerLoops = 1) { | |
126 SkString results = data->getResult(format, result, | |
127 currentLine.c_str(), timerTypes, numInnerLoops); | |
128 results.append("\n"); | |
129 this->logProgress(results.c_str()); | |
130 } | |
131 virtual void end() {;} | |
132 private: | |
133 SkBenchLogger* fLogger; | |
134 SkString currentLine; | |
135 }; | |
136 | |
137 #ifdef SK_BUILD_JSON_WRITER | |
138 /** | |
139 * This ResultsWriter collects data in a JSON node | |
jcgregorio
2014/05/27 19:57:16
PictureJSONResultsWriter
kelvinly
2014/05/27 20:27:31
Done.
| |
140 * | |
141 * The format is something like | |
142 * { | |
143 * benches: [ | |
144 * { | |
145 * name: "Name_of_test" | |
146 * tilesets: [ | |
147 * { | |
148 * name: "Name of the configuration" | |
149 * tiles: [ | |
150 * { | |
151 * flags: { | |
152 * purging: true //Flags for the current tile | |
153 * // are put here | |
154 * } | |
155 * data: { | |
156 * wsecs: [....] //Actual data ends up here | |
157 * } | |
158 * } | |
159 * ] | |
160 * } | |
161 * ] | |
162 * } | |
163 * ] | |
164 * }*/ | |
165 | |
166 class PictureJSONResultsWriter : public PictureResultsWriter { | |
167 public: | |
168 PictureJSONResultsWriter(const char filename[]) | |
169 : fFilename(filename), | |
170 fRoot(), | |
171 fCurrentBench(NULL), | |
172 fCurrentTileSet(NULL), | |
173 fCurrentTile(NULL) {;} | |
174 | |
175 virtual void bench(const char name[], int32_t x, int32_t y) { | |
176 SkString sk_name(name); | |
177 sk_name.append("_"); | |
178 sk_name.appendS32(x); | |
179 sk_name.append("_"); | |
180 sk_name.appendS32(y); | |
181 Json::Value* bench_node = SkFindNamedNode(&fRoot["benches"], sk_name.c_s tr()); | |
182 fCurrentBench = &(*bench_node)["tileSets"]; | |
183 } | |
184 virtual void tileConfig(SkString configName) { | |
185 SkASSERT(fCurrentBench != NULL); | |
186 fCurrentTileSet = SkFindNamedNode(fCurrentBench, configName.c_str()); | |
187 fCurrentTile = &(*fCurrentTileSet)["tiles"][0]; | |
188 } | |
189 virtual void tileMeta(int x, int y, int tx, int ty) { | |
190 SkASSERT(fCurrentTileSet != NULL); | |
191 (*fCurrentTileSet)["tx"] = tx; | |
192 (*fCurrentTileSet)["ty"] = ty; | |
193 fCurrentTile = &(*fCurrentTileSet)["tiles"][x+tx*y]; | |
194 } | |
195 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) { | |
196 SkASSERT(fCurrentTile != NULL); | |
197 if(flag == PictureResultsWriter::kPurging) { | |
198 (*fCurrentTile)["flags"]["purging"] = true; | |
199 } else if(flag == PictureResultsWriter::kAvg) { | |
200 (*fCurrentTile)["flags"]["averaged"] = true; | |
201 } | |
202 } | |
203 virtual void tileData( | |
204 TimerData* data, | |
205 const char format[], | |
206 const TimerData::Result result, | |
207 uint32_t timerTypes, | |
208 int numInnerLoops = 1) { | |
209 SkASSERT(fCurrentTile != NULL); | |
210 (*fCurrentTile)["data"] = data->getJSON(timerTypes, result, numInnerLoop s); | |
211 } | |
212 virtual void end() { | |
jcgregorio
2014/05/27 19:57:16
4 spaces
kelvinly
2014/05/27 20:27:31
Done.
| |
213 SkFILEWStream stream(fFilename.c_str()); | |
214 stream.writeText(Json::FastWriter().write(fRoot).c_str()); | |
215 stream.flush(); | |
216 } | |
217 private: | |
218 SkString fFilename; | |
219 Json::Value fRoot; | |
220 Json::Value *fCurrentBench; | |
221 Json::Value *fCurrentTileSet; | |
222 Json::Value *fCurrentTile; | |
223 }; | |
224 #endif // SK_BUILD_JSON_WRITER | |
225 | |
226 #endif | |
OLD | NEW |