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

Side by Side Diff: bench/nanobench.cpp

Issue 559153002: Measure picture recording speed in nanobench. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 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/RecordingBench.cpp ('k') | gyp/bench.gyp » ('j') | 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 "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 "SKPBench.h" 16 #include "SKPBench.h"
16 #include "Stats.h" 17 #include "Stats.h"
17 #include "Timer.h" 18 #include "Timer.h"
18 19
19 #include "SkBBHFactory.h" 20 #include "SkBBHFactory.h"
20 #include "SkCanvas.h" 21 #include "SkCanvas.h"
21 #include "SkCommonFlags.h" 22 #include "SkCommonFlags.h"
22 #include "SkForceLinking.h" 23 #include "SkForceLinking.h"
23 #include "SkGraphics.h" 24 #include "SkGraphics.h"
24 #include "SkOSFile.h" 25 #include "SkOSFile.h"
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 401
401 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); 402 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
402 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); 403 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
403 } 404 }
404 #endif 405 #endif
405 406
406 class BenchmarkStream { 407 class BenchmarkStream {
407 public: 408 public:
408 BenchmarkStream() : fBenches(BenchRegistry::Head()) 409 BenchmarkStream() : fBenches(BenchRegistry::Head())
409 , fGMs(skiagm::GMRegistry::Head()) 410 , fGMs(skiagm::GMRegistry::Head())
411 , fCurrentRecording(0)
410 , fCurrentScale(0) 412 , fCurrentScale(0)
411 , fCurrentSKP(0) { 413 , fCurrentSKP(0) {
412 for (int i = 0; i < FLAGS_skps.count(); i++) { 414 for (int i = 0; i < FLAGS_skps.count(); i++) {
413 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 415 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
414 fSKPs.push_back() = FLAGS_skps[i]; 416 fSKPs.push_back() = FLAGS_skps[i];
415 } else { 417 } else {
416 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 418 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
417 SkString path; 419 SkString path;
418 while (it.next(&path)) { 420 while (it.next(&path)) {
419 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); 421 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ());
420 } 422 }
421 } 423 }
422 } 424 }
423 425
424 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", 426 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
425 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { 427 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) {
426 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); 428 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]);
427 exit(1); 429 exit(1);
428 } 430 }
429 431
430 for (int i = 0; i < FLAGS_scales.count(); i++) { 432 for (int i = 0; i < FLAGS_scales.count(); i++) {
431 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { 433 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
432 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); 434 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]);
433 exit(1); 435 exit(1);
434 } 436 }
435 } 437 }
436 } 438 }
437 439
440 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
441 // Not strictly necessary, as it will be checked again later,
442 // but helps to avoid a lot of pointless work if we're going to skip it.
443 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
444 return false;
445 }
446
447 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
448 if (stream.get() == NULL) {
449 SkDebugf("Could not read %s.\n", path);
450 return false;
451 }
452
453 pic->reset(SkPicture::CreateFromStream(stream.get()));
454 if (pic->get() == NULL) {
455 SkDebugf("Could not read %s as an SkPicture.\n", path);
456 return false;
457 }
458 return true;
459 }
460
438 Benchmark* next() { 461 Benchmark* next() {
439 if (fBenches) { 462 if (fBenches) {
440 Benchmark* bench = fBenches->factory()(NULL); 463 Benchmark* bench = fBenches->factory()(NULL);
441 fBenches = fBenches->next(); 464 fBenches = fBenches->next();
442 fSourceType = "bench"; 465 fSourceType = "bench";
466 fBenchType = "micro";
443 return bench; 467 return bench;
444 } 468 }
445 469
446 while (fGMs) { 470 while (fGMs) {
447 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); 471 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
448 fGMs = fGMs->next(); 472 fGMs = fGMs->next();
449 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { 473 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
450 fSourceType = "gm"; 474 fSourceType = "gm";
475 fBenchType = "micro";
451 return SkNEW_ARGS(GMBench, (gm.detach())); 476 return SkNEW_ARGS(GMBench, (gm.detach()));
452 } 477 }
453 } 478 }
454 479
480 // First add all .skps as RecordingBenches.
481 while (fCurrentRecording < fSKPs.count()) {
482 const SkString& path = fSKPs[fCurrentRecording++];
483 SkAutoTUnref<SkPicture> pic;
484 if (!ReadPicture(path.c_str(), &pic)) {
485 continue;
486 }
487 SkString name = SkOSPath::Basename(path.c_str());
488 fSourceType = "skp";
489 fBenchType = "recording";
490 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h));
491 }
492
493 // Then once each for each scale as SKPBenches (playback).
455 while (fCurrentScale < fScales.count()) { 494 while (fCurrentScale < fScales.count()) {
456 while (fCurrentSKP < fSKPs.count()) { 495 while (fCurrentSKP < fSKPs.count()) {
457 const SkString& path = fSKPs[fCurrentSKP++]; 496 const SkString& path = fSKPs[fCurrentSKP++];
458 497 SkAutoTUnref<SkPicture> pic;
459 // Not strictly necessary, as it will be checked again later, 498 if (!ReadPicture(path.c_str(), &pic)) {
460 // but helps to avoid a lot of pointless work if we're going to skip it.
461 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
462 continue; 499 continue;
463 } 500 }
464
465 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str() ));
466 if (stream.get() == NULL) {
467 SkDebugf("Could not read %s.\n", path.c_str());
468 exit(1);
469 }
470
471 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.g et()));
472 if (pic.get() == NULL) {
473 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str( ));
474 exit(1);
475 }
476
477 SkString name = SkOSPath::Basename(path.c_str());
478
479 if (FLAGS_bbh) { 501 if (FLAGS_bbh) {
480 // The SKP we read off disk doesn't have a BBH. Re-record s o it grows one. 502 // The SKP we read off disk doesn't have a BBH. Re-record s o it grows one.
481 // Here we use an SkTileGrid with parameters optimized for F LAGS_clip. 503 // Here we use an SkTileGrid with parameters optimized for F LAGS_clip.
482 const SkTileGridFactory::TileGridInfo info = { 504 const SkTileGridFactory::TileGridInfo info = {
483 SkISize::Make(fClip.width(), fClip.height()), // tile i nterval 505 SkISize::Make(fClip.width(), fClip.height()), // tile i nterval
484 SkISize::Make(0,0), // margin 506 SkISize::Make(0,0), // margin
485 SkIPoint::Make(fClip.left(), fClip.top()), // offset 507 SkIPoint::Make(fClip.left(), fClip.top()), // offset
486 }; 508 };
487 SkTileGridFactory factory(info); 509 SkTileGridFactory factory(info);
488 SkPictureRecorder recorder; 510 SkPictureRecorder recorder;
489 pic->playback(recorder.beginRecording(pic->cullRect().width( ), 511 pic->playback(recorder.beginRecording(pic->cullRect().width( ),
490 pic->cullRect().height (), 512 pic->cullRect().height (),
491 &factory)); 513 &factory));
492 pic.reset(recorder.endRecording()); 514 pic.reset(recorder.endRecording());
493 } 515 }
494 516 SkString name = SkOSPath::Basename(path.c_str());
495 fSourceType = "skp"; 517 fSourceType = "skp";
518 fBenchType = "playback";
496 return SkNEW_ARGS(SKPBench, 519 return SkNEW_ARGS(SKPBench,
497 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]) ); 520 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]) );
498 } 521 }
499 fCurrentSKP = 0; 522 fCurrentSKP = 0;
500 fCurrentScale++; 523 fCurrentScale++;
501 } 524 }
502 525
503 return NULL; 526 return NULL;
504 } 527 }
505 528
506 void fillCurrentOptions(ResultsWriter* log) const { 529 void fillCurrentOptions(ResultsWriter* log) const {
507 log->configOption("source_type", fSourceType); 530 log->configOption("source_type", fSourceType);
531 log->configOption("bench_type", fBenchType);
508 if (0 == strcmp(fSourceType, "skp")) { 532 if (0 == strcmp(fSourceType, "skp")) {
509 log->configOption("clip", 533 log->configOption("clip",
510 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, 534 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
511 fClip.fRight, fClip.fBottom).c _str()); 535 fClip.fRight, fClip.fBottom).c _str());
512 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); 536 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str());
513 } 537 }
514 } 538 }
515 539
516 private: 540 private:
517 const BenchRegistry* fBenches; 541 const BenchRegistry* fBenches;
518 const skiagm::GMRegistry* fGMs; 542 const skiagm::GMRegistry* fGMs;
519 SkIRect fClip; 543 SkIRect fClip;
520 SkTArray<SkScalar> fScales; 544 SkTArray<SkScalar> fScales;
521 SkTArray<SkString> fSKPs; 545 SkTArray<SkString> fSKPs;
522 546
523 const char* fSourceType; 547 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
548 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
549 int fCurrentRecording;
524 int fCurrentScale; 550 int fCurrentScale;
525 int fCurrentSKP; 551 int fCurrentSKP;
526 }; 552 };
527 553
528 int nanobench_main(); 554 int nanobench_main();
529 int nanobench_main() { 555 int nanobench_main() {
530 SetupCrashHandler(); 556 SetupCrashHandler();
531 SkAutoGraphics ag; 557 SkAutoGraphics ag;
532 558
533 #if SK_SUPPORT_GPU 559 #if SK_SUPPORT_GPU
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 713
688 return 0; 714 return 0;
689 } 715 }
690 716
691 #if !defined SK_BUILD_FOR_IOS 717 #if !defined SK_BUILD_FOR_IOS
692 int main(int argc, char** argv) { 718 int main(int argc, char** argv) {
693 SkCommandLineFlags::Parse(argc, argv); 719 SkCommandLineFlags::Parse(argc, argv);
694 return nanobench_main(); 720 return nanobench_main();
695 } 721 }
696 #endif 722 #endif
OLDNEW
« no previous file with comments | « bench/RecordingBench.cpp ('k') | gyp/bench.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698