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

Unified Diff: tools/bbh_shootout.cpp

Issue 16948011: Measure tiled rendering. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Code review Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tools.gyp ('k') | tools/lua/bbh_filter.lua » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/bbh_shootout.cpp
diff --git a/tools/bbh_shootout.cpp b/tools/bbh_shootout.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..895e628b7a2df33f5db68ba2cf9811ef2a249744
--- /dev/null
+++ b/tools/bbh_shootout.cpp
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "BenchTimer.h"
+#include "PictureBenchmark.h"
+#include "PictureRenderer.h"
+#include "PictureRenderingFlags.h"
+#include "SkCommandLineFlags.h"
+#include "SkForceLinking.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkGraphics.h"
+#include "TimerData.h"
+
+
+__SK_FORCE_IMAGE_DECODER_LINKING;
+
+static const int kNumRecordings = 10;
+static const int kNumPlaybacks = 1;
+
+static const int gTileDimensions[2] = {256, 256};
+
+enum BenchmarkType {
+ kNormal_BenchmarkType = 0,
+ kRTree_BenchmarkType,
+};
+
+// Defined in PictureRenderingFlags.cpp
+extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
+
+static SkPicture pic_from_path(const char path[], bool* success) {
+ SkFILEStream stream(path);
+ *success = false;
+ if (!stream.isValid()) {
+ SkDebugf("-- Can't open '%s'\n", path);
+ }
+ SkPicture pic(&stream, success, &lazy_decode_bitmap);
+ if (!success) {
reed1 2013/07/08 12:07:03 Is there a Factory method to create a picture from
sglez 2013/07/08 22:00:34 There is SkPicture::CreateFromStream... it's newer
+ SkDebugf("Could not create SkPicture: %s\n", path);
+ }
+ return pic;
+}
+
+/**
+ * This function is the sink to which all work ends up going.
+ * Renders the picture into the renderer. It may or may not use an RTree.
+ * The renderer is chosen upstream. If we want to measure recording, we will
+ * use a RecordPictureRenderer. If we want to measure rendering, we eill use a
+ * TiledPictureRenderer.
+ */
+static void do_benchmark_work(sk_tools::PictureRenderer* renderer,
+ int benchmarkType, const SkString *path, SkPicture* pic,
+ const int numRepeats, const char *msg) {
+ SkASSERT(NULL != pic);
+
+ SkString msgPrefix;
+
+ switch (benchmarkType){
+ case kNormal_BenchmarkType:
+ msgPrefix.printf("Normal");
+ renderer->setBBoxHierarchyType(sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
+ break;
+ case kRTree_BenchmarkType:
+ msgPrefix.printf("RTree");
+ renderer->setBBoxHierarchyType(sk_tools::PictureRenderer::kRTree_BBoxHierarchyType);
+ break;
+ }
+
+ renderer->init(pic);
+
+ SkDebugf("%s %s %s %d times...\n", msgPrefix.c_str(), msg, path->c_str(), numRepeats);
+ for (int i = 0; i < numRepeats; ++i) {
+ renderer->setup();
+ bool result = renderer->render(path);
+ if(!result) {
+ SkDebugf("Error recording.\n");
+ }
+ }
+ renderer->end();
+}
+
+/**
+ * Call do_benchmark_work with a tiled renderer using the default tile dimensions.
+ */
+static void benchmark_playback(int benchmarkType, const SkString* path, SkPicture* pic) {
+ sk_tools::TiledPictureRenderer renderer;
+
+ renderer.setTileWidth(gTileDimensions[0]);
+ renderer.setTileHeight(gTileDimensions[1]);
+
+ do_benchmark_work(&renderer, benchmarkType, path, pic, kNumPlaybacks, "tiled playback");
+}
+
+/**
+ * Call do_benchmark_work with a RecordPictureRenderer.
+ */
+static void benchmark_recording(int benchmarkType, const SkString* path, SkPicture* pic) {
+ sk_tools::RecordPictureRenderer renderer;
+
+ do_benchmark_work(&renderer, benchmarkType, path, pic, kNumRecordings, "recording");
+}
+
+/**
+ * Returns a SkScalar representing CPU time for a TimerData.
+ * As a side effect, it spits the timer result to stdout.
+ * Will return -1.0 on error.
+ */
+static SkScalar get_data_result(TimerData &timerData, const char *configName) {
+ const SkString timerResult = timerData.getResult(
+ /*logPerIter = */ false,
+ /*printMin = */ false,
+ /*repeatDraw = */ 1,
+ /*configName = */ configName,
+ /*showWallTime = */ false,
+ /*showTruncatedWallTime = */ false,
+ /*showCpuTime = */ true,
+ /*showTruncatedCpuTime = */ false,
+ /*showGpuTime = */ false);
+
+ const char findStr[] = "= ";
+ int pos = timerResult.find(findStr);
+ if (-1 == pos) {
+ SkDebugf("Unexpected output from TimerData::getResult(...). Unable to parse.");
+ return -1.0;
+ }
+ SkDebugf("%s\n", timerResult.c_str());
+
+ SkScalar cpuTime = atof(timerResult.c_str() + pos + sizeof(findStr) - 1);
+ if (cpuTime == SkIntToScalar(0)) { // atof returns 0.0 on error.
+ SkDebugf("Unable to read value from timer result.\n");
+ return -1.0;
+ }
+ return cpuTime;
+}
+
+static const SkString perIterTimeFormat("%f");
+static const SkString normalTimeFormat("%f");
+
+/**
+ * Takes argc,argv along with one of the benchmark functions defined above.
+ * Will loop along all skp files and perform a measurment; then it will return
+ * that measurement.
+ */
+TimerData benchmark_loop(
+ int argc,
+ char **argv,
+ void (*func)(int, const SkString*, SkPicture*),
+ int benchmarkType) {
+ TimerData timerData(perIterTimeFormat, normalTimeFormat);
+ for (int index = 1; index < argc; ++index) {
+ BenchTimer timer;
+ SkString path(argv[index]);
+ timer.start();
+ bool success = false;
+ SkPicture pic = pic_from_path(argv[index], &success);
+ if (success) {
+ func(benchmarkType, &path, &pic);
+ }
+ timer.end();
+ timerData.appendTimes(&timer, index == argc - 1);
+ }
+ return timerData;
caryclark 2013/07/08 13:04:57 instead of returning the timerData, why not return
sglez 2013/07/08 22:00:34 Moved the body of get_data_result into this functi
+}
+
+static int tool_main(int argc, char** argv) {
+ SkAutoGraphics ag;
+ SkString usage;
+ usage.printf("Usage: filename [filename]*\n");
+
+ if (argc < 2) {
+ SkDebugf("%s\n", usage.c_str());
+ }
+
+ TimerData normalRecordData =
reed1 2013/07/08 12:07:03 Can this section be organized w/ tables of static
sglez 2013/07/08 22:00:34 Done. Thanks.
+ benchmark_loop(argc, argv, benchmark_recording, kNormal_BenchmarkType);
+ TimerData rtreeRecordData =
+ benchmark_loop(argc, argv, benchmark_recording, kRTree_BenchmarkType);
+ TimerData normalPlaybackData =
+ benchmark_loop(argc, argv, benchmark_playback, kNormal_BenchmarkType);
+ TimerData rtreePlaybackData =
+ benchmark_loop(argc, argv, benchmark_playback, kRTree_BenchmarkType);
+
+ SkScalar normalRecordResult = get_data_result(normalRecordData, "normal_record");
+ SkScalar rtreeRecordResult = get_data_result(rtreeRecordData, "rtree_record");
+ SkScalar normalPlaybackResult = get_data_result(normalPlaybackData, "normal_playbak");
+ SkScalar rtreePlaybackResult = get_data_result(rtreePlaybackData, "rtree_playback");
+ SkASSERT(normalRecordResult != -1.0);
+ SkASSERT(rtreeRecordResult != -1.0);
+ SkASSERT(normalPlaybackResult != -1.0);
+ SkASSERT(rtreePlaybackResult != -1.0);
+
+ SkASSERT(normalRecordResult != 0 && normalPlaybackResult != 0);
+ SkDebugf("Recording: Relative difference: %.4f\n", rtreeRecordResult / normalRecordResult);
+ SkDebugf("Playback: Relative difference: %.4f\n", rtreePlaybackResult / normalPlaybackResult);
+
+ SkScalar times =
+ (kNumPlaybacks * (normalRecordResult - rtreeRecordResult)) /
+ (kNumRecordings * (rtreePlaybackResult - normalPlaybackResult));
+
+ SkDebugf("Number of playback repetitions for RTree to be worth it: %d (ratio: %.4f)\n",
+ SkScalarCeilToInt(times), times);
+
+ return 0;
+}
+
+int main(int argc, char** argv) {
+ return tool_main(argc, argv);
+}
+
« no previous file with comments | « gyp/tools.gyp ('k') | tools/lua/bbh_filter.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698