OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 SkPictureResultsWriter_DEFINED | 10 #ifndef SkPictureResultsWriter_DEFINED |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 * passed to it, so the owner is required to manage any classes | 49 * passed to it, so the owner is required to manage any classes |
50 * passed to PictureResultsMultiWriter */ | 50 * passed to PictureResultsMultiWriter */ |
51 class PictureResultsMultiWriter : public PictureResultsWriter { | 51 class PictureResultsMultiWriter : public PictureResultsWriter { |
52 public: | 52 public: |
53 PictureResultsMultiWriter() | 53 PictureResultsMultiWriter() |
54 : fWriters() {} | 54 : fWriters() {} |
55 void add(PictureResultsWriter* newWriter) { | 55 void add(PictureResultsWriter* newWriter) { |
56 fWriters.push_back(newWriter); | 56 fWriters.push_back(newWriter); |
57 } | 57 } |
58 virtual ~PictureResultsMultiWriter() {} | 58 virtual ~PictureResultsMultiWriter() {} |
59 virtual void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { | 59 void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { |
60 for(int i=0; i<fWriters.count(); ++i) { | 60 for(int i=0; i<fWriters.count(); ++i) { |
61 fWriters[i]->bench(name, x, y); | 61 fWriters[i]->bench(name, x, y); |
62 } | 62 } |
63 } | 63 } |
64 virtual void logRenderer(sk_tools::PictureRenderer *pr) SK_OVERRIDE { | 64 void logRenderer(sk_tools::PictureRenderer *pr) SK_OVERRIDE { |
65 for(int i=0; i<fWriters.count(); ++i) { | 65 for(int i=0; i<fWriters.count(); ++i) { |
66 fWriters[i]->logRenderer(pr); | 66 fWriters[i]->logRenderer(pr); |
67 } | 67 } |
68 } | 68 } |
69 virtual void tileMeta(int x, int y, int tx, int ty) SK_OVERRIDE { | 69 void tileMeta(int x, int y, int tx, int ty) SK_OVERRIDE { |
70 for(int i=0; i<fWriters.count(); ++i) { | 70 for(int i=0; i<fWriters.count(); ++i) { |
71 fWriters[i]->tileMeta(x, y, tx, ty); | 71 fWriters[i]->tileMeta(x, y, tx, ty); |
72 } | 72 } |
73 } | 73 } |
74 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) SK_OVERRIDE { | 74 void addTileFlag(PictureResultsWriter::TileFlags flag) SK_OVERRIDE { |
75 for(int i=0; i<fWriters.count(); ++i) { | 75 for(int i=0; i<fWriters.count(); ++i) { |
76 fWriters[i]->addTileFlag(flag); | 76 fWriters[i]->addTileFlag(flag); |
77 } | 77 } |
78 } | 78 } |
79 virtual void tileData( | 79 virtual void tileData( |
80 TimerData* data, | 80 TimerData* data, |
81 const char format[], | 81 const char format[], |
82 const TimerData::Result result, | 82 const TimerData::Result result, |
83 uint32_t timerTypes, | 83 uint32_t timerTypes, |
84 int numInnerLoops = 1) SK_OVERRIDE { | 84 int numInnerLoops = 1) SK_OVERRIDE { |
85 for(int i=0; i<fWriters.count(); ++i) { | 85 for(int i=0; i<fWriters.count(); ++i) { |
86 fWriters[i]->tileData(data, format, result, timerTypes, | 86 fWriters[i]->tileData(data, format, result, timerTypes, |
87 numInnerLoops); | 87 numInnerLoops); |
88 } | 88 } |
89 } | 89 } |
90 virtual void end() SK_OVERRIDE { | 90 void end() SK_OVERRIDE { |
91 for(int i=0; i<fWriters.count(); ++i) { | 91 for(int i=0; i<fWriters.count(); ++i) { |
92 fWriters[i]->end(); | 92 fWriters[i]->end(); |
93 } | 93 } |
94 } | 94 } |
95 private: | 95 private: |
96 SkTArray<PictureResultsWriter*> fWriters; | 96 SkTArray<PictureResultsWriter*> fWriters; |
97 }; | 97 }; |
98 | 98 |
99 /** | 99 /** |
100 * Writes to BenchLogger to mimic original behavior | 100 * Writes to BenchLogger to mimic original behavior |
101 */ | 101 */ |
102 class PictureResultsLoggerWriter : public PictureResultsWriter { | 102 class PictureResultsLoggerWriter : public PictureResultsWriter { |
103 private: | 103 private: |
104 void logProgress(const char str[]) { | 104 void logProgress(const char str[]) { |
105 if(fLogger != NULL) { | 105 if(fLogger != NULL) { |
106 fLogger->logProgress(str); | 106 fLogger->logProgress(str); |
107 } | 107 } |
108 } | 108 } |
109 public: | 109 public: |
110 PictureResultsLoggerWriter(BenchLogger* log) | 110 PictureResultsLoggerWriter(BenchLogger* log) |
111 : fLogger(log), fCurrentLine() {} | 111 : fLogger(log), fCurrentLine() {} |
112 virtual void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { | 112 void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { |
113 SkString result; | 113 SkString result; |
114 result.printf("running bench [%i %i] %s ", x, y, name); | 114 result.printf("running bench [%i %i] %s ", x, y, name); |
115 this->logProgress(result.c_str()); | 115 this->logProgress(result.c_str()); |
116 } | 116 } |
117 virtual void logRenderer(sk_tools::PictureRenderer* renderer) SK_OVERRIDE { | 117 void logRenderer(sk_tools::PictureRenderer* renderer) SK_OVERRIDE { |
118 fCurrentLine = renderer->getConfigName(); | 118 fCurrentLine = renderer->getConfigName(); |
119 } | 119 } |
120 virtual void tileMeta(int x, int y, int tx, int ty) SK_OVERRIDE { | 120 void tileMeta(int x, int y, int tx, int ty) SK_OVERRIDE { |
121 fCurrentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty); | 121 fCurrentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty); |
122 } | 122 } |
123 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) SK_OVERRIDE { | 123 void addTileFlag(PictureResultsWriter::TileFlags flag) SK_OVERRIDE { |
124 if(flag == PictureResultsWriter::kPurging) { | 124 if(flag == PictureResultsWriter::kPurging) { |
125 fCurrentLine.append(" <withPurging>"); | 125 fCurrentLine.append(" <withPurging>"); |
126 } else if(flag == PictureResultsWriter::kAvg) { | 126 } else if(flag == PictureResultsWriter::kAvg) { |
127 fCurrentLine.append(" <averaged>"); | 127 fCurrentLine.append(" <averaged>"); |
128 } | 128 } |
129 } | 129 } |
130 virtual void tileData( | 130 virtual void tileData( |
131 TimerData* data, | 131 TimerData* data, |
132 const char format[], | 132 const char format[], |
133 const TimerData::Result result, | 133 const TimerData::Result result, |
134 uint32_t timerTypes, | 134 uint32_t timerTypes, |
135 int numInnerLoops = 1) SK_OVERRIDE { | 135 int numInnerLoops = 1) SK_OVERRIDE { |
136 SkString results = data->getResult(format, result, | 136 SkString results = data->getResult(format, result, |
137 fCurrentLine.c_str(), timerTypes, numInnerLoops); | 137 fCurrentLine.c_str(), timerTypes, numInnerLoops); |
138 results.append("\n"); | 138 results.append("\n"); |
139 this->logProgress(results.c_str()); | 139 this->logProgress(results.c_str()); |
140 } | 140 } |
141 virtual void end() SK_OVERRIDE {} | 141 void end() SK_OVERRIDE {} |
142 private: | 142 private: |
143 BenchLogger* fLogger; | 143 BenchLogger* fLogger; |
144 SkString fCurrentLine; | 144 SkString fCurrentLine; |
145 }; | 145 }; |
146 | 146 |
147 /** | 147 /** |
148 * This PictureResultsWriter collects data in a JSON node | 148 * This PictureResultsWriter collects data in a JSON node |
149 * | 149 * |
150 * The format is something like | 150 * The format is something like |
151 * { | 151 * { |
(...skipping 30 matching lines...) Expand all Loading... |
182 int gitNumber) | 182 int gitNumber) |
183 : fStream(filename) { | 183 : fStream(filename) { |
184 fBuilderName = SkString(builderName); | 184 fBuilderName = SkString(builderName); |
185 fBuildNumber = buildNumber; | 185 fBuildNumber = buildNumber; |
186 fTimestamp = timestamp; | 186 fTimestamp = timestamp; |
187 fGitHash = SkString(gitHash); | 187 fGitHash = SkString(gitHash); |
188 fGitNumber = gitNumber; | 188 fGitNumber = gitNumber; |
189 fBuilderData = this->makeBuilderJson(); | 189 fBuilderData = this->makeBuilderJson(); |
190 } | 190 } |
191 | 191 |
192 virtual void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { | 192 void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { |
193 fBenchName = SkString(name); | 193 fBenchName = SkString(name); |
194 } | 194 } |
195 virtual void logRenderer(sk_tools::PictureRenderer* pr) SK_OVERRIDE { | 195 void logRenderer(sk_tools::PictureRenderer* pr) SK_OVERRIDE { |
196 fParams = pr->getJSONConfig(); | 196 fParams = pr->getJSONConfig(); |
197 fConfigString = pr->getConfigName(); | 197 fConfigString = pr->getConfigName(); |
198 } | 198 } |
199 // Apparently tiles aren't used, so tileMeta is empty | 199 // Apparently tiles aren't used, so tileMeta is empty |
200 virtual void tileMeta(int x, int y, int tx, int ty) SK_OVERRIDE {} | 200 void tileMeta(int x, int y, int tx, int ty) SK_OVERRIDE {} |
201 // Flags aren't used, so addTileFlag is empty | 201 // Flags aren't used, so addTileFlag is empty |
202 virtual void addTileFlag(PictureResultsWriter::TileFlags flag) SK_OVERRIDE {
} | 202 void addTileFlag(PictureResultsWriter::TileFlags flag) SK_OVERRIDE {} |
203 virtual void tileData( | 203 virtual void tileData( |
204 TimerData* data, | 204 TimerData* data, |
205 const char format[], | 205 const char format[], |
206 const TimerData::Result result, | 206 const TimerData::Result result, |
207 uint32_t timerTypes, | 207 uint32_t timerTypes, |
208 int numInnerLoops = 1) SK_OVERRIDE { | 208 int numInnerLoops = 1) SK_OVERRIDE { |
209 Json::Value newData = data->getJSON(timerTypes, result, numInnerLoops); | 209 Json::Value newData = data->getJSON(timerTypes, result, numInnerLoops); |
210 Json::Value combinedParams(fBuilderData); | 210 Json::Value combinedParams(fBuilderData); |
211 for(Json::ValueIterator iter = fParams.begin(); iter != fParams.end(); | 211 for(Json::ValueIterator iter = fParams.begin(); iter != fParams.end(); |
212 iter++) { | 212 iter++) { |
(...skipping 21 matching lines...) Expand all Loading... |
234 vals++) { | 234 vals++) { |
235 times.push_back((*vals).asDouble()); | 235 times.push_back((*vals).asDouble()); |
236 } | 236 } |
237 qsort(static_cast<void*>(times.begin()), times.count(), | 237 qsort(static_cast<void*>(times.begin()), times.count(), |
238 sizeof(double), PictureJSONResultsWriter::CompareDoubles); | 238 sizeof(double), PictureJSONResultsWriter::CompareDoubles); |
239 data["value"] = times[static_cast<int>(times.count() * 0.25f)]; | 239 data["value"] = times[static_cast<int>(times.count() * 0.25f)]; |
240 data["params"]["measurementType"] = iter.key().asString(); | 240 data["params"]["measurementType"] = iter.key().asString(); |
241 fStream.writeText(Json::FastWriter().write(data).c_str()); | 241 fStream.writeText(Json::FastWriter().write(data).c_str()); |
242 } | 242 } |
243 } | 243 } |
244 virtual void end() SK_OVERRIDE { | 244 void end() SK_OVERRIDE { |
245 fStream.flush(); | 245 fStream.flush(); |
246 } | 246 } |
247 private: | 247 private: |
248 Json::Value makeBuilderJson() const { | 248 Json::Value makeBuilderJson() const { |
249 static const int kNumKeys = 6; | 249 static const int kNumKeys = 6; |
250 static const char* kKeys[kNumKeys] = { | 250 static const char* kKeys[kNumKeys] = { |
251 "role", "os", "model", "gpu", "arch", "configuration"}; | 251 "role", "os", "model", "gpu", "arch", "configuration"}; |
252 Json::Value builderData; | 252 Json::Value builderData; |
253 | 253 |
254 if (!fBuilderName.isEmpty()) { | 254 if (!fBuilderName.isEmpty()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 301 |
302 SkString fConfigString; | 302 SkString fConfigString; |
303 SkString fBuilderName; | 303 SkString fBuilderName; |
304 int fBuildNumber; | 304 int fBuildNumber; |
305 int fTimestamp; | 305 int fTimestamp; |
306 SkString fGitHash; | 306 SkString fGitHash; |
307 int fGitNumber; | 307 int fGitNumber; |
308 }; | 308 }; |
309 | 309 |
310 #endif | 310 #endif |
OLD | NEW |