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: 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"
11 #include "CrashHandler.h" 11 #include "CrashHandler.h"
12 #include "ResultsWriter.h" 12 #include "ResultsWriter.h"
13 #include "Stats.h" 13 #include "Stats.h"
14 #include "Timer.h" 14 #include "Timer.h"
15 15
16 #include "SkCanvas.h" 16 #include "SkCanvas.h"
17 #include "SkCommandLineFlags.h" 17 #include "SkCommandLineFlags.h"
18 #include "SkForceLinking.h" 18 #include "SkForceLinking.h"
19 #include "SkGraphics.h" 19 #include "SkGraphics.h"
20 #include "SkString.h" 20 #include "SkString.h"
21 #include "SkSurface.h" 21 #include "SkSurface.h"
22 22
23 #if SK_SUPPORT_GPU 23 #if SK_SUPPORT_GPU
24 #include "gl/GrGLDefines.h"
24 #include "GrContextFactory.h" 25 #include "GrContextFactory.h"
25 GrContextFactory gGrFactory; 26 GrContextFactory gGrFactory;
26 #endif 27 #endif
27 28
28 __SK_FORCE_IMAGE_DECODER_LINKING; 29 __SK_FORCE_IMAGE_DECODER_LINKING;
29 30
30 #if SK_DEBUG 31 #if SK_DEBUG
31 DEFINE_bool(runOnce, true, "Run each benchmark just once?"); 32 DEFINE_bool(runOnce, true, "Run each benchmark just once?");
32 #else 33 #else
33 DEFINE_bool(runOnce, false, "Run each benchmark just once?"); 34 DEFINE_bool(runOnce, false, "Run each benchmark just once?");
(...skipping 12 matching lines...) Expand all
46 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); 47 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
47 48
48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); 49 DEFINE_bool(cpu, true, "Master switch for CPU-bound work.");
49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); 50 DEFINE_bool(gpu, true, "Master switch for GPU-bound work.");
50 51
51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); 52 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h."); 53 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h.");
53 DEFINE_int32(maxCalibrationAttempts, 3, 54 DEFINE_int32(maxCalibrationAttempts, 3,
54 "Try up to this many times to guess loops for a bench, or skip the bench."); 55 "Try up to this many times to guess loops for a bench, or skip the bench.");
55 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); 56 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this.");
57 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON.");
58 DEFINE_string(gitHash, "", "Git hash to add to JSON.");
56 59
57 60
58 static SkString humanize(double ms) { 61 static SkString humanize(double ms) {
59 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 62 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
60 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 63 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
61 #ifdef SK_BUILD_FOR_WIN 64 #ifdef SK_BUILD_FOR_WIN
62 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 65 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
63 #else 66 #else
64 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 67 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
65 #endif 68 #endif
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 log->option("system", "WIN32"); 272 log->option("system", "WIN32");
270 #elif defined(SK_BUILD_FOR_MAC) 273 #elif defined(SK_BUILD_FOR_MAC)
271 log->option("system", "MAC"); 274 log->option("system", "MAC");
272 #elif defined(SK_BUILD_FOR_ANDROID) 275 #elif defined(SK_BUILD_FOR_ANDROID)
273 log->option("system", "ANDROID"); 276 log->option("system", "ANDROID");
274 #elif defined(SK_BUILD_FOR_UNIX) 277 #elif defined(SK_BUILD_FOR_UNIX)
275 log->option("system", "UNIX"); 278 log->option("system", "UNIX");
276 #else 279 #else
277 log->option("system", "other"); 280 log->option("system", "other");
278 #endif 281 #endif
279 #if defined(SK_DEBUG) 282 }
280 log->option("build", "DEBUG"); 283
281 #else 284 #if SK_SUPPORT_GPU
282 log->option("build", "RELEASE"); 285 static void fill_gpu_options(ResultsWriter* log, SkGLContextHelper* ctx) {
286 const GLubyte* version;
287 SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION));
288 log->configOption("GL_VERSION", (const char*)(version));
289
290 SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER));
291 log->configOption("GL_RENDERER", (const char*) version);
292
293 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
294 log->configOption("GL_VENDOR", (const char*) version);
295
296 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
297 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
298 }
283 #endif 299 #endif
284 }
285 300
286 int tool_main(int argc, char** argv); 301 int tool_main(int argc, char** argv);
287 int tool_main(int argc, char** argv) { 302 int tool_main(int argc, char** argv) {
288 SetupCrashHandler(); 303 SetupCrashHandler();
289 SkAutoGraphics ag; 304 SkAutoGraphics ag;
290 SkCommandLineFlags::Parse(argc, argv); 305 SkCommandLineFlags::Parse(argc, argv);
291 306
292 if (FLAGS_runOnce) { 307 if (FLAGS_runOnce) {
293 FLAGS_samples = 1; 308 FLAGS_samples = 1;
294 FLAGS_gpuFrameLag = 0; 309 FLAGS_gpuFrameLag = 0;
295 } 310 }
296 311
297 MultiResultsWriter log; 312 MultiResultsWriter log;
298 SkAutoTDelete<JSONResultsWriter> json; 313 SkAutoTDelete<NanoJSONResultsWriter> json;
299 if (!FLAGS_outResultsFile.isEmpty()) { 314 if (!FLAGS_outResultsFile.isEmpty()) {
300 json.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0]))); 315 const char* gitHash = FLAGS_gitHash.isEmpty() ? "unknown-revision" : FLA GS_gitHash[0];
316 json.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0], gitHash) ));
301 log.add(json.get()); 317 log.add(json.get());
302 } 318 }
303 CallEnd<MultiResultsWriter> ender(log); 319 CallEnd<MultiResultsWriter> ender(log);
320
321 if (1 == FLAGS_key.count() % 2) {
322 SkDebugf("ERROR: --key must be passed with an even number of arguments.\ n");
323 return 1;
324 }
325 for (int i = 1; i < FLAGS_key.count(); i += 2) {
326 log.key(FLAGS_key[i-1], FLAGS_key[i]);
327 }
304 fill_static_options(&log); 328 fill_static_options(&log);
305 329
306 const double overhead = estimate_timer_overhead(); 330 const double overhead = estimate_timer_overhead();
307 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); 331 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
308 332
309 SkAutoTMalloc<double> samples(FLAGS_samples); 333 SkAutoTMalloc<double> samples(FLAGS_samples);
310 334
311 if (FLAGS_runOnce) { 335 if (FLAGS_runOnce) {
312 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n"); 336 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n");
313 } else if (FLAGS_verbose) { 337 } else if (FLAGS_verbose) {
314 // No header. 338 // No header.
315 } else if (FLAGS_quiet) { 339 } else if (FLAGS_quiet) {
316 SkDebugf("median\tbench\tconfig\n"); 340 SkDebugf("median\tbench\tconfig\n");
317 } else { 341 } else {
318 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); 342 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n");
319 } 343 }
320 344
321 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) { 345 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) {
322 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); 346 SkAutoTDelete<Benchmark> bench(r->factory()(NULL));
323 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { 347 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
324 continue; 348 continue;
325 } 349 }
326 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY);
327 350
328 SkTDArray<Target*> targets; 351 SkTDArray<Target*> targets;
329 create_targets(bench.get(), &targets); 352 create_targets(bench.get(), &targets);
330 353
331 bench->preDraw(); 354 if (!targets.isEmpty()) {
355 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY );
356 bench->preDraw();
357 }
332 for (int j = 0; j < targets.count(); j++) { 358 for (int j = 0; j < targets.count(); j++) {
333 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; 359 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL;
334 const char* config = targets[j]->config; 360 const char* config = targets[j]->config;
335 361
336 const int loops = 362 const int loops =
337 #if SK_SUPPORT_GPU 363 #if SK_SUPPORT_GPU
338 Benchmark::kGPU_Backend == targets[j]->backend 364 Benchmark::kGPU_Backend == targets[j]->backend
339 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 365 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
340 : 366 :
341 #endif 367 #endif
342 cpu_bench( overhead, bench.get(), canvas, samples.get()); 368 cpu_bench( overhead, bench.get(), canvas, samples.get());
343 369
344 if (loops == 0) { 370 if (loops == 0) {
345 SkDebugf("Unable to time %s\t%s (overhead %s)\n", 371 SkDebugf("Unable to time %s\t%s (overhead %s)\n",
346 bench->getName(), config, HUMANIZE(overhead)); 372 bench->getName(), config, HUMANIZE(overhead));
347 continue; 373 continue;
348 } 374 }
349 375
350 Stats stats(samples.get(), FLAGS_samples); 376 Stats stats(samples.get(), FLAGS_samples);
351 log.config(config); 377 log.config(config);
378 #if SK_SUPPORT_GPU
379 if (Benchmark::kGPU_Backend == targets[j]->backend) {
380 fill_gpu_options(&log, targets[j]->gl);
381 }
382 #endif
352 log.timer("min_ms", stats.min); 383 log.timer("min_ms", stats.min);
353 log.timer("median_ms", stats.median); 384 log.timer("median_ms", stats.median);
354 log.timer("mean_ms", stats.mean); 385 log.timer("mean_ms", stats.mean);
355 log.timer("max_ms", stats.max); 386 log.timer("max_ms", stats.max);
356 log.timer("stddev_ms", sqrt(stats.var)); 387 log.timer("stddev_ms", sqrt(stats.var));
357 388
358 if (FLAGS_runOnce) { 389 if (FLAGS_runOnce) {
359 if (targets.count() == 1) { 390 if (targets.count() == 1) {
360 config = ""; // Only print the config if we run the same ben ch on more than one. 391 config = ""; // Only print the config if we run the same ben ch on more than one.
361 } 392 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 426 }
396 427
397 return 0; 428 return 0;
398 } 429 }
399 430
400 #if !defined SK_BUILD_FOR_IOS 431 #if !defined SK_BUILD_FOR_IOS
401 int main(int argc, char * const argv[]) { 432 int main(int argc, char * const argv[]) {
402 return tool_main(argc, (char**) argv); 433 return tool_main(argc, (char**) argv);
403 } 434 }
404 #endif 435 #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