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 "ProcStats.h" | 13 #include "ProcStats.h" |
14 #include "ResultsWriter.h" | 14 #include "ResultsWriter.h" |
15 #include "RecordingBench.h" | 15 #include "RecordingBench.h" |
16 #include "Resources.h" | |
16 #include "SKPBench.h" | 17 #include "SKPBench.h" |
18 #include "SKDBench.h" | |
17 #include "Stats.h" | 19 #include "Stats.h" |
18 #include "Timer.h" | 20 #include "Timer.h" |
19 | 21 |
20 #include "SkBBoxHierarchy.h" | 22 #include "SkBBoxHierarchy.h" |
21 #include "SkCanvas.h" | 23 #include "SkCanvas.h" |
22 #include "SkCommonFlags.h" | 24 #include "SkCommonFlags.h" |
23 #include "SkForceLinking.h" | 25 #include "SkForceLinking.h" |
24 #include "SkGraphics.h" | 26 #include "SkGraphics.h" |
25 #include "SkOSFile.h" | 27 #include "SkOSFile.h" |
26 #include "SkPictureRecorder.h" | 28 #include "SkPictureRecorder.h" |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 } | 434 } |
433 #endif | 435 #endif |
434 | 436 |
435 class BenchmarkStream { | 437 class BenchmarkStream { |
436 public: | 438 public: |
437 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 439 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
438 , fGMs(skiagm::GMRegistry::Head()) | 440 , fGMs(skiagm::GMRegistry::Head()) |
439 , fCurrentRecording(0) | 441 , fCurrentRecording(0) |
440 , fCurrentScale(0) | 442 , fCurrentScale(0) |
441 , fCurrentSKP(0) | 443 , fCurrentSKP(0) |
442 , fCurrentUseMPD(0) { | 444 , fCurrentUseMPD(0) |
445 , fCurrentColorType(0) { | |
443 for (int i = 0; i < FLAGS_skps.count(); i++) { | 446 for (int i = 0; i < FLAGS_skps.count(); i++) { |
444 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 447 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
445 fSKPs.push_back() = FLAGS_skps[i]; | 448 fSKPs.push_back() = FLAGS_skps[i]; |
446 } else { | 449 } else { |
447 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 450 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
448 SkString path; | 451 SkString path; |
449 while (it.next(&path)) { | 452 while (it.next(&path)) { |
450 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | 453 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); |
451 } | 454 } |
452 } | 455 } |
453 } | 456 } |
454 | 457 |
455 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", | 458 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
456 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { | 459 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { |
457 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); | 460 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); |
458 exit(1); | 461 exit(1); |
459 } | 462 } |
460 | 463 |
461 for (int i = 0; i < FLAGS_scales.count(); i++) { | 464 for (int i = 0; i < FLAGS_scales.count(); i++) { |
462 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { | 465 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
463 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); | 466 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); |
464 exit(1); | 467 exit(1); |
465 } | 468 } |
466 } | 469 } |
467 | 470 |
468 fUseMPDs.push_back() = false; | 471 fUseMPDs.push_back() = false; |
469 if (FLAGS_mpd) { | 472 if (FLAGS_mpd) { |
470 fUseMPDs.push_back() = true; | 473 fUseMPDs.push_back() = true; |
471 } | 474 } |
475 | |
476 // Get the resource path for SKD benchmarks | |
477 fResourceDir = GetResourcePath(); | |
scroggo
2015/02/11 19:38:10
Sorry, I think I mislead you in conversation; I th
msarett
2015/02/11 21:57:01
Done.
| |
478 if (fResourceDir.isEmpty()) { | |
479 SkDebugf("SKDBench Failed: fResourceDir is not specified"); | |
480 } | |
481 | |
482 // Get an iterator for resource files | |
483 fFileIter = *(new SkOSFile::Iter(fResourceDir.c_str())); | |
mtklein
2015/02/11 19:15:36
This pattern seems odd. It's allocating on the he
msarett
2015/02/11 21:57:01
Done.
| |
484 | |
485 // Choose the candidate color types | |
486 SkColorType colorTypes[3] = { kN32_SkColorType, | |
487 kRGB_565_SkColorType, | |
488 kAlpha_8_SkColorType }; | |
489 fColorTypes = *(new SkTArray<SkColorType>(colorTypes, 3)); | |
mtklein
2015/02/11 19:15:36
If this sticks, I think you might want to write th
msarett
2015/02/11 21:57:01
Done.
| |
472 } | 490 } |
473 | 491 |
474 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | 492 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
475 // Not strictly necessary, as it will be checked again later, | 493 // Not strictly necessary, as it will be checked again later, |
476 // but helps to avoid a lot of pointless work if we're going to skip it. | 494 // but helps to avoid a lot of pointless work if we're going to skip it. |
477 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | 495 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
478 return false; | 496 return false; |
479 } | 497 } |
480 | 498 |
481 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 499 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 (name.c_str(), pic.get(), fClip, | 573 (name.c_str(), pic.get(), fClip, |
556 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) ); | 574 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) ); |
557 } | 575 } |
558 fCurrentUseMPD = 0; | 576 fCurrentUseMPD = 0; |
559 fCurrentSKP++; | 577 fCurrentSKP++; |
560 } | 578 } |
561 fCurrentSKP = 0; | 579 fCurrentSKP = 0; |
562 fCurrentScale++; | 580 fCurrentScale++; |
563 } | 581 } |
564 | 582 |
583 // Run the SKDBenches | |
584 SkString file; | |
585 while (fFileIter.next(&file)) { | |
586 // Run a separate benchmark for each image and color type | |
587 SkString path = SkOSPath::Join(fResourceDir.c_str(), file.c_str()); | |
588 return SkNEW_ARGS(SKDBench, ("SKD", path, | |
scroggo
2015/02/11 19:38:10
As with SKPs and images in DM, I think we should c
msarett
2015/02/11 21:57:01
Done.
| |
589 fColorTypes[fCurrentColorType])); | |
590 } | |
591 // Reset the iterator for the next color type | |
592 if (++fCurrentColorType < fColorTypes.count()) { | |
593 fFileIter.reset(fResourceDir.c_str()); | |
594 while (fFileIter.next(&file)) { | |
595 SkString path = SkOSPath::Join(fResourceDir.c_str(), | |
596 file.c_str()); | |
597 return SkNEW_ARGS(SKDBench, ("SKD", path, | |
598 fColorTypes[fCurrentColorType])); | |
599 } | |
600 } | |
601 | |
565 return NULL; | 602 return NULL; |
566 } | 603 } |
567 | 604 |
568 void fillCurrentOptions(ResultsWriter* log) const { | 605 void fillCurrentOptions(ResultsWriter* log) const { |
569 log->configOption("source_type", fSourceType); | 606 log->configOption("source_type", fSourceType); |
570 log->configOption("bench_type", fBenchType); | 607 log->configOption("bench_type", fBenchType); |
571 if (0 == strcmp(fSourceType, "skp")) { | 608 if (0 == strcmp(fSourceType, "skp")) { |
572 log->configOption("clip", | 609 log->configOption("clip", |
573 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 610 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
574 fClip.fRight, fClip.fBottom).c _str()); | 611 fClip.fRight, fClip.fBottom).c _str()); |
575 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); | 612 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); |
576 if (fCurrentUseMPD > 0) { | 613 if (fCurrentUseMPD > 0) { |
577 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); | 614 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
578 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); | 615 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); |
579 } | 616 } |
580 } | 617 } |
581 if (0 == strcmp(fBenchType, "recording")) { | 618 if (0 == strcmp(fBenchType, "recording")) { |
582 log->metric("bytes", fSKPBytes); | 619 log->metric("bytes", fSKPBytes); |
583 log->metric("ops", fSKPOps); | 620 log->metric("ops", fSKPOps); |
584 } | 621 } |
585 } | 622 } |
586 | 623 |
587 private: | 624 private: |
588 const BenchRegistry* fBenches; | 625 const BenchRegistry* fBenches; |
589 const skiagm::GMRegistry* fGMs; | 626 const skiagm::GMRegistry* fGMs; |
590 SkIRect fClip; | 627 SkIRect fClip; |
591 SkTArray<SkScalar> fScales; | 628 SkTArray<SkScalar> fScales; |
592 SkTArray<SkString> fSKPs; | 629 SkTArray<SkString> fSKPs; |
593 SkTArray<bool> fUseMPDs; | 630 SkTArray<bool> fUseMPDs; |
631 SkString fResourceDir; | |
632 SkOSFile::Iter fFileIter; | |
594 | 633 |
595 double fSKPBytes, fSKPOps; | 634 double fSKPBytes, fSKPOps; |
596 | 635 |
597 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 636 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
598 const char* fBenchType; // How we bench it: micro, recording, playback, .. . | 637 const char* fBenchType; // How we bench it: micro, recording, playback, .. . |
599 int fCurrentRecording; | 638 int fCurrentRecording; |
600 int fCurrentScale; | 639 int fCurrentScale; |
601 int fCurrentSKP; | 640 int fCurrentSKP; |
602 int fCurrentUseMPD; | 641 int fCurrentUseMPD; |
642 SkTArray<SkColorType> fColorTypes; | |
643 int fCurrentColorType; | |
603 }; | 644 }; |
604 | 645 |
605 int nanobench_main(); | 646 int nanobench_main(); |
606 int nanobench_main() { | 647 int nanobench_main() { |
607 SetupCrashHandler(); | 648 SetupCrashHandler(); |
608 SkAutoGraphics ag; | 649 SkAutoGraphics ag; |
609 SkTaskGroup::Enabler enabled; | 650 SkTaskGroup::Enabler enabled; |
610 | 651 |
611 #if SK_SUPPORT_GPU | 652 #if SK_SUPPORT_GPU |
612 GrContext::Options grContextOpts; | 653 GrContext::Options grContextOpts; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 | 834 |
794 return 0; | 835 return 0; |
795 } | 836 } |
796 | 837 |
797 #if !defined SK_BUILD_FOR_IOS | 838 #if !defined SK_BUILD_FOR_IOS |
798 int main(int argc, char** argv) { | 839 int main(int argc, char** argv) { |
799 SkCommandLineFlags::Parse(argc, argv); | 840 SkCommandLineFlags::Parse(argc, argv); |
800 return nanobench_main(); | 841 return nanobench_main(); |
801 } | 842 } |
802 #endif | 843 #endif |
OLD | NEW |