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

Side by Side Diff: tools/PictureResultsWriter.h

Issue 286903025: PictureBenchmark JSON logging (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Switch JSON styles from styled to fast Created 6 years, 7 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
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 "SkBenchLogger.h"
13 #include "SkJSONCPP.h"
14 #include "SkStream.h"
15 #include "SkString.h"
16 #include "SkTArray.h"
17
18 /**
19 * Base class for writing picture bench results.
20 */
21 class PictureResultsWriter : SkNoncopyable {
22 protected:
23 Json::Value* find_named_node(Json::Value* root, const char name[]) {
jcgregorio 2014/05/27 15:34:25 Why is find_named_node duplicated here?
kelvinly 2014/05/27 16:41:06 I guess I copy and pasted from ResultsWriter, and
24 Json::Value* search_results = NULL;
25 for(Json::Value::iterator iter = root->begin();
26 iter!= root->end(); ++iter) {
27 if(SkString(name).equals((*iter)["name"].asCString())) {
28 search_results = &(*iter);
29 break;
30 }
31 }
32
33 if(search_results != NULL) {
34 return search_results;
35 } else {
36 Json::Value* new_val = &(root->append(Json::Value()));
37 (*new_val)["name"] = name;
38 return new_val;
39 }
40 }
41
42 public:
43 enum TileFlags {kPurging, kAvg};
44
45 PictureResultsWriter() {;}
46 virtual ~PictureResultsWriter() {;}
47
48 virtual void bench(const char name[], int32_t x, int32_t y) = 0;
49 virtual void tileConfig(SkString configName) = 0;
50 virtual void tileMeta(int x, int y, int tx, int ty) = 0;
51 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) = 0;
52 virtual void tileData(
53 TimerData* data,
54 const char format[],
55 const TimerData::Result result,
56 uint32_t timerTypes,
57 int numInnerLoops = 1) = 0;
58 virtual void end() = 0;
59 };
60
61 class PictureResultsMultiWriter : public PictureResultsWriter {
62 public:
63 PictureResultsMultiWriter() : writers() {;}
64 void add(PictureResultsWriter* newWriter) {
65 writers.push_back(newWriter);
66 }
67 virtual ~PictureResultsMultiWriter() {;}
68 virtual void bench(const char name[], int32_t x, int32_t y) {
69 for(int i=0; i<writers.count(); ++i) {
70 writers[i]->bench(name, x, y);
71 }
72 }
73 virtual void tileConfig(SkString configName) {
74 for(int i=0; i<writers.count(); ++i) {
75 writers[i]->tileConfig(configName);
76 }
77 }
78 virtual void tileMeta(int x, int y, int tx, int ty) {
79 for(int i=0; i<writers.count(); ++i) {
80 writers[i]->tileMeta(x, y, tx, ty);
81 }
82 }
83 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
84 for(int i=0; i<writers.count(); ++i) {
85 writers[i]->addTileFlag(flag);
86 }
87 }
88 virtual void tileData(
89 TimerData* data,
90 const char format[],
91 const TimerData::Result result,
92 uint32_t timerTypes,
93 int numInnerLoops = 1) {
94 for(int i=0; i<writers.count(); ++i) {
95 writers[i]->tileData(data, format, result, timerTypes,
96 numInnerLoops);
97 }
98 }
99 virtual void end() {
100 for(int i=0; i<writers.count(); ++i) {
101 writers[i]->end();
102 }
103 }
104 private:
105 SkTArray<PictureResultsWriter*> writers;
106 };
107
108 /**
109 * Writes to SkBenchLogger to mimic original behavior
110 */
111 class PictureResultsLoggerWriter : public PictureResultsWriter {
112 private:
113 void logProgress(const char str[]) {
114 if(fLogger != NULL) {
115 fLogger->logProgress(str);
116 }
117 }
118 public:
119 PictureResultsLoggerWriter(SkBenchLogger* log)
120 : fLogger(log), currentLine() {;}
121 virtual void bench(const char name[], int32_t x, int32_t y) {
122 SkString result;
123 result.printf("running bench [%i %i] %s ", x, y, name);
124 this->logProgress(result.c_str());
125 }
126 virtual void tileConfig(SkString configName) {
127 currentLine = configName;
128 }
129 virtual void tileMeta(int x, int y, int tx, int ty) {
130 currentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty);
131 }
132 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
133 if(flag == PictureResultsWriter::kPurging) {
134 currentLine.append(" <withPurging>");
135 } else if(flag == PictureResultsWriter::kAvg) {
136 currentLine.append(" <averaged>");
137 }
138 }
139 virtual void tileData(
140 TimerData* data,
141 const char format[],
142 const TimerData::Result result,
143 uint32_t timerTypes,
144 int numInnerLoops = 1) {
145 SkString results = data->getResult(format, result,
146 currentLine.c_str(), timerTypes, numInnerLoops);
147 results.append("\n");
148 this->logProgress(results.c_str());
149 }
150 virtual void end() {;}
151 private:
152 SkBenchLogger* fLogger;
153 SkString currentLine;
154 };
155
156 #ifdef SK_BUILD_JSON_WRITER
157 /**
158 * This ResultsWriter collects data in a JSON node
159 */
160 class PictureJSONResultsWriter : public PictureResultsWriter {
161 public:
162 PictureJSONResultsWriter(const char filename[])
163 : fFilename(filename),
164 fRoot(),
165 fCurrentBench(NULL),
166 fCurrentTileSet(NULL),
167 fCurrentTile(NULL) {;}
168
169 virtual void bench(const char name[], int32_t x, int32_t y) {
170 SkString sk_name(name);
171 sk_name.append("_");
172 sk_name.appendS32(x);
173 sk_name.append("_");
174 sk_name.appendS32(y);
175 Json::Value* bench_node = find_named_node(&fRoot["benches"], sk_name.c_s tr());
176 fCurrentBench = &(*bench_node)["tileSets"];
177 }
178 virtual void tileConfig(SkString configName) {
179 SkASSERT(fCurrentBench != NULL);
180 fCurrentTileSet = find_named_node(fCurrentBench, configName.c_str());
181 fCurrentTile = &(*fCurrentTileSet)["tiles"][0];
182 }
183 virtual void tileMeta(int x, int y, int tx, int ty) {
184 SkASSERT(fCurrentTileSet != NULL);
185 (*fCurrentTileSet)["tx"] = tx;
186 (*fCurrentTileSet)["ty"] = ty;
187 fCurrentTile = &(*fCurrentTileSet)["tiles"][x+tx*y];
188 }
189 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
190 SkASSERT(fCurrentTile != NULL);
191 if(flag == PictureResultsWriter::kPurging) {
192 (*fCurrentTile)["flags"]["purging"] = true;
193 } else if(flag == PictureResultsWriter::kAvg) {
194 (*fCurrentTile)["flags"]["averaged"] = true;
195 }
196 }
197 virtual void tileData(
198 TimerData* data,
199 const char format[],
200 const TimerData::Result result,
201 uint32_t timerTypes,
202 int numInnerLoops = 1) {
203 SkASSERT(fCurrentTile != NULL);
204 (*fCurrentTile)["data"] = data->getJSON(timerTypes, result, numInnerLoop s);
205 }
206 virtual void end() {
207 SkFILEWStream stream(fFilename.c_str());
208 stream.writeText(Json::FastWriter().write(fRoot).c_str());
209 stream.flush();
210 }
211 private:
212 SkString fFilename;
213 Json::Value fRoot;
214 Json::Value *fCurrentBench;
215 Json::Value *fCurrentTileSet;
216 Json::Value *fCurrentTile;
217 };
218 #endif // SK_BUILD_JSON_WRITER
219
220 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698