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

Side by Side Diff: bench/nanobench.cpp

Issue 392393002: Change JSON output of nanobench. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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 | « bench/ResultsWriter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "Benchmark.h" 10 #include "Benchmark.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); 45 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
46 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); 46 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
47 47
48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); 48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work.");
49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); 49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work.");
50 50
51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); 51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h."); 52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h.");
53 DEFINE_int32(maxCalibrationAttempts, 3, 53 DEFINE_int32(maxCalibrationAttempts, 3,
54 "Try up to this many times to guess loops for a bench, or skip the bench."); 54 "Try up to this many times to guess loops for a bench, or skip the bench.");
55 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON.");
56 DEFINE_string(gitHash, "", "Git hash to add to JSON.");
55 57
56 58
57 static SkString humanize(double ms) { 59 static SkString humanize(double ms) {
58 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 60 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
59 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 61 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
60 #ifdef SK_BUILD_FOR_WIN 62 #ifdef SK_BUILD_FOR_WIN
61 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 63 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
62 #else 64 #else
63 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 65 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
64 #endif 66 #endif
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 #else 262 #else
261 log->option("system", "other"); 263 log->option("system", "other");
262 #endif 264 #endif
263 #if defined(SK_DEBUG) 265 #if defined(SK_DEBUG)
264 log->option("build", "DEBUG"); 266 log->option("build", "DEBUG");
265 #else 267 #else
266 log->option("build", "RELEASE"); 268 log->option("build", "RELEASE");
267 #endif 269 #endif
268 } 270 }
269 271
272 #if SK_SUPPORT_GPU
273 static void fill_gpu_options(ResultsWriter* log) {
274 // Need help, how do I get the GL version, vendor, renderer, etc?
jcgregorio 2014/07/16 19:11:29 Open question here, how do I do this?
bsalomon 2014/07/16 19:36:29 You want to tunnel the SkGLContextHelper here (ava
jcgregorio 2014/07/17 13:11:51 Thanks! On 2014/07/16 19:36:29, bsalomon wrote:
275 log->option("GL_VERSION", "4.4");
276 }
277 #endif
278
270 int tool_main(int argc, char** argv); 279 int tool_main(int argc, char** argv);
271 int tool_main(int argc, char** argv) { 280 int tool_main(int argc, char** argv) {
272 SetupCrashHandler(); 281 SetupCrashHandler();
273 SkAutoGraphics ag; 282 SkAutoGraphics ag;
274 SkCommandLineFlags::Parse(argc, argv); 283 SkCommandLineFlags::Parse(argc, argv);
275 284
276 if (FLAGS_runOnce) { 285 if (FLAGS_runOnce) {
277 FLAGS_samples = 1; 286 FLAGS_samples = 1;
278 FLAGS_gpuFrameLag = 0; 287 FLAGS_gpuFrameLag = 0;
279 } 288 }
280 289
281 MultiResultsWriter log; 290 MultiResultsWriter log;
282 SkAutoTDelete<JSONResultsWriter> json; 291 SkAutoTDelete<NanoJSONResultsWriter> json;
283 if (!FLAGS_outResultsFile.isEmpty()) { 292 if (!FLAGS_outResultsFile.isEmpty() && !FLAGS_gitHash.isEmpty() ) {
284 json.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0]))); 293 json.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0], FLAGS_gi tHash[0])));
285 log.add(json.get()); 294 log.add(json.get());
286 } 295 }
287 CallEnd<MultiResultsWriter> ender(log); 296 CallEnd<MultiResultsWriter> ender(log);
297
298 if (1 == FLAGS_key.count() % 2) {
299 SkDebugf("ERROR: --key must be passed with an even number of arguments") ;
300 return 1;
301 }
302 for (int i = 1; i < FLAGS_key.count(); i += 2) {
303 log.key(FLAGS_key[i-1], FLAGS_key[i]);
304 }
288 fill_static_options(&log); 305 fill_static_options(&log);
289 306
307 #if SK_SUPPORT_GPU
308 fill_gpu_options(&log);
309 #endif
310
290 const double overhead = estimate_timer_overhead(); 311 const double overhead = estimate_timer_overhead();
291 SkAutoTMalloc<double> samples(FLAGS_samples); 312 SkAutoTMalloc<double> samples(FLAGS_samples);
292 313
293 if (FLAGS_runOnce) { 314 if (FLAGS_runOnce) {
294 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n"); 315 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n");
295 } else if (FLAGS_verbose) { 316 } else if (FLAGS_verbose) {
296 // No header. 317 // No header.
297 } else if (FLAGS_quiet) { 318 } else if (FLAGS_quiet) {
298 SkDebugf("median\tbench\tconfig\n"); 319 SkDebugf("median\tbench\tconfig\n");
299 } else { 320 } else {
300 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); 321 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n");
301 } 322 }
302 323
303 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) { 324 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) {
304 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); 325 SkAutoTDelete<Benchmark> bench(r->factory()(NULL));
305 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { 326 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
306 continue; 327 continue;
307 } 328 }
308 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY); 329 bool loggedBench = false;
mtklein 2014/07/16 19:26:51 Why this change?
jcgregorio 2014/07/17 13:11:51 So that we only add info to the JSON file if we ac
309 330
310 SkTDArray<Target*> targets; 331 SkTDArray<Target*> targets;
311 create_targets(bench.get(), &targets); 332 create_targets(bench.get(), &targets);
312 333
313 bench->preDraw(); 334 bench->preDraw();
314 for (int j = 0; j < targets.count(); j++) { 335 for (int j = 0; j < targets.count(); j++) {
315 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; 336 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL;
316 const char* config = targets[j]->config; 337 const char* config = targets[j]->config;
317 338
318 const int loops = 339 const int loops =
319 #if SK_SUPPORT_GPU 340 #if SK_SUPPORT_GPU
320 Benchmark::kGPU_Backend == targets[j]->backend 341 Benchmark::kGPU_Backend == targets[j]->backend
321 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 342 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
322 : 343 :
323 #endif 344 #endif
324 cpu_bench( overhead, bench.get(), canvas, samples.get()); 345 cpu_bench( overhead, bench.get(), canvas, samples.get());
325 346
326 if (loops == 0) { 347 if (loops == 0) {
327 SkDebugf("Unable to time %s\t%s (overhead %s)\n", 348 SkDebugf("Unable to time %s\t%s (overhead %s)\n",
328 bench->getName(), config, humanize(overhead).c_str()); 349 bench->getName(), config, humanize(overhead).c_str());
329 continue; 350 continue;
330 } 351 }
352 if (!loggedBench) {
353 log.bench(bench->getName(), bench->getSize().fX, bench->getSize( ).fY);
354 loggedBench = true;
355 }
331 356
332 Stats stats(samples.get(), FLAGS_samples); 357 Stats stats(samples.get(), FLAGS_samples);
333 log.config(config); 358 log.config(config);
334 log.timer("min_ms", stats.min); 359 log.timer("min_ms", stats.min);
335 log.timer("median_ms", stats.median); 360 log.timer("median_ms", stats.median);
336 log.timer("mean_ms", stats.mean); 361 log.timer("mean_ms", stats.mean);
337 log.timer("max_ms", stats.max); 362 log.timer("max_ms", stats.max);
338 log.timer("stddev_ms", sqrt(stats.var)); 363 log.timer("stddev_ms", sqrt(stats.var));
339 364
340 if (FLAGS_runOnce) { 365 if (FLAGS_runOnce) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 402 }
378 403
379 return 0; 404 return 0;
380 } 405 }
381 406
382 #if !defined SK_BUILD_FOR_IOS 407 #if !defined SK_BUILD_FOR_IOS
383 int main(int argc, char * const argv[]) { 408 int main(int argc, char * const argv[]) {
384 return tool_main(argc, (char**) argv); 409 return tool_main(argc, (char**) argv);
385 } 410 }
386 #endif 411 #endif
OLDNEW
« no previous file with comments | « bench/ResultsWriter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698