2014-04-11 15:53:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-23 19:13:26 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-04-11 15:53:39 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkPicture.h"
|
2014-05-09 15:00:10 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2014-04-11 15:53:39 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-06-16 21:04:32 +00:00
|
|
|
#include "Stats.h"
|
2014-06-20 18:29:20 +00:00
|
|
|
#include "Timer.h"
|
2014-06-16 21:04:32 +00:00
|
|
|
|
2014-04-11 15:53:39 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
2014-06-16 21:04:32 +00:00
|
|
|
DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback.");
|
|
|
|
DEFINE_int32(samples, 10, "Gather this many samples of each picture playback.");
|
2014-04-11 15:53:39 +00:00
|
|
|
DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture.");
|
|
|
|
DEFINE_int32(tile, 1000000000, "Simulated tile size.");
|
2014-04-21 14:59:59 +00:00
|
|
|
DEFINE_string(match, "", "The usual filters on file names of SKPs to bench.");
|
2014-04-28 19:41:17 +00:00
|
|
|
DEFINE_string(timescale, "ms", "Print times in ms, us, or ns");
|
2014-06-16 21:04:32 +00:00
|
|
|
DEFINE_int32(verbose, 0, "0: print min sample; "
|
|
|
|
"1: print min, mean, max and noise indication "
|
|
|
|
"2: print all samples");
|
2014-04-28 19:41:17 +00:00
|
|
|
|
2014-06-16 21:04:32 +00:00
|
|
|
static double timescale() {
|
|
|
|
if (FLAGS_timescale.contains("us")) return 1000;
|
|
|
|
if (FLAGS_timescale.contains("ns")) return 1000000;
|
|
|
|
return 1;
|
2014-04-28 19:41:17 +00:00
|
|
|
}
|
2014-04-11 15:53:39 +00:00
|
|
|
|
2014-06-23 19:13:26 +00:00
|
|
|
static SkPicture* rerecord(const SkPicture& src, bool skr) {
|
2014-05-29 16:52:40 +00:00
|
|
|
SkTileGridFactory::TileGridInfo info;
|
|
|
|
info.fTileInterval.set(FLAGS_tile, FLAGS_tile);
|
|
|
|
info.fMargin.setEmpty();
|
|
|
|
info.fOffset.setZero();
|
|
|
|
SkTileGridFactory factory(info);
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2014-06-23 19:13:26 +00:00
|
|
|
src.draw(skr ? recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(), &factory)
|
|
|
|
: recorder. beginRecording(src.width(), src.height(), &factory));
|
2014-05-29 16:52:40 +00:00
|
|
|
return recorder.endRecording();
|
|
|
|
}
|
2014-04-11 15:53:39 +00:00
|
|
|
|
2014-06-23 19:13:26 +00:00
|
|
|
static void bench(SkPMColor* scratch, const SkPicture& src, const char* name) {
|
|
|
|
SkAutoTUnref<const SkPicture> picture(rerecord(src, FLAGS_skr));
|
2014-04-21 15:03:36 +00:00
|
|
|
|
2014-04-11 19:06:46 +00:00
|
|
|
SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(),
|
|
|
|
src.height(),
|
|
|
|
scratch,
|
|
|
|
src.width() * sizeof(SkPMColor)));
|
2014-04-11 16:13:54 +00:00
|
|
|
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAGS_tile)));
|
2014-04-11 15:53:39 +00:00
|
|
|
|
2014-06-16 21:04:32 +00:00
|
|
|
// Draw once to warm any caches. The first sample otherwise can be very noisy.
|
2014-06-23 19:13:26 +00:00
|
|
|
picture->draw(canvas.get());
|
2014-06-16 21:04:32 +00:00
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
WallTimer timer;
|
|
|
|
const double scale = timescale();
|
2014-06-16 21:04:32 +00:00
|
|
|
SkAutoTMalloc<double> samples(FLAGS_samples);
|
|
|
|
for (int i = 0; i < FLAGS_samples; i++) {
|
|
|
|
// We assume timer overhead (typically, ~30ns) is insignificant
|
|
|
|
// compared to draw runtime (at least ~100us, usually several ms).
|
2014-06-20 18:29:20 +00:00
|
|
|
timer.start();
|
2014-06-23 19:13:26 +00:00
|
|
|
picture->draw(canvas.get());
|
2014-06-16 21:04:32 +00:00
|
|
|
timer.end();
|
2014-06-20 18:29:20 +00:00
|
|
|
samples[i] = timer.fWall * scale;
|
2014-04-11 15:53:39 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 21:04:32 +00:00
|
|
|
Stats stats(samples.get(), FLAGS_samples);
|
|
|
|
if (FLAGS_verbose == 0) {
|
|
|
|
printf("%g\t%s\n", stats.min, name);
|
|
|
|
} else if (FLAGS_verbose == 1) {
|
|
|
|
// Get a rough idea of how noisy the measurements were.
|
|
|
|
const double noisePercent = 100 * sqrt(stats.var) / stats.mean;
|
|
|
|
printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, noisePercent, name);
|
|
|
|
} else if (FLAGS_verbose == 2) {
|
|
|
|
printf("%s", name);
|
|
|
|
for (int i = 0; i < FLAGS_samples; i++) {
|
|
|
|
printf("\t%g", samples[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2014-04-11 15:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
SkAutoGraphics autoGraphics;
|
|
|
|
|
|
|
|
// We share a single scratch bitmap among benches to reduce the profile noise from allocation.
|
|
|
|
static const int kMaxArea = 209825221; // tabl_mozilla is this big.
|
|
|
|
SkAutoTMalloc<SkPMColor> scratch(kMaxArea);
|
|
|
|
|
|
|
|
SkOSFile::Iter it(FLAGS_skps[0], ".skp");
|
|
|
|
SkString filename;
|
|
|
|
bool failed = false;
|
|
|
|
while (it.next(&filename)) {
|
2014-04-21 14:59:59 +00:00
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-04-11 15:53:39 +00:00
|
|
|
const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
|
|
|
|
|
|
|
|
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str()));
|
|
|
|
if (!stream) {
|
|
|
|
SkDebugf("Could not read %s.\n", path.c_str());
|
|
|
|
failed = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-23 19:13:26 +00:00
|
|
|
SkAutoTUnref<const SkPicture> src(SkPicture::CreateFromStream(stream));
|
2014-04-11 15:53:39 +00:00
|
|
|
if (!src) {
|
|
|
|
SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
|
|
|
|
failed = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->width() * src->height() > kMaxArea) {
|
|
|
|
SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).\n",
|
|
|
|
path.c_str(), src->width(), src->height(), kMaxArea);
|
|
|
|
failed = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:52:40 +00:00
|
|
|
bench(scratch.get(), *src, filename.c_str());
|
2014-04-11 15:53:39 +00:00
|
|
|
}
|
|
|
|
return failed ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|