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

Side by Side Diff: bench/nanobench.cpp

Issue 918673002: Adding new benchmark to test image decoding performance. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Image decode benchmarking code (revision 2) Created 5 years, 10 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
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 "DecodingBench.h"
12 #include "GMBench.h" 13 #include "GMBench.h"
13 #include "ProcStats.h" 14 #include "ProcStats.h"
14 #include "ResultsWriter.h" 15 #include "ResultsWriter.h"
15 #include "RecordingBench.h" 16 #include "RecordingBench.h"
17 #include "Resources.h"
16 #include "SKPBench.h" 18 #include "SKPBench.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"
27 #include "SkPictureUtils.h" 29 #include "SkPictureUtils.h"
28 #include "SkString.h" 30 #include "SkString.h"
29 #include "SkSurface.h" 31 #include "SkSurface.h"
30 #include "SkTaskGroup.h" 32 #include "SkTaskGroup.h"
31 33
34 #include <stdio.h>
35
msarett 2015/02/11 21:57:01 I will remove this. I was using it to debug and i
mtklein 2015/02/12 00:29:34 One day you will find yourself typing SkDebugf acc
msarett 2015/02/12 18:52:56 :)
32 #if SK_SUPPORT_GPU 36 #if SK_SUPPORT_GPU
33 #include "gl/GrGLDefines.h" 37 #include "gl/GrGLDefines.h"
34 #include "GrContextFactory.h" 38 #include "GrContextFactory.h"
35 SkAutoTDelete<GrContextFactory> gGrFactory; 39 SkAutoTDelete<GrContextFactory> gGrFactory;
36 #endif 40 #endif
37 41
38 __SK_FORCE_IMAGE_DECODER_LINKING; 42 __SK_FORCE_IMAGE_DECODER_LINKING;
39 43
40 static const int kAutoTuneLoops = 0; 44 static const int kAutoTuneLoops = 0;
41 45
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 436 }
433 #endif 437 #endif
434 438
435 class BenchmarkStream { 439 class BenchmarkStream {
436 public: 440 public:
437 BenchmarkStream() : fBenches(BenchRegistry::Head()) 441 BenchmarkStream() : fBenches(BenchRegistry::Head())
438 , fGMs(skiagm::GMRegistry::Head()) 442 , fGMs(skiagm::GMRegistry::Head())
439 , fCurrentRecording(0) 443 , fCurrentRecording(0)
440 , fCurrentScale(0) 444 , fCurrentScale(0)
441 , fCurrentSKP(0) 445 , fCurrentSKP(0)
442 , fCurrentUseMPD(0) { 446 , fCurrentUseMPD(0)
447 , fCurrentImage(0)
448 , fCurrentColorType(0) {
443 for (int i = 0; i < FLAGS_skps.count(); i++) { 449 for (int i = 0; i < FLAGS_skps.count(); i++) {
444 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 450 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
445 fSKPs.push_back() = FLAGS_skps[i]; 451 fSKPs.push_back() = FLAGS_skps[i];
446 } else { 452 } else {
447 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 453 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
448 SkString path; 454 SkString path;
449 while (it.next(&path)) { 455 while (it.next(&path)) {
450 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); 456 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ());
451 } 457 }
452 } 458 }
453 } 459 }
454 460
455 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", 461 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
456 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { 462 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) {
457 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); 463 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]);
458 exit(1); 464 exit(1);
459 } 465 }
460 466
461 for (int i = 0; i < FLAGS_scales.count(); i++) { 467 for (int i = 0; i < FLAGS_scales.count(); i++) {
462 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { 468 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]); 469 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]);
464 exit(1); 470 exit(1);
465 } 471 }
466 } 472 }
467 473
468 fUseMPDs.push_back() = false; 474 fUseMPDs.push_back() = false;
469 if (FLAGS_mpd) { 475 if (FLAGS_mpd) {
470 fUseMPDs.push_back() = true; 476 fUseMPDs.push_back() = true;
471 } 477 }
478
479 // Prepare the images for decoding
480 for (int i = 0; i < FLAGS_images.count(); i++) {
481 const char* flag = FLAGS_images[i];
482 // If the value passed in is a directory, add all the images
483 if (sk_isdir(flag)) {
484 SkOSFile::Iter it(flag);
485 SkString file;
486 while (it.next(&file)) {
487 fImages.push_back() = SkOSPath::Join(flag, file.c_str());
488 }
489 }
490 // Also add the value if it is a single image
491 else if (sk_exists(flag)) {
scroggo 2015/02/12 14:19:02 This should go on the same line as the closing bra
msarett 2015/02/12 18:52:56 Done.
492 fImages.push_back() = flag;
493 }
494 }
495
496 // Choose the candidate color types for image decoding
497 SkColorType colorTypes[] =
498 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType };
_cary 2015/02/12 15:18:05 make this const
msarett 2015/02/12 18:52:56 Done.
499 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes);
472 } 500 }
473 501
474 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { 502 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
475 // Not strictly necessary, as it will be checked again later, 503 // 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. 504 // but helps to avoid a lot of pointless work if we're going to skip it.
477 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { 505 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
478 return false; 506 return false;
479 } 507 }
480 508
481 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); 509 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 (name.c_str(), pic.get(), fClip, 583 (name.c_str(), pic.get(), fClip,
556 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) ); 584 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) );
557 } 585 }
558 fCurrentUseMPD = 0; 586 fCurrentUseMPD = 0;
559 fCurrentSKP++; 587 fCurrentSKP++;
560 } 588 }
561 fCurrentSKP = 0; 589 fCurrentSKP = 0;
562 fCurrentScale++; 590 fCurrentScale++;
563 } 591 }
564 592
593 // Run the DecodingBenches
594 SkString file;
595 while (fCurrentImage < fImages.count()) {
596 while (fCurrentColorType < fColorTypes.count()) {
597 SkString path = fImages[fCurrentImage];
_cary 2015/02/12 15:18:05 const SkString& path
msarett 2015/02/12 18:52:56 Done.
598 SkColorType colorType = fColorTypes[fCurrentColorType];
599 fCurrentColorType++;
600 // Check if the image decodes before creating the benchmark
601 SkBitmap bitmap;
602 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap,
603 colorType, SkImageDecoder::kDecodePixels_Mode)) {
604 return SkNEW_ARGS(DecodingBench, (path, colorType));
605 }
606 }
607 fCurrentColorType = 0;
608 fCurrentImage++;
609 }
610
565 return NULL; 611 return NULL;
566 } 612 }
567 613
568 void fillCurrentOptions(ResultsWriter* log) const { 614 void fillCurrentOptions(ResultsWriter* log) const {
569 log->configOption("source_type", fSourceType); 615 log->configOption("source_type", fSourceType);
570 log->configOption("bench_type", fBenchType); 616 log->configOption("bench_type", fBenchType);
571 if (0 == strcmp(fSourceType, "skp")) { 617 if (0 == strcmp(fSourceType, "skp")) {
572 log->configOption("clip", 618 log->configOption("clip",
573 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, 619 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
574 fClip.fRight, fClip.fBottom).c _str()); 620 fClip.fRight, fClip.fBottom).c _str());
575 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); 621 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str());
576 if (fCurrentUseMPD > 0) { 622 if (fCurrentUseMPD > 0) {
577 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); 623 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
578 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); 624 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false");
579 } 625 }
580 } 626 }
581 if (0 == strcmp(fBenchType, "recording")) { 627 if (0 == strcmp(fBenchType, "recording")) {
582 log->metric("bytes", fSKPBytes); 628 log->metric("bytes", fSKPBytes);
583 log->metric("ops", fSKPOps); 629 log->metric("ops", fSKPOps);
584 } 630 }
585 } 631 }
586 632
587 private: 633 private:
588 const BenchRegistry* fBenches; 634 const BenchRegistry* fBenches;
589 const skiagm::GMRegistry* fGMs; 635 const skiagm::GMRegistry* fGMs;
590 SkIRect fClip; 636 SkIRect fClip;
591 SkTArray<SkScalar> fScales; 637 SkTArray<SkScalar> fScales;
592 SkTArray<SkString> fSKPs; 638 SkTArray<SkString> fSKPs;
593 SkTArray<bool> fUseMPDs; 639 SkTArray<bool> fUseMPDs;
640 SkTArray<SkString> fImages;
641 SkTArray<SkColorType> fColorTypes;
594 642
595 double fSKPBytes, fSKPOps; 643 double fSKPBytes, fSKPOps;
596 644
597 const char* fSourceType; // What we're benching: bench, GM, SKP, ... 645 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
598 const char* fBenchType; // How we bench it: micro, recording, playback, .. . 646 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
599 int fCurrentRecording; 647 int fCurrentRecording;
600 int fCurrentScale; 648 int fCurrentScale;
601 int fCurrentSKP; 649 int fCurrentSKP;
602 int fCurrentUseMPD; 650 int fCurrentUseMPD;
651 int fCurrentImage;
652 int fCurrentColorType;
603 }; 653 };
604 654
605 int nanobench_main(); 655 int nanobench_main();
606 int nanobench_main() { 656 int nanobench_main() {
607 SetupCrashHandler(); 657 SetupCrashHandler();
608 SkAutoGraphics ag; 658 SkAutoGraphics ag;
609 SkTaskGroup::Enabler enabled; 659 SkTaskGroup::Enabler enabled;
610 660
611 #if SK_SUPPORT_GPU 661 #if SK_SUPPORT_GPU
612 GrContext::Options grContextOpts; 662 GrContext::Options grContextOpts;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 843
794 return 0; 844 return 0;
795 } 845 }
796 846
797 #if !defined SK_BUILD_FOR_IOS 847 #if !defined SK_BUILD_FOR_IOS
798 int main(int argc, char** argv) { 848 int main(int argc, char** argv) {
799 SkCommandLineFlags::Parse(argc, argv); 849 SkCommandLineFlags::Parse(argc, argv);
800 return nanobench_main(); 850 return nanobench_main();
801 } 851 }
802 #endif 852 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698