Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: tools/PictureResultsWriter.h

Issue 286903025: PictureBenchmark JSON logging (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed typos, added a little more documentation Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/PictureBenchmark.cpp ('k') | tools/bench_pictures_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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() {}
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 /**
43 * This class allows bench data to be piped into multiple
44 * PictureResultWriter classes. It does not own any classes
45 * passed to it, so the owner is required to manage any classes
46 * passed to PictureResultsMultiWriter */
47 class PictureResultsMultiWriter : public PictureResultsWriter {
48 public:
49 PictureResultsMultiWriter() : writers() {;}
jcgregorio 2014/05/27 20:36:07 More stray semicolons here and below. Also see th
kelvinly 2014/05/27 20:41:17 Sorry, think I got all of them now
50 void add(PictureResultsWriter* newWriter) {
51 writers.push_back(newWriter);
52 }
53 virtual ~PictureResultsMultiWriter() {;}
54 virtual void bench(const char name[], int32_t x, int32_t y) {
55 for(int i=0; i<writers.count(); ++i) {
56 writers[i]->bench(name, x, y);
57 }
58 }
59 virtual void tileConfig(SkString configName) {
60 for(int i=0; i<writers.count(); ++i) {
61 writers[i]->tileConfig(configName);
62 }
63 }
64 virtual void tileMeta(int x, int y, int tx, int ty) {
65 for(int i=0; i<writers.count(); ++i) {
66 writers[i]->tileMeta(x, y, tx, ty);
67 }
68 }
69 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
70 for(int i=0; i<writers.count(); ++i) {
71 writers[i]->addTileFlag(flag);
72 }
73 }
74 virtual void tileData(
75 TimerData* data,
76 const char format[],
77 const TimerData::Result result,
78 uint32_t timerTypes,
79 int numInnerLoops = 1) {
80 for(int i=0; i<writers.count(); ++i) {
81 writers[i]->tileData(data, format, result, timerTypes,
82 numInnerLoops);
83 }
84 }
85 virtual void end() {
86 for(int i=0; i<writers.count(); ++i) {
87 writers[i]->end();
88 }
89 }
90 private:
91 SkTArray<PictureResultsWriter*> writers;
jcgregorio 2014/05/27 20:36:07 fWriters
kelvinly 2014/05/27 20:41:17 Done.
92 };
93
94 /**
95 * Writes to SkBenchLogger to mimic original behavior
96 */
97 class PictureResultsLoggerWriter : public PictureResultsWriter {
98 private:
99 void logProgress(const char str[]) {
100 if(fLogger != NULL) {
101 fLogger->logProgress(str);
102 }
103 }
104 public:
105 PictureResultsLoggerWriter(SkBenchLogger* log)
106 : fLogger(log), currentLine() {;}
107 virtual void bench(const char name[], int32_t x, int32_t y) {
108 SkString result;
109 result.printf("running bench [%i %i] %s ", x, y, name);
110 this->logProgress(result.c_str());
111 }
112 virtual void tileConfig(SkString configName) {
113 currentLine = configName;
114 }
115 virtual void tileMeta(int x, int y, int tx, int ty) {
116 currentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty);
117 }
118 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
119 if(flag == PictureResultsWriter::kPurging) {
120 currentLine.append(" <withPurging>");
121 } else if(flag == PictureResultsWriter::kAvg) {
122 currentLine.append(" <averaged>");
123 }
124 }
125 virtual void tileData(
126 TimerData* data,
127 const char format[],
128 const TimerData::Result result,
129 uint32_t timerTypes,
130 int numInnerLoops = 1) {
131 SkString results = data->getResult(format, result,
132 currentLine.c_str(), timerTypes, numInnerLoops);
133 results.append("\n");
134 this->logProgress(results.c_str());
135 }
136 virtual void end() {;}
137 private:
138 SkBenchLogger* fLogger;
139 SkString currentLine;
140 };
141
142 #ifdef SK_BUILD_JSON_WRITER
143 /**
144 * This PictureResultsWriter collects data in a JSON node
145 *
146 * The format is something like
147 * {
148 * benches: [
149 * {
150 * name: "Name_of_test"
151 * tilesets: [
152 * {
153 * name: "Name of the configuration"
154 * tiles: [
155 * {
156 * flags: {
157 * purging: true //Flags for the current tile
158 * // are put here
159 * }
160 * data: {
161 * wsecs: [....] //Actual data ends up here
162 * }
163 * }
164 * ]
165 * }
166 * ]
167 * }
168 * ]
169 * }*/
170
171 class PictureJSONResultsWriter : public PictureResultsWriter {
172 public:
173 PictureJSONResultsWriter(const char filename[])
174 : fFilename(filename),
175 fRoot(),
176 fCurrentBench(NULL),
177 fCurrentTileSet(NULL),
178 fCurrentTile(NULL) {;}
179
180 virtual void bench(const char name[], int32_t x, int32_t y) {
181 SkString sk_name(name);
182 sk_name.append("_");
183 sk_name.appendS32(x);
184 sk_name.append("_");
185 sk_name.appendS32(y);
186 Json::Value* bench_node = SkFindNamedNode(&fRoot["benches"], sk_name.c_s tr());
187 fCurrentBench = &(*bench_node)["tileSets"];
188 }
189 virtual void tileConfig(SkString configName) {
190 SkASSERT(fCurrentBench != NULL);
191 fCurrentTileSet = SkFindNamedNode(fCurrentBench, configName.c_str());
192 fCurrentTile = &(*fCurrentTileSet)["tiles"][0];
193 }
194 virtual void tileMeta(int x, int y, int tx, int ty) {
195 SkASSERT(fCurrentTileSet != NULL);
196 (*fCurrentTileSet)["tx"] = tx;
197 (*fCurrentTileSet)["ty"] = ty;
198 fCurrentTile = &(*fCurrentTileSet)["tiles"][x+tx*y];
199 }
200 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
201 SkASSERT(fCurrentTile != NULL);
202 if(flag == PictureResultsWriter::kPurging) {
203 (*fCurrentTile)["flags"]["purging"] = true;
204 } else if(flag == PictureResultsWriter::kAvg) {
205 (*fCurrentTile)["flags"]["averaged"] = true;
206 }
207 }
208 virtual void tileData(
209 TimerData* data,
210 const char format[],
211 const TimerData::Result result,
212 uint32_t timerTypes,
213 int numInnerLoops = 1) {
214 SkASSERT(fCurrentTile != NULL);
215 (*fCurrentTile)["data"] = data->getJSON(timerTypes, result, numInnerLoop s);
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 SkString fFilename;
224 Json::Value fRoot;
225 Json::Value *fCurrentBench;
226 Json::Value *fCurrentTileSet;
227 Json::Value *fCurrentTile;
228 };
229 #endif // SK_BUILD_JSON_WRITER
230
231 #endif
OLDNEW
« no previous file with comments | « tools/PictureBenchmark.cpp ('k') | tools/bench_pictures_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698