add pipe to nanobench
authorMike Reed <reed@google.com>
Fri, 21 Oct 2016 14:43:36 +0000 (10:43 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 21 Oct 2016 15:02:45 +0000 (15:02 +0000)
BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3801

Change-Id: Ia0b90b1e2947a7b9ae7cb340ef5cd5b3251bbd23
Reviewed-on: https://skia-review.googlesource.com/3801
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>

bench/RecordingBench.cpp
bench/RecordingBench.h
bench/nanobench.cpp

index d8034ce5d5f3cc174743a8b0ca28f3935ec90422..69be9114674e5b084e338abe79614f2485ea882b 100644 (file)
 #include "SkLiteRecorder.h"
 #include "SkPictureRecorder.h"
 
-RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite)
-    : fName(name)
-    , fUseBBH(useBBH) {
+PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
     // Flatten the source picture in case it's trivially nested (useless for timing).
     SkPictureRecorder rec;
     pic->playback(rec.beginRecording(pic->cullRect(), nullptr,
                                      SkPictureRecorder::kPlaybackDrawPicture_RecordFlag));
     fSrc = rec.finishRecordingAsPicture();
-
-    // If we're recording into an SkLiteDL, also record _from_ one.
-    if (lite) {
-        fDL = SkLiteDL::New(pic->cullRect());
-        SkLiteRecorder r;
-        r.reset(fDL.get());
-        fSrc->playback(&r);
-    }
 }
 
-const char* RecordingBench::onGetName() {
+const char* PictureCentricBench::onGetName() {
     return fName.c_str();
 }
 
-bool RecordingBench::isSuitableFor(Backend backend) {
+bool PictureCentricBench::isSuitableFor(Backend backend) {
     return backend == kNonRendering_Backend;
 }
 
-SkIPoint RecordingBench::onGetSize() {
+SkIPoint PictureCentricBench::onGetSize() {
     return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
                           SkScalarCeilToInt(fSrc->cullRect().height()));
 }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite)
+    : INHERITED(name, pic)
+    , fUseBBH(useBBH)
+{
+    // If we're recording into an SkLiteDL, also record _from_ one.
+    if (lite) {
+        fDL = SkLiteDL::New(fSrc->cullRect());
+        SkLiteRecorder r;
+        r.reset(fDL.get());
+        fSrc->playback(&r);
+    }
+}
+
 void RecordingBench::onDraw(int loops, SkCanvas*) {
     if (fDL) {
         SkLiteRecorder rec;
@@ -61,3 +66,23 @@ void RecordingBench::onDraw(int loops, SkCanvas*) {
         }
     }
 }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "SkPipe.h"
+#include "SkStream.h"
+
+PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) {
+    fName.prepend("pipe_");
+}
+
+void PipingBench::onDraw(int loops, SkCanvas*) {
+    SkDynamicMemoryWStream stream;
+    SkPipeSerializer serializer;
+
+    while (loops --> 0) {
+        fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream));
+        serializer.endWrite();
+        stream.reset();
+    }
+}
index 8e0e12ee966f355ea77ff46b0d5f6b4f6ea0d304..4e34276a887cdfb49344deb4d4f27d284e9ca9e4 100644 (file)
 #include "SkPicture.h"
 #include "SkLiteDL.h"
 
-class RecordingBench : public Benchmark {
+class PictureCentricBench : public Benchmark {
 public:
-    RecordingBench(const char* name, const SkPicture*, bool useBBH, bool lite);
+    PictureCentricBench(const char* name, const SkPicture*);
 
 protected:
     const char* onGetName() override;
     bool isSuitableFor(Backend) override;
-    void onDraw(int loops, SkCanvas*) override;
     SkIPoint onGetSize() override;
 
-private:
+protected:
     sk_sp<const SkPicture> fSrc;
     SkString fName;
+
+    typedef Benchmark INHERITED;
+};
+
+class RecordingBench : public PictureCentricBench {
+public:
+    RecordingBench(const char* name, const SkPicture*, bool useBBH, bool lite);
+
+protected:
+    void onDraw(int loops, SkCanvas*) override;
+
+private:
     sk_sp<SkLiteDL> fDL;
     bool fUseBBH;
 
-    typedef Benchmark INHERITED;
+    typedef PictureCentricBench INHERITED;
+};
+
+class PipingBench : public PictureCentricBench {
+public:
+    PipingBench(const char* name, const SkPicture*);
+
+protected:
+    void onDraw(int loops, SkCanvas*) override;
+
+private:
+    typedef PictureCentricBench INHERITED;
 };
 
 #endif//RecordingBench_DEFINED
index e929a8069f36ec65a7b6deb555ea88672d07e559..6a0fb0445b51f5906870af999ac441baa885b235 100644 (file)
@@ -126,7 +126,7 @@ DEFINE_string(useThermalManager, "0,1,10,1000", "enabled,threshold,sleepTimeMs,T
 DEFINE_string(sourceType, "",
         "Apply usual --match rules to source type: bench, gm, skp, image, etc.");
 DEFINE_string(benchType,  "",
-        "Apply usual --match rules to bench type: micro, recording, playback, skcodec, etc.");
+        "Apply usual --match rules to bench type: micro, recording, piping, playback, skcodec, etc.");
 
 static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
 
@@ -583,6 +583,7 @@ public:
     BenchmarkStream() : fBenches(BenchRegistry::Head())
                       , fGMs(skiagm::GMRegistry::Head())
                       , fCurrentRecording(0)
+                      , fCurrentPiping(0)
                       , fCurrentScale(0)
                       , fCurrentSKP(0)
                       , fCurrentSVG(0)
@@ -727,6 +728,21 @@ public:
             return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh, FLAGS_lite);
         }
 
+        // Add all .skps as PipeBenches.
+        while (fCurrentPiping < fSKPs.count()) {
+            const SkString& path = fSKPs[fCurrentPiping++];
+            sk_sp<SkPicture> pic = ReadPicture(path.c_str());
+            if (!pic) {
+                continue;
+            }
+            SkString name = SkOSPath::Basename(path.c_str());
+            fSourceType = "skp";
+            fBenchType  = "piping";
+            fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic.get()));
+            fSKPOps   = pic->approximateOpCount();
+            return new PipingBench(name.c_str(), pic.get());
+        }
+
         // Then once each for each scale as SKPBenches (playback).
         while (fCurrentScale < fScales.count()) {
             while (fCurrentSKP < fSKPs.count()) {
@@ -1057,6 +1073,7 @@ private:
     const char* fSourceType;  // What we're benching: bench, GM, SKP, ...
     const char* fBenchType;   // How we bench it: micro, recording, playback, ...
     int fCurrentRecording;
+    int fCurrentPiping;
     int fCurrentScale;
     int fCurrentSKP;
     int fCurrentSVG;