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 | 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 "GMBench.h" | 12 #include "GMBench.h" |
13 #include "ResultsWriter.h" | 13 #include "ResultsWriter.h" |
14 #include "SKPBench.h" | |
14 #include "Stats.h" | 15 #include "Stats.h" |
15 #include "Timer.h" | 16 #include "Timer.h" |
16 | 17 |
18 #include "SkOSFile.h" | |
17 #include "SkCanvas.h" | 19 #include "SkCanvas.h" |
18 #include "SkCommonFlags.h" | 20 #include "SkCommonFlags.h" |
19 #include "SkForceLinking.h" | 21 #include "SkForceLinking.h" |
20 #include "SkGraphics.h" | 22 #include "SkGraphics.h" |
21 #include "SkString.h" | 23 #include "SkString.h" |
22 #include "SkSurface.h" | 24 #include "SkSurface.h" |
23 | 25 |
24 #if SK_SUPPORT_GPU | 26 #if SK_SUPPORT_GPU |
25 #include "gl/GrGLDefines.h" | 27 #include "gl/GrGLDefines.h" |
26 #include "GrContextFactory.h" | 28 #include "GrContextFactory.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
42 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); | 44 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
43 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); | 45 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); |
44 | 46 |
45 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); | 47 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
46 DEFINE_int32(maxCalibrationAttempts, 3, | 48 DEFINE_int32(maxCalibrationAttempts, 3, |
47 "Try up to this many times to guess loops for a bench, or skip the bench."); | 49 "Try up to this many times to guess loops for a bench, or skip the bench."); |
48 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); | 50 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
49 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); | 51 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); |
50 DEFINE_string(gitHash, "", "Git hash to add to JSON."); | 52 DEFINE_string(gitHash, "", "Git hash to add to JSON."); |
51 | 53 |
54 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); | |
55 DEFINE_string(scales, "1.0,1.1", "Scales for SKPs."); | |
bsalomon
2014/08/01 13:23:24
Maybe the default should just be 1.0?
mtklein
2014/08/01 13:55:34
Done.
Oddly, having a single value by default mak
| |
56 | |
52 static SkString humanize(double ms) { | 57 static SkString humanize(double ms) { |
53 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); | 58 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
54 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); | 59 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
55 #ifdef SK_BUILD_FOR_WIN | 60 #ifdef SK_BUILD_FOR_WIN |
56 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); | 61 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); |
57 #else | 62 #else |
58 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); | 63 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
59 #endif | 64 #endif |
60 return SkStringPrintf("%.3gms", ms); | 65 return SkStringPrintf("%.3gms", ms); |
61 } | 66 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); | 355 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); |
351 log->configOption("GL_VENDOR", (const char*) version); | 356 log->configOption("GL_VENDOR", (const char*) version); |
352 | 357 |
353 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); | 358 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
354 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); | 359 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
355 } | 360 } |
356 #endif | 361 #endif |
357 | 362 |
358 class BenchmarkStream { | 363 class BenchmarkStream { |
359 public: | 364 public: |
360 BenchmarkStream() : fBenches(BenchRegistry::Head()) , fGMs(skiagm::GMRegistr y::Head()) {} | 365 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
366 , fGMs(skiagm::GMRegistry::Head()) | |
367 , fCurrentScale(0) | |
368 , fCurrentSKP(0) { | |
369 if (!FLAGS_skps.isEmpty()) { | |
370 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | |
371 SkString path; | |
372 while (it.next(&path)) { | |
373 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); | |
374 } | |
375 } | |
361 | 376 |
362 Benchmark* next(const char** sourceType) { | 377 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
378 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { | |
379 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); | |
380 exit(1); | |
381 } | |
382 | |
383 SkTArray<SkString> scales; | |
384 SkStrSplit(FLAGS_scales[0], ",", &scales); | |
385 for (int i = 0; i < scales.count(); i++) { | |
386 if (1 != sscanf(scales[i].c_str(), "%f", &fScales.push_back())) { | |
387 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", scale s[i].c_str()); | |
388 exit(1); | |
389 } | |
390 } | |
391 } | |
392 | |
393 Benchmark* next() { | |
363 if (fBenches) { | 394 if (fBenches) { |
364 Benchmark* bench = fBenches->factory()(NULL); | 395 Benchmark* bench = fBenches->factory()(NULL); |
365 fBenches = fBenches->next(); | 396 fBenches = fBenches->next(); |
366 *sourceType = "bench"; | 397 fSourceType = "bench"; |
367 return bench; | 398 return bench; |
368 } | 399 } |
400 | |
369 while (fGMs) { | 401 while (fGMs) { |
370 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); | 402 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
371 fGMs = fGMs->next(); | 403 fGMs = fGMs->next(); |
372 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { | 404 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { |
373 *sourceType = "gm"; | 405 fSourceType = "gm"; |
374 return SkNEW_ARGS(GMBench, (gm.detach())); | 406 return SkNEW_ARGS(GMBench, (gm.detach())); |
375 } | 407 } |
376 } | 408 } |
409 | |
410 while (fCurrentScale < fScales.count()) { | |
411 while (fCurrentSKP < fSKPs.count()) { | |
412 const SkString& path = fSKPs[fCurrentSKP++]; | |
413 | |
414 // Not strictly necessary, as it will be checked again later, | |
415 // but helps to avoid a lot of pointless work if we're going to skip it. | |
416 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { | |
417 continue; | |
418 } | |
419 | |
420 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str() )); | |
421 if (stream.get() == NULL) { | |
422 SkDebugf("Could not read %s.\n", path.c_str()); | |
423 exit(1); | |
424 } | |
425 | |
426 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.g et())); | |
427 if (pic.get() == NULL) { | |
428 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str( )); | |
429 exit(1); | |
430 } | |
431 | |
432 SkString name = SkOSPath::Basename(path.c_str()); | |
433 | |
434 fSourceType = "skp"; | |
435 return SkNEW_ARGS(SKPBench, | |
436 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]) ); | |
437 } | |
438 fCurrentSKP = 0; | |
439 fCurrentScale++; | |
440 } | |
441 | |
377 return NULL; | 442 return NULL; |
378 } | 443 } |
444 | |
445 void fillCurrentOptions(ResultsWriter* log) const { | |
446 log->configOption("source_type", fSourceType); | |
447 if (0 == strcmp(fSourceType, "skp")) { | |
448 log->configOption("clip", | |
449 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | |
450 fClip.fRight, fClip.fBottom).c _str()); | |
451 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); | |
452 } | |
453 } | |
454 | |
379 private: | 455 private: |
380 const BenchRegistry* fBenches; | 456 const BenchRegistry* fBenches; |
381 const skiagm::GMRegistry* fGMs; | 457 const skiagm::GMRegistry* fGMs; |
458 SkIRect fClip; | |
459 SkTArray<SkScalar> fScales; | |
460 SkTArray<SkString> fSKPs; | |
461 | |
462 const char* fSourceType; | |
463 int fCurrentScale; | |
464 int fCurrentSKP; | |
382 }; | 465 }; |
383 | 466 |
384 int nanobench_main(); | 467 int nanobench_main(); |
385 int nanobench_main() { | 468 int nanobench_main() { |
386 SetupCrashHandler(); | 469 SetupCrashHandler(); |
387 SkAutoGraphics ag; | 470 SkAutoGraphics ag; |
388 | 471 |
389 if (FLAGS_runOnce) { | 472 if (FLAGS_runOnce) { |
390 FLAGS_samples = 1; | 473 FLAGS_samples = 1; |
391 FLAGS_gpuFrameLag = 0; | 474 FLAGS_gpuFrameLag = 0; |
(...skipping 28 matching lines...) Expand all Loading... | |
420 // No header. | 503 // No header. |
421 } else if (FLAGS_quiet) { | 504 } else if (FLAGS_quiet) { |
422 SkDebugf("median\tbench\tconfig\n"); | 505 SkDebugf("median\tbench\tconfig\n"); |
423 } else { | 506 } else { |
424 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); | 507 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); |
425 } | 508 } |
426 | 509 |
427 SkTDArray<Config> configs; | 510 SkTDArray<Config> configs; |
428 create_configs(&configs); | 511 create_configs(&configs); |
429 | 512 |
430 BenchmarkStream benches; | 513 BenchmarkStream benchStream; |
431 const char* sourceType; | 514 while (Benchmark* b = benchStream.next()) { |
432 while (Benchmark* b = benches.next(&sourceType)) { | |
433 SkAutoTDelete<Benchmark> bench(b); | 515 SkAutoTDelete<Benchmark> bench(b); |
434 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | 516 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
435 continue; | 517 continue; |
436 } | 518 } |
437 | 519 |
438 SkTDArray<Target*> targets; | 520 SkTDArray<Target*> targets; |
439 create_targets(&targets, bench.get(), configs); | 521 create_targets(&targets, bench.get(), configs); |
440 | 522 |
441 if (!targets.isEmpty()) { | 523 if (!targets.isEmpty()) { |
442 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY ); | 524 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY ); |
443 bench->preDraw(); | 525 bench->preDraw(); |
444 } | 526 } |
445 for (int j = 0; j < targets.count(); j++) { | 527 for (int j = 0; j < targets.count(); j++) { |
446 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; | 528 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; |
447 const char* config = targets[j]->config.name; | 529 const char* config = targets[j]->config.name; |
448 | 530 |
531 #if SK_DEBUG | |
532 // FIXME: Some SKPs SkASSERT in debug mode. Skip them for now until we can fix things. | |
bsalomon
2014/08/01 13:23:24
Should prolly file a bug and stick a link to it he
mtklein
2014/08/01 13:55:34
Done.
| |
533 if (0 == strcmp("565", config) | |
534 && ( SkStrStartsWith(bench->getName(), "desk_carsvg.skp") | |
535 || SkStrStartsWith(bench->getName(), "desk_forecastio.skp ") | |
536 || SkStrStartsWith(bench->getName(), "tabl_cnet.skp") | |
537 || SkStrStartsWith(bench->getName(), "tabl_googlecalendar .skp"))) { | |
538 SkDebugf("Skipping 565 %s. It'd assert.\n", bench->getName()); | |
539 continue; | |
540 } | |
541 #endif | |
542 | |
449 const int loops = | 543 const int loops = |
450 #if SK_SUPPORT_GPU | 544 #if SK_SUPPORT_GPU |
451 Benchmark::kGPU_Backend == targets[j]->config.backend | 545 Benchmark::kGPU_Backend == targets[j]->config.backend |
452 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) | 546 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
453 : | 547 : |
454 #endif | 548 #endif |
455 cpu_bench( overhead, bench.get(), canvas, samples.get()); | 549 cpu_bench( overhead, bench.get(), canvas, samples.get()); |
456 | 550 |
457 if (loops == 0) { | 551 if (loops == 0) { |
458 SkDebugf("Unable to time %s\t%s (overhead %s)\n", | 552 SkDebugf("Unable to time %s\t%s (overhead %s)\n", |
459 bench->getName(), config, HUMANIZE(overhead)); | 553 bench->getName(), config, HUMANIZE(overhead)); |
460 continue; | 554 continue; |
461 } | 555 } |
462 | 556 |
463 Stats stats(samples.get(), FLAGS_samples); | 557 Stats stats(samples.get(), FLAGS_samples); |
464 log.config(config); | 558 log.config(config); |
465 log.configOption("source_type", sourceType); | 559 benchStream.fillCurrentOptions(&log); |
466 #if SK_SUPPORT_GPU | 560 #if SK_SUPPORT_GPU |
467 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { | 561 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { |
468 fill_gpu_options(&log, targets[j]->gl); | 562 fill_gpu_options(&log, targets[j]->gl); |
469 } | 563 } |
470 #endif | 564 #endif |
471 log.timer("min_ms", stats.min); | 565 log.timer("min_ms", stats.min); |
472 log.timer("median_ms", stats.median); | 566 log.timer("median_ms", stats.median); |
473 log.timer("mean_ms", stats.mean); | 567 log.timer("mean_ms", stats.mean); |
474 log.timer("max_ms", stats.max); | 568 log.timer("max_ms", stats.max); |
475 log.timer("stddev_ms", sqrt(stats.var)); | 569 log.timer("stddev_ms", sqrt(stats.var)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 | 612 |
519 return 0; | 613 return 0; |
520 } | 614 } |
521 | 615 |
522 #if !defined SK_BUILD_FOR_IOS | 616 #if !defined SK_BUILD_FOR_IOS |
523 int main(int argc, char** argv) { | 617 int main(int argc, char** argv) { |
524 SkCommandLineFlags::Parse(argc, argv); | 618 SkCommandLineFlags::Parse(argc, argv); |
525 return nanobench_main(); | 619 return nanobench_main(); |
526 } | 620 } |
527 #endif | 621 #endif |
OLD | NEW |