2013-07-19 18:54:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
#include "Timer.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-07-19 18:54:04 +00:00
|
|
|
#include "LazyDecodeBitmap.h"
|
|
|
|
#include "PictureBenchmark.h"
|
|
|
|
#include "PictureRenderer.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2013-07-19 18:54:04 +00:00
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
2013-07-22 19:28:40 +00:00
|
|
|
#include "SkTArray.h"
|
2013-07-19 18:54:04 +00:00
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
typedef sk_tools::PictureRenderer::BBoxHierarchyType BBoxType;
|
|
|
|
static const int kBBoxTypeCount = sk_tools::PictureRenderer::kLast_BBoxHierarchyType + 1;
|
2013-07-19 18:54:04 +00:00
|
|
|
|
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
DEFINE_string2(skps, r, "", "The list of SKPs to benchmark.");
|
2014-03-11 19:12:44 +00:00
|
|
|
DEFINE_string(bb_types, "", "The set of bbox types to test. If empty, all are tested. "
|
2014-08-26 21:07:04 +00:00
|
|
|
"Should be one or more of none, rtree, tilegrid.");
|
2014-03-11 17:27:07 +00:00
|
|
|
DEFINE_int32(record, 100, "Number of times to record each SKP.");
|
|
|
|
DEFINE_int32(playback, 1, "Number of times to playback each SKP.");
|
|
|
|
DEFINE_int32(tilesize, 256, "The size of a tile.");
|
2013-08-20 12:23:18 +00:00
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
struct Measurement {
|
2013-07-19 18:54:04 +00:00
|
|
|
SkString fName;
|
2014-03-11 17:27:07 +00:00
|
|
|
double fRecordAverage[kBBoxTypeCount];
|
|
|
|
double fPlaybackAverage[kBBoxTypeCount];
|
2013-07-19 18:54:04 +00:00
|
|
|
};
|
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
const char* kBBoxHierarchyTypeNames[kBBoxTypeCount] = {
|
|
|
|
"none", // kNone_BBoxHierarchyType
|
|
|
|
"rtree", // kRTree_BBoxHierarchyType
|
2013-07-19 18:54:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static SkPicture* pic_from_path(const char path[]) {
|
|
|
|
SkFILEStream stream(path);
|
|
|
|
if (!stream.isValid()) {
|
|
|
|
SkDebugf("-- Can't open '%s'\n", path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is the sink to which all work ends up going.
|
2014-03-11 17:27:07 +00:00
|
|
|
* @param renderer The renderer to use to perform the work.
|
|
|
|
* To measure rendering, use a TiledPictureRenderer.
|
|
|
|
* To measure recording, use a RecordPictureRenderer.
|
|
|
|
* @param bBoxType The bounding box hierarchy type to use.
|
|
|
|
* @param pic The picture to draw to the renderer.
|
|
|
|
* @param numRepeats The number of times to repeat the draw.
|
|
|
|
* @param timer The timer used to benchmark the work.
|
2013-07-19 18:54:04 +00:00
|
|
|
*/
|
|
|
|
static void do_benchmark_work(sk_tools::PictureRenderer* renderer,
|
2014-10-09 11:59:19 +00:00
|
|
|
BBoxType bBoxType,
|
|
|
|
SkPicture* pic,
|
|
|
|
const int numRepeats,
|
|
|
|
Timer* timer) {
|
2014-03-11 17:27:07 +00:00
|
|
|
renderer->setBBoxHierarchyType(bBoxType);
|
2014-10-09 11:59:19 +00:00
|
|
|
renderer->init(pic, NULL, NULL, NULL, false, false);
|
2013-07-19 18:54:04 +00:00
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
SkDebugf("%s %d times...\n", renderer->getConfigName().c_str(), numRepeats);
|
2013-07-19 18:54:04 +00:00
|
|
|
for (int i = 0; i < numRepeats; ++i) {
|
|
|
|
renderer->setup();
|
2014-03-11 17:27:07 +00:00
|
|
|
// Render once to fill caches
|
2014-03-19 17:26:07 +00:00
|
|
|
renderer->render();
|
2013-07-19 18:54:04 +00:00
|
|
|
// Render again to measure
|
|
|
|
timer->start();
|
2014-03-19 17:26:07 +00:00
|
|
|
renderer->render();
|
2013-07-19 18:54:04 +00:00
|
|
|
timer->end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 20:03:57 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
2014-03-11 17:27:07 +00:00
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
2013-07-19 18:54:04 +00:00
|
|
|
SkAutoGraphics ag;
|
2014-03-11 17:27:07 +00:00
|
|
|
bool includeBBoxType[kBBoxTypeCount];
|
|
|
|
for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
|
2014-03-11 19:12:44 +00:00
|
|
|
includeBBoxType[bBoxType] = (FLAGS_bb_types.count() == 0) ||
|
|
|
|
FLAGS_bb_types.contains(kBBoxHierarchyTypeNames[bBoxType]);
|
2014-03-11 17:27:07 +00:00
|
|
|
}
|
|
|
|
// go through all the pictures
|
|
|
|
SkTArray<Measurement> measurements;
|
|
|
|
for (int index = 0; index < FLAGS_skps.count(); ++index) {
|
|
|
|
const char* path = FLAGS_skps[index];
|
|
|
|
SkPicture* picture = pic_from_path(path);
|
|
|
|
if (NULL == picture) {
|
|
|
|
SkDebugf("Couldn't create picture. Ignoring path: %s\n", path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkDebugf("Benchmarking path: %s\n", path);
|
|
|
|
Measurement& measurement = measurements.push_back();
|
|
|
|
measurement.fName = path;
|
|
|
|
for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
|
|
|
|
if (!includeBBoxType[bBoxType]) { continue; }
|
|
|
|
if (FLAGS_playback > 0) {
|
2014-08-18 14:52:17 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContext::Options grContextOpts;
|
|
|
|
sk_tools::TiledPictureRenderer playbackRenderer(grContextOpts);
|
|
|
|
#else
|
2014-03-11 17:27:07 +00:00
|
|
|
sk_tools::TiledPictureRenderer playbackRenderer;
|
2014-08-18 14:52:17 +00:00
|
|
|
#endif
|
2014-06-20 18:29:20 +00:00
|
|
|
Timer playbackTimer;
|
2014-03-11 17:27:07 +00:00
|
|
|
do_benchmark_work(&playbackRenderer, (BBoxType)bBoxType,
|
|
|
|
picture, FLAGS_playback, &playbackTimer);
|
|
|
|
measurement.fPlaybackAverage[bBoxType] = playbackTimer.fCpu;
|
|
|
|
}
|
|
|
|
if (FLAGS_record > 0) {
|
2014-08-18 14:52:17 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContext::Options grContextOpts;
|
|
|
|
sk_tools::RecordPictureRenderer recordRenderer(grContextOpts);
|
|
|
|
#else
|
2014-03-11 17:27:07 +00:00
|
|
|
sk_tools::RecordPictureRenderer recordRenderer;
|
2014-08-18 14:52:17 +00:00
|
|
|
#endif
|
2014-06-20 18:29:20 +00:00
|
|
|
Timer recordTimer;
|
2014-03-11 17:27:07 +00:00
|
|
|
do_benchmark_work(&recordRenderer, (BBoxType)bBoxType,
|
|
|
|
picture, FLAGS_record, &recordTimer);
|
|
|
|
measurement.fRecordAverage[bBoxType] = recordTimer.fCpu;
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 18:54:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
Measurement globalMeasurement;
|
|
|
|
for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
|
|
|
|
if (!includeBBoxType[bBoxType]) { continue; }
|
|
|
|
globalMeasurement.fPlaybackAverage[bBoxType] = 0;
|
|
|
|
globalMeasurement.fRecordAverage[bBoxType] = 0;
|
|
|
|
for (int index = 0; index < measurements.count(); ++index) {
|
|
|
|
const Measurement& measurement = measurements[index];
|
|
|
|
globalMeasurement.fPlaybackAverage[bBoxType] +=
|
|
|
|
measurement.fPlaybackAverage[bBoxType];
|
|
|
|
globalMeasurement.fRecordAverage[bBoxType] +=
|
|
|
|
measurement.fRecordAverage[bBoxType];
|
|
|
|
}
|
|
|
|
globalMeasurement.fPlaybackAverage[bBoxType] /= measurements.count();
|
|
|
|
globalMeasurement.fRecordAverage[bBoxType] /= measurements.count();
|
2013-07-19 18:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output gnuplot readable histogram data..
|
|
|
|
const char* pbTitle = "bbh_shootout_playback.dat";
|
|
|
|
const char* recTitle = "bbh_shootout_record.dat";
|
|
|
|
SkFILEWStream playbackOut(pbTitle);
|
|
|
|
SkFILEWStream recordOut(recTitle);
|
|
|
|
recordOut.writeText("# ");
|
|
|
|
playbackOut.writeText("# ");
|
2014-03-11 17:27:07 +00:00
|
|
|
SkDebugf("---\n");
|
|
|
|
for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
|
|
|
|
if (!includeBBoxType[bBoxType]) { continue; }
|
2013-07-19 18:54:04 +00:00
|
|
|
SkString out;
|
2014-03-11 17:27:07 +00:00
|
|
|
out.printf("%s ", kBBoxHierarchyTypeNames[bBoxType]);
|
|
|
|
recordOut.writeText(out.c_str());
|
|
|
|
playbackOut.writeText(out.c_str());
|
|
|
|
|
|
|
|
if (FLAGS_record > 0) {
|
|
|
|
SkDebugf("Average %s recording time: %.3fms\n",
|
|
|
|
kBBoxHierarchyTypeNames[bBoxType],
|
|
|
|
globalMeasurement.fRecordAverage[bBoxType]);
|
2013-07-19 18:54:04 +00:00
|
|
|
}
|
2014-03-11 17:27:07 +00:00
|
|
|
if (FLAGS_playback > 0) {
|
|
|
|
SkDebugf("Average %s playback time: %.3fms\n",
|
|
|
|
kBBoxHierarchyTypeNames[bBoxType],
|
|
|
|
globalMeasurement.fPlaybackAverage[bBoxType]);
|
2013-07-19 18:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
recordOut.writeText("\n");
|
|
|
|
playbackOut.writeText("\n");
|
2013-08-20 12:23:18 +00:00
|
|
|
// Write to file, and save recording averages.
|
2014-03-11 17:27:07 +00:00
|
|
|
for (int index = 0; index < measurements.count(); ++index) {
|
|
|
|
const Measurement& measurement = measurements[index];
|
2013-07-19 18:54:04 +00:00
|
|
|
SkString pbLine;
|
|
|
|
SkString recLine;
|
|
|
|
|
2014-03-11 17:27:07 +00:00
|
|
|
pbLine.printf("%d", index);
|
|
|
|
recLine.printf("%d", index);
|
|
|
|
for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
|
|
|
|
if (!includeBBoxType[bBoxType]) { continue; }
|
|
|
|
pbLine.appendf(" %f", measurement.fPlaybackAverage[bBoxType]);
|
|
|
|
recLine.appendf(" %f", measurement.fRecordAverage[bBoxType]);
|
2013-07-19 18:54:04 +00:00
|
|
|
}
|
|
|
|
pbLine.appendf("\n");
|
|
|
|
recLine.appendf("\n");
|
|
|
|
playbackOut.writeText(pbLine.c_str());
|
|
|
|
recordOut.writeText(recLine.c_str());
|
|
|
|
}
|
|
|
|
SkDebugf("\nWrote data to gnuplot-readable files: %s %s\n", pbTitle, recTitle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-19 20:21:05 +00:00
|
|
|
#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
|
2013-07-19 18:54:04 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
return tool_main(argc, argv);
|
|
|
|
}
|
2013-07-19 20:21:05 +00:00
|
|
|
#endif
|