| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 * } | 167 * } |
| 168 * ] | 168 * ] |
| 169 * } | 169 * } |
| 170 * ] | 170 * ] |
| 171 * } | 171 * } |
| 172 * ] | 172 * ] |
| 173 * }*/ | 173 * }*/ |
| 174 | 174 |
| 175 class PictureJSONResultsWriter : public PictureResultsWriter { | 175 class PictureJSONResultsWriter : public PictureResultsWriter { |
| 176 public: | 176 public: |
| 177 PictureJSONResultsWriter(const char filename[], | 177 PictureJSONResultsWriter(const char filename[], |
| 178 const char builderName[], | 178 const char builderName[], |
| 179 int buildNumber, | 179 int buildNumber, |
| 180 int timestamp, | 180 int timestamp, |
| 181 const char gitHash[], | 181 const char gitHash[], |
| 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 = SkMakeBuilderJSON(fBuilderName); | 189 fBuilderData = this->makeBuilderJson(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 virtual void bench(const char name[], int32_t x, int32_t y) SK_OVERRIDE { | 192 virtual 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 virtual 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 227 | 227 |
| 228 // Not including skpSize because that's deprecated? | 228 // Not including skpSize because that's deprecated? |
| 229 data["key"] = this->makeKey(iter.key().asString().c_str()).c_str(); | 229 data["key"] = this->makeKey(iter.key().asString().c_str()).c_str(); |
| 230 // Get the data | 230 // Get the data |
| 231 SkTArray<double> times; | 231 SkTArray<double> times; |
| 232 Json::Value val = *iter; | 232 Json::Value val = *iter; |
| 233 for(Json::ValueIterator vals = val.begin(); vals != val.end(); | 233 for(Json::ValueIterator vals = val.begin(); vals != val.end(); |
| 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 virtual void end() SK_OVERRIDE { |
| 245 fStream.flush(); | 245 fStream.flush(); |
| 246 } | 246 } |
| 247 private: | 247 private: |
| 248 Json::Value makeBuilderJson() const { |
| 249 static const int kNumKeys = 6; |
| 250 static const char* kKeys[kNumKeys] = { |
| 251 "role", "os", "model", "gpu", "arch", "configuration"}; |
| 252 Json::Value builderData; |
| 253 |
| 254 if (!fBuilderName.isEmpty()) { |
| 255 SkTArray<SkString> splitBuilder; |
| 256 SkStrSplit(fBuilderName.c_str(), "-", &splitBuilder); |
| 257 SkASSERT(splitBuilder.count() >= kNumKeys); |
| 258 for (int i = 0; i < kNumKeys && i < splitBuilder.count(); ++i) { |
| 259 builderData[kKeys[i]] = splitBuilder[i].c_str(); |
| 260 } |
| 261 builderData["builderName"] = fBuilderName.c_str(); |
| 262 if (kNumKeys < splitBuilder.count()) { |
| 263 SkString extras; |
| 264 for (int i = kNumKeys; i < splitBuilder.count(); ++i) { |
| 265 extras.append(splitBuilder[i]); |
| 266 if (i != splitBuilder.count() - 1) { |
| 267 extras.append("-"); |
| 268 } |
| 269 } |
| 270 builderData["badParams"] = extras.c_str(); |
| 271 } |
| 272 } |
| 273 return builderData; |
| 274 } |
| 275 |
| 248 static int CompareDoubles(const void* p1, const void* p2) { | 276 static int CompareDoubles(const void* p1, const void* p2) { |
| 249 if(*static_cast<const double*>(p1) < *static_cast<const double*>(p2)) { | 277 if(*static_cast<const double*>(p1) < *static_cast<const double*>(p2)) { |
| 250 return -1; | 278 return -1; |
| 251 } else if(*static_cast<const double*>(p1) == | 279 } else if(*static_cast<const double*>(p1) == |
| 252 *static_cast<const double*>(p2)) { | 280 *static_cast<const double*>(p2)) { |
| 253 return 0; | 281 return 0; |
| 254 } else { | 282 } else { |
| 255 return 1; | 283 return 1; |
| 256 } | 284 } |
| 257 } | 285 } |
| 258 SkString makeKey(const char measurementType[]) const { | 286 SkString makeKey(const char measurementType[]) const { |
| 259 SkString tmp(fBuilderName); | 287 SkString tmp(fBuilderName); |
| 260 tmp.append("_"); | 288 tmp.append("_"); |
| 261 tmp.append(fBenchName); | 289 tmp.append(fBenchName); |
| 262 tmp.append("_"); | 290 tmp.append("_"); |
| 263 tmp.append(fConfigString); | 291 tmp.append(fConfigString); |
| 264 tmp.append("_"); | 292 tmp.append("_"); |
| 265 tmp.append(measurementType); | 293 tmp.append(measurementType); |
| 266 return tmp; | 294 return tmp; |
| 267 } | 295 } |
| 268 | 296 |
| 269 SkFILEWStream fStream; | 297 SkFILEWStream fStream; |
| 270 Json::Value fBuilderData; | 298 Json::Value fBuilderData; |
| 271 SkString fBenchName; | 299 SkString fBenchName; |
| 272 Json::Value fParams; | 300 Json::Value fParams; |
| 273 | 301 |
| 274 SkString fConfigString; | 302 SkString fConfigString; |
| 275 SkString fBuilderName; | 303 SkString fBuilderName; |
| 276 int fBuildNumber; | 304 int fBuildNumber; |
| 277 int fTimestamp; | 305 int fTimestamp; |
| 278 SkString fGitHash; | 306 SkString fGitHash; |
| 279 int fGitNumber; | 307 int fGitNumber; |
| 280 }; | 308 }; |
| 281 | 309 |
| 282 #endif | 310 #endif |
| OLD | NEW |