8c1a4f80d9
Here's a demo. The new code is still looking 2-3x faster. ~/skia (bench) $ r nanobench --match nytimes --config nonrendering --ms 2000 curr/maxrss loops min median mean max stddev samples config bench 19/26 MB 2 146µs 147µs 151µs 422µs 9% 6615 nonrendering desk_nytimes.skp 20/26 MB 4 46.6µs 46.9µs 48.2µs 204µs 10% 10370 nonrendering keymobi_nytimes_com_.skp ~/skia (bench) $ r nanobench --match nytimes --config nonrendering --ms 2000 --lite curr/maxrss loops min median mean max stddev samples config bench 19/26 MB 2 73.8µs 76.9µs 78.7µs 417µs 14% 12702 nonrendering desk_nytimes.skp 20/26 MB 5 18.5µs 18.7µs 19.3µs 137µs 12% 20713 nonrendering keymobi_nytimes_com_.skp Here's a quick performance diff, where <1x means --lite is faster: top25desk_wikipedia__1_tab_.skp 285us -> 364us 1.27x top25desk_games_yahoo_com.skp 302us -> 329us 1.09x tabl_mozilla.skp 241us -> 260us 1.08x desk_chalkboard.skp 321us -> 313us 0.98x tabl_gamedeksiam.skp 383us -> 367us 0.96x top25desk_pinterest.skp 375us -> 281us 0.75x keymobi_reddit_com_r_programmin.skp 258us -> 142us 0.55x desk_nytimes.skp 149us -> 77.9us 0.52x keymobi_worldjournal_com_.skp 201us -> 104us 0.52x top25desk_blogger.skp 112us -> 55us 0.49x top25desk_sports_yahoo_com_.skp 186us -> 89.6us 0.48x desk_googlespreadsheet.skp 206us -> 97.5us 0.47x top25desk_google_com_search_q_c.skp 192us -> 89.8us 0.47x keymobi_wikipedia__1_tab_.skp 170us -> 79.3us 0.47x keymobi_wikipedia__1_tab____del.skp 170us -> 78.2us 0.46x desk_unicodetable.skp 6.25ms -> 2.87ms 0.46x desk_carsvg.skp 138us -> 63.3us 0.46x top25desk_answers_yahoo_com.skp 133us -> 60.7us 0.46x top25desk_espn.skp 108us -> 49.2us 0.45x top25desk_plus_google_com_11003.skp 361us -> 162us 0.45x desk_espn.skp 99.4us -> 44.5us 0.45x tabl_worldjournal.skp 103us -> 45.6us 0.44x desk_ugamsolutions.skp 56.2us -> 24.8us 0.44x top25desk_facebook.skp 82.7us -> 35.7us 0.43x keymobi_cuteoverload_com.skp 213us -> 91.9us 0.43x top25desk_linkedin.skp 61.3us -> 26.3us 0.43x top25desk_news_yahoo_com.skp 153us -> 65.6us 0.43x desk_gmailthread.skp 64.9us -> 27.8us 0.43x keymobi_androidpolice_com_2012_.skp 167us -> 71.3us 0.43x top25desk_amazon_com.skp 77.5us -> 33.1us 0.43x desk_wowwiki.skp 129us -> 54.1us 0.42x top25desk_weather_com.skp 113us -> 47.1us 0.42x keymobi_facebook_com_barackobam.skp 95.2us -> 39.6us 0.42x keymobi_shop_mobileweb_ebay_com.skp 31.5us -> 13.1us 0.42x keymobi_amazon_com_gp_aw_s_ref_.skp 46.1us -> 18.9us 0.41x keymobi_mobile_news_sandbox_goo.skp 90.7us -> 37us 0.41x top25desk_google_com__hl_en_q_b.skp 52.4us -> 21.4us 0.41x keymobi_answers_yahoo_com_quest.skp 96.5us -> 39.3us 0.41x tabl_pravda.skp 126us -> 51.2us 0.41x keymobi_nytimes_com_.skp 46.9us -> 19us 0.4x keymobi_ftw_usatoday_com_2014_0.skp 119us -> 48.2us 0.4x top25desk_youtube_com.skp 162us -> 65.3us 0.4x keymobi_news_yahoo_com.skp 58.1us -> 23.2us 0.4x keymobi_boingboing_net.skp 58.8us -> 23.4us 0.4x keymobi_techcrunch_com.skp 26.3us -> 10.4us 0.39x keymobi_plus_google_com_app_bas.skp 26.9us -> 10.4us 0.38x keymobi_google_co_uk_search_hl_.skp 35.1us -> 13.4us 0.38x keymobi_pinterest.skp 26.2us -> 10us 0.38x keymobi_deviantart_com_.skp 67.1us -> 25.4us 0.38x tabl_gmail.skp 10.3us -> 3.86us 0.38x top25desk_ebay_com.skp 65.6us -> 24.5us 0.37x keymobi_m_youtube_com_watch_v_9.skp 57.9us -> 21.6us 0.37x top25desk_wordpress.skp 138us -> 51.3us 0.37x keymobi_gsp_ro.skp 17us -> 6.34us 0.37x top25desk_techcrunch_com.skp 93.6us -> 34.7us 0.37x keymobi_cnn_com_2012_10_03_poli.skp 232us -> 85.5us 0.37x keymobi_cnn_com.skp 30.5us -> 11.1us 0.37x keymobi_baidu_com_s_wd_barack_o.skp 39.3us -> 14.3us 0.36x keymobi_online_wsj_com_home_pag.skp 50.3us -> 18.3us 0.36x keymobi_digg_com.skp 54.8us -> 19.5us 0.36x keymobi_wowwiki_com_world_of_wa.skp 39.4us -> 14us 0.36x keymobi_theverge_com_2012_10_28.skp 102us -> 36.4us 0.36x tabl_digg.skp 105us -> 37.4us 0.36x top25desk_google_com_calendar_.skp 67.2us -> 23.7us 0.35x keymobi_wordpress.skp 65.3us -> 23us 0.35x desk_css3gradients.skp 56.4us -> 19.8us 0.35x top25desk_mail_google_com_mail_.skp 119us -> 41.6us 0.35x desk_googlehome.skp 8.2us -> 2.85us 0.35x top25desk_docs___1_open_documen.skp 23.8us -> 8.22us 0.35x keymobi_mlb_com_.skp 18.6us -> 6.3us 0.34x keymobi_slashdot_org_.skp 33us -> 11us 0.33x desk_tiger8svg.skp 96.2us -> 32us 0.33x top25desk_twitter.skp 124us -> 40.7us 0.33x keymobi_bing_com_search_q_sloth.skp 17.3us -> 5.55us 0.32x keymobi_linkedin.skp 6.78us -> 1.99us 0.29x top25desk_booking_com.skp 291us -> 83.2us 0.29x keymobi_blogger.skp 19.3us -> 5.47us 0.28x keymobi_sfgate_com_.skp 83.3us -> 23us 0.28x desk_jsfiddlebigcar.skp 10.8us -> 2.95us 0.27x keymobi_theverge_com.skp 22us -> 5.27us 0.24x desk_mapsvg.skp 1.15us -> 216ns 0.19x keymobi_iphone_capitolvolkswage.skp 121us -> 22.3us 0.18x desk_wikipedia.skp 1.36us -> 244ns 0.18x desk_pokemonwiki.skp 1.35us -> 243ns 0.18x desk_samoasvg.skp 1.39us -> 241ns 0.17x desk_tigersvg.skp 1.41us -> 241ns 0.17x keymobi_booking_com_searchresul.skp 129us -> 19.7us 0.15x Some spot testing makes it look like everything that's not a giant speedup can be made so by tweaking my (arbitrarily set) maximum size for the free list. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2220273002 Review-Url: https://codereview.chromium.org/2220273002
1313 lines
48 KiB
C++
1313 lines
48 KiB
C++
/*
|
|
* Copyright 2014 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "nanobench.h"
|
|
|
|
#include "AndroidCodecBench.h"
|
|
#include "Benchmark.h"
|
|
#include "BitmapRegionDecoderBench.h"
|
|
#include "CodecBench.h"
|
|
#include "CodecBenchPriv.h"
|
|
#include "ColorCodecBench.h"
|
|
#include "CrashHandler.h"
|
|
#include "GMBench.h"
|
|
#include "ProcStats.h"
|
|
#include "ResultsWriter.h"
|
|
#include "RecordingBench.h"
|
|
#include "SKPAnimationBench.h"
|
|
#include "SKPBench.h"
|
|
#include "Stats.h"
|
|
|
|
#include "SkAndroidCodec.h"
|
|
#include "SkBitmapRegionDecoder.h"
|
|
#include "SkBBoxHierarchy.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkCodec.h"
|
|
#include "SkCommonFlags.h"
|
|
#include "SkCommonFlagsConfig.h"
|
|
#include "SkData.h"
|
|
#include "SkForceLinking.h"
|
|
#include "SkGraphics.h"
|
|
#include "SkLeanWindows.h"
|
|
#include "SkOSFile.h"
|
|
#include "SkPictureRecorder.h"
|
|
#include "SkPictureUtils.h"
|
|
#include "SkString.h"
|
|
#include "SkSurface.h"
|
|
#include "SkTaskGroup.h"
|
|
#include "SkThreadUtils.h"
|
|
#include "ThermalManager.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifndef SK_BUILD_FOR_WIN32
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
#include "nanobenchAndroid.h"
|
|
#endif
|
|
|
|
#if SK_SUPPORT_GPU
|
|
#include "gl/GrGLDefines.h"
|
|
#include "GrCaps.h"
|
|
#include "GrContextFactory.h"
|
|
#include "gl/GrGLUtil.h"
|
|
using sk_gpu_test::GrContextFactory;
|
|
using sk_gpu_test::TestContext;
|
|
SkAutoTDelete<GrContextFactory> gGrFactory;
|
|
#endif
|
|
|
|
struct GrContextOptions;
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
static const int kAutoTuneLoops = 0;
|
|
|
|
static const int kDefaultLoops =
|
|
#ifdef SK_DEBUG
|
|
1;
|
|
#else
|
|
kAutoTuneLoops;
|
|
#endif
|
|
|
|
static SkString loops_help_txt() {
|
|
SkString help;
|
|
help.printf("Number of times to run each bench. Set this to %d to auto-"
|
|
"tune for each bench. Timings are only reported when auto-tuning.",
|
|
kAutoTuneLoops);
|
|
return help;
|
|
}
|
|
|
|
static SkString to_string(int n) {
|
|
SkString str;
|
|
str.appendS32(n);
|
|
return str;
|
|
}
|
|
|
|
DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str());
|
|
|
|
DEFINE_int32(samples, 10, "Number of samples to measure for each bench.");
|
|
DEFINE_int32(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples.");
|
|
DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead.");
|
|
DEFINE_double(overheadGoal, 0.0001,
|
|
"Loop until timer overhead is at most this fraction of our measurments.");
|
|
DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
|
|
DEFINE_int32(gpuFrameLag, 5, "If unknown, estimated maximum number of frames GPU allows to lag.");
|
|
|
|
DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
|
|
DEFINE_int32(maxCalibrationAttempts, 3,
|
|
"Try up to this many times to guess loops for a bench, or skip the bench.");
|
|
DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this.");
|
|
DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
|
|
DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
|
|
DEFINE_string(zoom, "1.0,0", "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
|
|
"function that ping-pongs between 1.0 and zoomMax.");
|
|
DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
|
|
DEFINE_bool(lite, false, "Use SkLiteRecorder in recording benchmarks?");
|
|
DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
|
|
DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
|
|
DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
|
|
DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
|
|
DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
|
|
DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
|
|
DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
|
|
DEFINE_string(useThermalManager, "0,1,10,1000", "enabled,threshold,sleepTimeMs,TimeoutMs for "
|
|
"thermalManager\n");
|
|
|
|
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.");
|
|
|
|
static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
|
|
|
|
static SkString humanize(double ms) {
|
|
if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
|
|
return HumanizeMs(ms);
|
|
}
|
|
#define HUMANIZE(ms) humanize(ms).c_str()
|
|
|
|
bool Target::init(SkImageInfo info, Benchmark* bench) {
|
|
if (Benchmark::kRaster_Backend == config.backend) {
|
|
this->surface = SkSurface::MakeRaster(info);
|
|
if (!this->surface) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
bool Target::capturePixels(SkBitmap* bmp) {
|
|
SkCanvas* canvas = this->getCanvas();
|
|
if (!canvas) {
|
|
return false;
|
|
}
|
|
bmp->setInfo(canvas->imageInfo());
|
|
if (!canvas->readPixels(bmp, 0, 0)) {
|
|
SkDebugf("Can't read canvas pixels.\n");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
struct GPUTarget : public Target {
|
|
explicit GPUTarget(const Config& c) : Target(c), context(nullptr) { }
|
|
TestContext* context;
|
|
|
|
void setup() override {
|
|
this->context->makeCurrent();
|
|
// Make sure we're done with whatever came before.
|
|
this->context->finish();
|
|
}
|
|
void endTiming() override {
|
|
if (this->context) {
|
|
this->context->waitOnSyncOrSwap();
|
|
}
|
|
}
|
|
void fence() override {
|
|
this->context->finish();
|
|
}
|
|
|
|
bool needsFrameTiming(int* maxFrameLag) const override {
|
|
if (!this->context->getMaxGpuFrameLag(maxFrameLag)) {
|
|
// Frame lag is unknown.
|
|
*maxFrameLag = FLAGS_gpuFrameLag;
|
|
}
|
|
return true;
|
|
}
|
|
bool init(SkImageInfo info, Benchmark* bench) override {
|
|
uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
|
|
0;
|
|
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
|
|
this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config.ctxType,
|
|
this->config.ctxOptions),
|
|
SkBudgeted::kNo, info,
|
|
this->config.samples, &props);
|
|
this->context = gGrFactory->getContextInfo(this->config.ctxType,
|
|
this->config.ctxOptions).testContext();
|
|
if (!this->surface.get()) {
|
|
return false;
|
|
}
|
|
if (!this->context->fenceSyncSupport()) {
|
|
SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
|
|
"Timings might not be accurate.\n", this->config.name.c_str());
|
|
}
|
|
return true;
|
|
}
|
|
void fillOptions(ResultsWriter* log) override {
|
|
const GrGLubyte* version;
|
|
if (this->context->backend() == kOpenGL_GrBackend) {
|
|
const GrGLInterface* gl =
|
|
reinterpret_cast<const GrGLInterface*>(this->context->backendContext());
|
|
GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION));
|
|
log->configOption("GL_VERSION", (const char*)(version));
|
|
|
|
GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER));
|
|
log->configOption("GL_RENDERER", (const char*) version);
|
|
|
|
GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR));
|
|
log->configOption("GL_VENDOR", (const char*) version);
|
|
|
|
GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
|
|
log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif
|
|
|
|
static double time(int loops, Benchmark* bench, Target* target) {
|
|
SkCanvas* canvas = target->getCanvas();
|
|
if (canvas) {
|
|
canvas->clear(SK_ColorWHITE);
|
|
}
|
|
bench->preDraw(canvas);
|
|
double start = now_ms();
|
|
canvas = target->beginTiming(canvas);
|
|
bench->draw(loops, canvas);
|
|
if (canvas) {
|
|
canvas->flush();
|
|
}
|
|
target->endTiming();
|
|
double elapsed = now_ms() - start;
|
|
bench->postDraw(canvas);
|
|
return elapsed;
|
|
}
|
|
|
|
static double estimate_timer_overhead() {
|
|
double overhead = 0;
|
|
for (int i = 0; i < FLAGS_overheadLoops; i++) {
|
|
double start = now_ms();
|
|
overhead += now_ms() - start;
|
|
}
|
|
return overhead / FLAGS_overheadLoops;
|
|
}
|
|
|
|
static int detect_forever_loops(int loops) {
|
|
// look for a magic run-forever value
|
|
if (loops < 0) {
|
|
loops = SK_MaxS32;
|
|
}
|
|
return loops;
|
|
}
|
|
|
|
static int clamp_loops(int loops) {
|
|
if (loops < 1) {
|
|
SkDebugf("ERROR: clamping loops from %d to 1. "
|
|
"There's probably something wrong with the bench.\n", loops);
|
|
return 1;
|
|
}
|
|
if (loops > FLAGS_maxLoops) {
|
|
SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
|
|
return FLAGS_maxLoops;
|
|
}
|
|
return loops;
|
|
}
|
|
|
|
static bool write_canvas_png(Target* target, const SkString& filename) {
|
|
|
|
if (filename.isEmpty()) {
|
|
return false;
|
|
}
|
|
if (target->getCanvas() &&
|
|
kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
|
|
return false;
|
|
}
|
|
|
|
SkBitmap bmp;
|
|
|
|
if (!target->capturePixels(&bmp)) {
|
|
return false;
|
|
}
|
|
|
|
SkString dir = SkOSPath::Dirname(filename.c_str());
|
|
if (!sk_mkdir(dir.c_str())) {
|
|
SkDebugf("Can't make dir %s.\n", dir.c_str());
|
|
return false;
|
|
}
|
|
SkFILEWStream stream(filename.c_str());
|
|
if (!stream.isValid()) {
|
|
SkDebugf("Can't write %s.\n", filename.c_str());
|
|
return false;
|
|
}
|
|
if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
|
|
SkDebugf("Can't encode a PNG.\n");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static int kFailedLoops = -2;
|
|
static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
|
|
// First figure out approximately how many loops of bench it takes to make overhead negligible.
|
|
double bench_plus_overhead = 0.0;
|
|
int round = 0;
|
|
int loops = bench->calculateLoops(FLAGS_loops);
|
|
if (kAutoTuneLoops == loops) {
|
|
while (bench_plus_overhead < overhead) {
|
|
if (round++ == FLAGS_maxCalibrationAttempts) {
|
|
SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
|
|
bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
|
|
return kFailedLoops;
|
|
}
|
|
bench_plus_overhead = time(1, bench, target);
|
|
}
|
|
}
|
|
|
|
// Later we'll just start and stop the timer once but loop N times.
|
|
// We'll pick N to make timer overhead negligible:
|
|
//
|
|
// overhead
|
|
// ------------------------- < FLAGS_overheadGoal
|
|
// overhead + N * Bench Time
|
|
//
|
|
// where bench_plus_overhead ≈ overhead + Bench Time.
|
|
//
|
|
// Doing some math, we get:
|
|
//
|
|
// (overhead / FLAGS_overheadGoal) - overhead
|
|
// ------------------------------------------ < N
|
|
// bench_plus_overhead - overhead)
|
|
//
|
|
// Luckily, this also works well in practice. :)
|
|
if (kAutoTuneLoops == loops) {
|
|
const double numer = overhead / FLAGS_overheadGoal - overhead;
|
|
const double denom = bench_plus_overhead - overhead;
|
|
loops = (int)ceil(numer / denom);
|
|
loops = clamp_loops(loops);
|
|
} else {
|
|
loops = detect_forever_loops(loops);
|
|
}
|
|
|
|
return loops;
|
|
}
|
|
|
|
static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
|
|
// First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
|
|
int loops = bench->calculateLoops(FLAGS_loops);
|
|
if (kAutoTuneLoops == loops) {
|
|
loops = 1;
|
|
double elapsed = 0;
|
|
do {
|
|
if (1<<30 == loops) {
|
|
// We're about to wrap. Something's wrong with the bench.
|
|
loops = 0;
|
|
break;
|
|
}
|
|
loops *= 2;
|
|
// If the GPU lets frames lag at all, we need to make sure we're timing
|
|
// _this_ round, not still timing last round.
|
|
for (int i = 0; i < maxGpuFrameLag; i++) {
|
|
elapsed = time(loops, bench, target);
|
|
}
|
|
} while (elapsed < FLAGS_gpuMs);
|
|
|
|
// We've overshot at least a little. Scale back linearly.
|
|
loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
|
|
loops = clamp_loops(loops);
|
|
|
|
// Make sure we're not still timing our calibration.
|
|
target->fence();
|
|
} else {
|
|
loops = detect_forever_loops(loops);
|
|
}
|
|
|
|
// Pretty much the same deal as the calibration: do some warmup to make
|
|
// sure we're timing steady-state pipelined frames.
|
|
for (int i = 0; i < maxGpuFrameLag - 1; i++) {
|
|
time(loops, bench, target);
|
|
}
|
|
|
|
return loops;
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
#define kBogusContextType GrContextFactory::kNativeGL_ContextType
|
|
#define kBogusContextOptions GrContextFactory::kNone_ContextOptions
|
|
#else
|
|
#define kBogusContextType 0
|
|
#define kBogusContextOptions 0
|
|
#endif
|
|
|
|
static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
if (const auto* gpuConfig = config->asConfigGpu()) {
|
|
if (!FLAGS_gpu)
|
|
return;
|
|
|
|
auto ctxOptions = GrContextFactory::kNone_ContextOptions;
|
|
if (gpuConfig->getUseNVPR()) {
|
|
ctxOptions = static_cast<GrContextFactory::ContextOptions>(
|
|
ctxOptions | GrContextFactory::kEnableNVPR_ContextOptions);
|
|
}
|
|
if (gpuConfig->getUseInstanced()) {
|
|
ctxOptions = static_cast<GrContextFactory::ContextOptions>(
|
|
ctxOptions | GrContextFactory::kUseInstanced_ContextOptions);
|
|
}
|
|
if (SkColorAndColorSpaceAreGammaCorrect(gpuConfig->getColorType(),
|
|
gpuConfig->getColorSpace())) {
|
|
ctxOptions = static_cast<GrContextFactory::ContextOptions>(
|
|
ctxOptions | GrContextFactory::kRequireSRGBSupport_ContextOptions);
|
|
}
|
|
const auto ctxType = gpuConfig->getContextType();
|
|
const auto sampleCount = gpuConfig->getSamples();
|
|
|
|
if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) {
|
|
const auto maxSampleCount = ctx->caps()->maxSampleCount();
|
|
if (sampleCount > ctx->caps()->maxSampleCount()) {
|
|
SkDebugf("Configuration sample count %d exceeds maximum %d.\n",
|
|
sampleCount, maxSampleCount);
|
|
return;
|
|
}
|
|
} else {
|
|
SkDebugf("No context was available matching config type and options.\n");
|
|
return;
|
|
}
|
|
|
|
Config target = {
|
|
gpuConfig->getTag(),
|
|
Benchmark::kGPU_Backend,
|
|
gpuConfig->getColorType(),
|
|
kPremul_SkAlphaType,
|
|
sk_ref_sp(gpuConfig->getColorSpace()),
|
|
sampleCount,
|
|
ctxType,
|
|
ctxOptions,
|
|
gpuConfig->getUseDIText()
|
|
};
|
|
|
|
configs->push_back(target);
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
#define CPU_CONFIG(name, backend, color, alpha, colorSpace) \
|
|
if (config->getTag().equals(#name)) { \
|
|
Config config = { \
|
|
SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
|
|
0, kBogusContextType, kBogusContextOptions, false \
|
|
}; \
|
|
configs->push_back(config); \
|
|
return; \
|
|
}
|
|
|
|
if (FLAGS_cpu) {
|
|
CPU_CONFIG(nonrendering, kNonRendering_Backend,
|
|
kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr)
|
|
|
|
CPU_CONFIG(8888, kRaster_Backend,
|
|
kN32_SkColorType, kPremul_SkAlphaType, nullptr)
|
|
CPU_CONFIG(565, kRaster_Backend,
|
|
kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
|
|
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
|
|
CPU_CONFIG(srgb, kRaster_Backend,
|
|
kN32_SkColorType, kPremul_SkAlphaType, srgbColorSpace)
|
|
CPU_CONFIG(f16, kRaster_Backend,
|
|
kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbColorSpace)
|
|
}
|
|
|
|
#undef CPU_CONFIG
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
if (config->getTag().equals("hwui")) {
|
|
Config config = { SkString("hwui"), Benchmark::kHWUI_Backend,
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
|
|
0, kBogusContextType, kBogusContextOptions, false };
|
|
configs->push_back(config);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// Append all configs that are enabled and supported.
|
|
void create_configs(SkTArray<Config>* configs) {
|
|
SkCommandLineConfigArray array;
|
|
ParseConfigs(FLAGS_config, &array);
|
|
for (int i = 0; i < array.count(); ++i) {
|
|
create_config(array[i], configs);
|
|
}
|
|
}
|
|
|
|
// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
|
|
static Target* is_enabled(Benchmark* bench, const Config& config) {
|
|
if (!bench->isSuitableFor(config.backend)) {
|
|
return nullptr;
|
|
}
|
|
|
|
SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
|
|
config.color, config.alpha, config.colorSpace);
|
|
|
|
Target* target = nullptr;
|
|
|
|
switch (config.backend) {
|
|
#if SK_SUPPORT_GPU
|
|
case Benchmark::kGPU_Backend:
|
|
target = new GPUTarget(config);
|
|
break;
|
|
#endif
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
case Benchmark::kHWUI_Backend:
|
|
target = new HWUITarget(config, bench);
|
|
break;
|
|
#endif
|
|
default:
|
|
target = new Target(config);
|
|
break;
|
|
}
|
|
|
|
if (!target->init(info, bench)) {
|
|
delete target;
|
|
return nullptr;
|
|
}
|
|
return target;
|
|
}
|
|
|
|
static bool valid_brd_bench(SkData* encoded, SkColorType colorType, uint32_t sampleSize,
|
|
uint32_t minOutputSize, int* width, int* height) {
|
|
SkAutoTDelete<SkBitmapRegionDecoder> brd(
|
|
SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
|
|
if (nullptr == brd.get()) {
|
|
// This is indicates that subset decoding is not supported for a particular image format.
|
|
return false;
|
|
}
|
|
|
|
if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
|
|
(uint32_t) brd->height()) {
|
|
// This indicates that the image is not large enough to decode a
|
|
// minOutputSize x minOutputSize subset at the given sampleSize.
|
|
return false;
|
|
}
|
|
|
|
// Set the image width and height. The calling code will use this to choose subsets to decode.
|
|
*width = brd->width();
|
|
*height = brd->height();
|
|
return true;
|
|
}
|
|
|
|
static void cleanup_run(Target* target) {
|
|
delete target;
|
|
#if SK_SUPPORT_GPU
|
|
if (FLAGS_abandonGpuContext) {
|
|
gGrFactory->abandonContexts();
|
|
}
|
|
if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
|
|
gGrFactory->destroyContexts();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
class BenchmarkStream {
|
|
public:
|
|
BenchmarkStream() : fBenches(BenchRegistry::Head())
|
|
, fGMs(skiagm::GMRegistry::Head())
|
|
, fCurrentRecording(0)
|
|
, fCurrentScale(0)
|
|
, fCurrentSKP(0)
|
|
, fCurrentUseMPD(0)
|
|
, fCurrentCodec(0)
|
|
, fCurrentAndroidCodec(0)
|
|
, fCurrentBRDImage(0)
|
|
, fCurrentColorImage(0)
|
|
, fCurrentColorType(0)
|
|
, fCurrentAlphaType(0)
|
|
, fCurrentSubsetType(0)
|
|
, fCurrentSampleSize(0)
|
|
, fCurrentAnimSKP(0) {
|
|
for (int i = 0; i < FLAGS_skps.count(); i++) {
|
|
if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
|
|
fSKPs.push_back() = FLAGS_skps[i];
|
|
} else {
|
|
SkOSFile::Iter it(FLAGS_skps[i], ".skp");
|
|
SkString path;
|
|
while (it.next(&path)) {
|
|
fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
|
|
&fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
|
|
SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
|
|
exit(1);
|
|
}
|
|
|
|
for (int i = 0; i < FLAGS_scales.count(); i++) {
|
|
if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
|
|
SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
|
|
SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
|
|
exit(1);
|
|
}
|
|
|
|
if (FLAGS_mpd) {
|
|
fUseMPDs.push_back() = true;
|
|
}
|
|
fUseMPDs.push_back() = false;
|
|
|
|
// Prepare the images for decoding
|
|
if (!CollectImages(FLAGS_images, &fImages)) {
|
|
exit(1);
|
|
}
|
|
if (!CollectImages(FLAGS_colorImages, &fColorImages)) {
|
|
exit(1);
|
|
}
|
|
|
|
// Choose the candidate color types for image decoding
|
|
fColorTypes.push_back(kN32_SkColorType);
|
|
if (!FLAGS_simpleCodec) {
|
|
fColorTypes.push_back(kRGB_565_SkColorType);
|
|
fColorTypes.push_back(kAlpha_8_SkColorType);
|
|
fColorTypes.push_back(kIndex_8_SkColorType);
|
|
fColorTypes.push_back(kGray_8_SkColorType);
|
|
}
|
|
}
|
|
|
|
static sk_sp<SkPicture> ReadPicture(const char* path) {
|
|
// Not strictly necessary, as it will be checked again later,
|
|
// but helps to avoid a lot of pointless work if we're going to skip it.
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
|
|
return nullptr;
|
|
}
|
|
|
|
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
|
|
if (stream.get() == nullptr) {
|
|
SkDebugf("Could not read %s.\n", path);
|
|
return nullptr;
|
|
}
|
|
|
|
return SkPicture::MakeFromStream(stream.get());
|
|
}
|
|
|
|
Benchmark* next() {
|
|
SkAutoTDelete<Benchmark> bench;
|
|
do {
|
|
bench.reset(this->rawNext());
|
|
if (!bench) {
|
|
return nullptr;
|
|
}
|
|
} while(SkCommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) ||
|
|
SkCommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType));
|
|
return bench.release();
|
|
}
|
|
|
|
Benchmark* rawNext() {
|
|
if (fBenches) {
|
|
Benchmark* bench = fBenches->factory()(nullptr);
|
|
fBenches = fBenches->next();
|
|
fSourceType = "bench";
|
|
fBenchType = "micro";
|
|
return bench;
|
|
}
|
|
|
|
while (fGMs) {
|
|
SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr));
|
|
fGMs = fGMs->next();
|
|
if (gm->runAsBench()) {
|
|
fSourceType = "gm";
|
|
fBenchType = "micro";
|
|
return new GMBench(gm.release());
|
|
}
|
|
}
|
|
|
|
// First add all .skps as RecordingBenches.
|
|
while (fCurrentRecording < fSKPs.count()) {
|
|
const SkString& path = fSKPs[fCurrentRecording++];
|
|
sk_sp<SkPicture> pic = ReadPicture(path.c_str());
|
|
if (!pic) {
|
|
continue;
|
|
}
|
|
SkString name = SkOSPath::Basename(path.c_str());
|
|
fSourceType = "skp";
|
|
fBenchType = "recording";
|
|
fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic.get()));
|
|
fSKPOps = pic->approximateOpCount();
|
|
return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh, FLAGS_lite);
|
|
}
|
|
|
|
// Then once each for each scale as SKPBenches (playback).
|
|
while (fCurrentScale < fScales.count()) {
|
|
while (fCurrentSKP < fSKPs.count()) {
|
|
const SkString& path = fSKPs[fCurrentSKP];
|
|
sk_sp<SkPicture> pic = ReadPicture(path.c_str());
|
|
if (!pic) {
|
|
fCurrentSKP++;
|
|
continue;
|
|
}
|
|
|
|
while (fCurrentUseMPD < fUseMPDs.count()) {
|
|
if (FLAGS_bbh) {
|
|
// The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
|
|
SkRTreeFactory factory;
|
|
SkPictureRecorder recorder;
|
|
pic->playback(recorder.beginRecording(pic->cullRect().width(),
|
|
pic->cullRect().height(),
|
|
&factory,
|
|
0));
|
|
pic = recorder.finishRecordingAsPicture();
|
|
}
|
|
SkString name = SkOSPath::Basename(path.c_str());
|
|
fSourceType = "skp";
|
|
fBenchType = "playback";
|
|
return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
|
|
fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP);
|
|
}
|
|
fCurrentUseMPD = 0;
|
|
fCurrentSKP++;
|
|
}
|
|
fCurrentSKP = 0;
|
|
fCurrentScale++;
|
|
}
|
|
|
|
// Now loop over each skp again if we have an animation
|
|
if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
|
|
while (fCurrentAnimSKP < fSKPs.count()) {
|
|
const SkString& path = fSKPs[fCurrentAnimSKP];
|
|
sk_sp<SkPicture> pic = ReadPicture(path.c_str());
|
|
if (!pic) {
|
|
fCurrentAnimSKP++;
|
|
continue;
|
|
}
|
|
|
|
fCurrentAnimSKP++;
|
|
SkString name = SkOSPath::Basename(path.c_str());
|
|
SkAutoTUnref<SKPAnimationBench::Animation> animation(
|
|
SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs));
|
|
return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation,
|
|
FLAGS_loopSKP);
|
|
}
|
|
}
|
|
|
|
for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
|
|
fSourceType = "image";
|
|
fBenchType = "skcodec";
|
|
const SkString& path = fImages[fCurrentCodec];
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
|
|
continue;
|
|
}
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
|
|
if (!codec) {
|
|
// Nothing to time.
|
|
SkDebugf("Cannot find codec for %s\n", path.c_str());
|
|
continue;
|
|
}
|
|
|
|
while (fCurrentColorType < fColorTypes.count()) {
|
|
const SkColorType colorType = fColorTypes[fCurrentColorType];
|
|
|
|
SkAlphaType alphaType = codec->getInfo().alphaType();
|
|
if (FLAGS_simpleCodec) {
|
|
if (kUnpremul_SkAlphaType == alphaType) {
|
|
alphaType = kPremul_SkAlphaType;
|
|
}
|
|
|
|
fCurrentColorType++;
|
|
} else {
|
|
switch (alphaType) {
|
|
case kOpaque_SkAlphaType:
|
|
// We only need to test one alpha type (opaque).
|
|
fCurrentColorType++;
|
|
break;
|
|
case kUnpremul_SkAlphaType:
|
|
case kPremul_SkAlphaType:
|
|
if (0 == fCurrentAlphaType) {
|
|
// Test unpremul first.
|
|
alphaType = kUnpremul_SkAlphaType;
|
|
fCurrentAlphaType++;
|
|
} else {
|
|
// Test premul.
|
|
alphaType = kPremul_SkAlphaType;
|
|
fCurrentAlphaType = 0;
|
|
fCurrentColorType++;
|
|
}
|
|
break;
|
|
default:
|
|
SkASSERT(false);
|
|
fCurrentColorType++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Make sure we can decode to this color type and alpha type.
|
|
SkImageInfo info =
|
|
codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
|
|
const size_t rowBytes = info.minRowBytes();
|
|
SkAutoMalloc storage(info.getSafeSize(rowBytes));
|
|
|
|
// Used if fCurrentColorType is kIndex_8_SkColorType
|
|
int colorCount = 256;
|
|
SkPMColor colors[256];
|
|
|
|
const SkCodec::Result result = codec->getPixels(
|
|
info, storage.get(), rowBytes, nullptr, colors,
|
|
&colorCount);
|
|
switch (result) {
|
|
case SkCodec::kSuccess:
|
|
case SkCodec::kIncompleteInput:
|
|
return new CodecBench(SkOSPath::Basename(path.c_str()),
|
|
encoded.get(), colorType, alphaType);
|
|
case SkCodec::kInvalidConversion:
|
|
// This is okay. Not all conversions are valid.
|
|
break;
|
|
default:
|
|
// This represents some sort of failure.
|
|
SkASSERT(false);
|
|
break;
|
|
}
|
|
}
|
|
fCurrentColorType = 0;
|
|
}
|
|
|
|
// Run AndroidCodecBenches
|
|
const int sampleSizes[] = { 2, 4, 8 };
|
|
for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) {
|
|
fSourceType = "image";
|
|
fBenchType = "skandroidcodec";
|
|
|
|
const SkString& path = fImages[fCurrentAndroidCodec];
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
|
|
continue;
|
|
}
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
|
|
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get()));
|
|
if (!codec) {
|
|
// Nothing to time.
|
|
SkDebugf("Cannot find codec for %s\n", path.c_str());
|
|
continue;
|
|
}
|
|
|
|
while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
|
|
int sampleSize = sampleSizes[fCurrentSampleSize];
|
|
fCurrentSampleSize++;
|
|
if (10 * sampleSize > SkTMin(codec->getInfo().width(), codec->getInfo().height())) {
|
|
// Avoid benchmarking scaled decodes of already small images.
|
|
break;
|
|
}
|
|
|
|
return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
|
|
encoded.get(), sampleSize);
|
|
}
|
|
fCurrentSampleSize = 0;
|
|
}
|
|
|
|
// Run the BRDBenches
|
|
// We intend to create benchmarks that model the use cases in
|
|
// android/libraries/social/tiledimage. In this library, an image is decoded in 512x512
|
|
// tiles. The image can be translated freely, so the location of a tile may be anywhere in
|
|
// the image. For that reason, we will benchmark decodes in five representative locations
|
|
// in the image. Additionally, this use case utilizes power of two scaling, so we will
|
|
// test on power of two sample sizes. The output tile is always 512x512, so, when a
|
|
// sampleSize is used, the size of the subset that is decoded is always
|
|
// (sampleSize*512)x(sampleSize*512).
|
|
// There are a few good reasons to only test on power of two sample sizes at this time:
|
|
// All use cases we are aware of only scale by powers of two.
|
|
// PNG decodes use the indicated sampling strategy regardless of the sample size, so
|
|
// these tests are sufficient to provide good coverage of our scaling options.
|
|
const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 };
|
|
const uint32_t minOutputSize = 512;
|
|
for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) {
|
|
fSourceType = "image";
|
|
fBenchType = "BRD";
|
|
|
|
const SkString& path = fImages[fCurrentBRDImage];
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
|
|
continue;
|
|
}
|
|
|
|
while (fCurrentColorType < fColorTypes.count()) {
|
|
while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
|
|
while (fCurrentSubsetType <= kLastSingle_SubsetType) {
|
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
|
|
const SkColorType colorType = fColorTypes[fCurrentColorType];
|
|
uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
|
|
int currentSubsetType = fCurrentSubsetType++;
|
|
|
|
int width = 0;
|
|
int height = 0;
|
|
if (!valid_brd_bench(encoded.get(), colorType, sampleSize, minOutputSize,
|
|
&width, &height)) {
|
|
break;
|
|
}
|
|
|
|
SkString basename = SkOSPath::Basename(path.c_str());
|
|
SkIRect subset;
|
|
const uint32_t subsetSize = sampleSize * minOutputSize;
|
|
switch (currentSubsetType) {
|
|
case kTopLeft_SubsetType:
|
|
basename.append("_TopLeft");
|
|
subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize);
|
|
break;
|
|
case kTopRight_SubsetType:
|
|
basename.append("_TopRight");
|
|
subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize,
|
|
subsetSize);
|
|
break;
|
|
case kMiddle_SubsetType:
|
|
basename.append("_Middle");
|
|
subset = SkIRect::MakeXYWH((width - subsetSize) / 2,
|
|
(height - subsetSize) / 2, subsetSize, subsetSize);
|
|
break;
|
|
case kBottomLeft_SubsetType:
|
|
basename.append("_BottomLeft");
|
|
subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize,
|
|
subsetSize);
|
|
break;
|
|
case kBottomRight_SubsetType:
|
|
basename.append("_BottomRight");
|
|
subset = SkIRect::MakeXYWH(width - subsetSize,
|
|
height - subsetSize, subsetSize, subsetSize);
|
|
break;
|
|
default:
|
|
SkASSERT(false);
|
|
}
|
|
|
|
return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(),
|
|
colorType, sampleSize, subset);
|
|
}
|
|
fCurrentSubsetType = 0;
|
|
fCurrentSampleSize++;
|
|
}
|
|
fCurrentSampleSize = 0;
|
|
fCurrentColorType++;
|
|
}
|
|
fCurrentColorType = 0;
|
|
}
|
|
|
|
while (fCurrentColorImage < fColorImages.count()) {
|
|
fSourceType = "colorimage";
|
|
fBenchType = "skcolorcodec";
|
|
const SkString& path = fColorImages[fCurrentColorImage];
|
|
fCurrentColorImage++;
|
|
sk_sp<SkData> encoded = SkData::MakeFromFileName(path.c_str());
|
|
if (encoded) {
|
|
return new ColorCodecBench(SkOSPath::Basename(path.c_str()).c_str(),
|
|
std::move(encoded));
|
|
} else {
|
|
SkDebugf("Could not read file %s.\n", path.c_str());
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void fillCurrentOptions(ResultsWriter* log) const {
|
|
log->configOption("source_type", fSourceType);
|
|
log->configOption("bench_type", fBenchType);
|
|
if (0 == strcmp(fSourceType, "skp")) {
|
|
log->configOption("clip",
|
|
SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
|
|
fClip.fRight, fClip.fBottom).c_str());
|
|
SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
|
|
log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
|
|
if (fCurrentUseMPD > 0) {
|
|
SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
|
|
log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
|
|
}
|
|
}
|
|
if (0 == strcmp(fBenchType, "recording")) {
|
|
log->metric("bytes", fSKPBytes);
|
|
log->metric("ops", fSKPOps);
|
|
}
|
|
}
|
|
|
|
private:
|
|
enum SubsetType {
|
|
kTopLeft_SubsetType = 0,
|
|
kTopRight_SubsetType = 1,
|
|
kMiddle_SubsetType = 2,
|
|
kBottomLeft_SubsetType = 3,
|
|
kBottomRight_SubsetType = 4,
|
|
kTranslate_SubsetType = 5,
|
|
kZoom_SubsetType = 6,
|
|
kLast_SubsetType = kZoom_SubsetType,
|
|
kLastSingle_SubsetType = kBottomRight_SubsetType,
|
|
};
|
|
|
|
const BenchRegistry* fBenches;
|
|
const skiagm::GMRegistry* fGMs;
|
|
SkIRect fClip;
|
|
SkTArray<SkScalar> fScales;
|
|
SkTArray<SkString> fSKPs;
|
|
SkTArray<bool> fUseMPDs;
|
|
SkTArray<SkString> fImages;
|
|
SkTArray<SkString> fColorImages;
|
|
SkTArray<SkColorType, true> fColorTypes;
|
|
SkScalar fZoomMax;
|
|
double fZoomPeriodMs;
|
|
|
|
double fSKPBytes, fSKPOps;
|
|
|
|
const char* fSourceType; // What we're benching: bench, GM, SKP, ...
|
|
const char* fBenchType; // How we bench it: micro, recording, playback, ...
|
|
int fCurrentRecording;
|
|
int fCurrentScale;
|
|
int fCurrentSKP;
|
|
int fCurrentUseMPD;
|
|
int fCurrentCodec;
|
|
int fCurrentAndroidCodec;
|
|
int fCurrentBRDImage;
|
|
int fCurrentColorImage;
|
|
int fCurrentColorType;
|
|
int fCurrentAlphaType;
|
|
int fCurrentSubsetType;
|
|
int fCurrentSampleSize;
|
|
int fCurrentAnimSKP;
|
|
};
|
|
|
|
// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
|
|
// This prints something every once in a while so that it knows we're still working.
|
|
static void start_keepalive() {
|
|
struct Loop {
|
|
static void forever(void*) {
|
|
for (;;) {
|
|
static const int kSec = 1200;
|
|
#if defined(SK_BUILD_FOR_WIN)
|
|
Sleep(kSec * 1000);
|
|
#else
|
|
sleep(kSec);
|
|
#endif
|
|
SkDebugf("\nBenchmarks still running...\n");
|
|
}
|
|
}
|
|
};
|
|
static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
|
|
intentionallyLeaked->start();
|
|
}
|
|
|
|
int nanobench_main();
|
|
int nanobench_main() {
|
|
SetupCrashHandler();
|
|
SkAutoGraphics ag;
|
|
SkTaskGroup::Enabler enabled(FLAGS_threads);
|
|
|
|
#if SK_SUPPORT_GPU
|
|
GrContextOptions grContextOpts;
|
|
gGrFactory.reset(new GrContextFactory(grContextOpts));
|
|
#endif
|
|
|
|
if (FLAGS_veryVerbose) {
|
|
FLAGS_verbose = true;
|
|
}
|
|
|
|
if (kAutoTuneLoops != FLAGS_loops) {
|
|
FLAGS_samples = 1;
|
|
FLAGS_gpuFrameLag = 0;
|
|
}
|
|
|
|
if (!FLAGS_writePath.isEmpty()) {
|
|
SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
|
|
if (!sk_mkdir(FLAGS_writePath[0])) {
|
|
SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
|
|
FLAGS_writePath.set(0, nullptr);
|
|
}
|
|
}
|
|
|
|
SkAutoTDelete<ResultsWriter> log(new ResultsWriter);
|
|
if (!FLAGS_outResultsFile.isEmpty()) {
|
|
#if defined(SK_RELEASE)
|
|
log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0]));
|
|
#else
|
|
SkDebugf("I'm ignoring --outResultsFile because this is a Debug build.");
|
|
return 1;
|
|
#endif
|
|
}
|
|
|
|
if (1 == FLAGS_properties.count() % 2) {
|
|
SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
|
|
return 1;
|
|
}
|
|
for (int i = 1; i < FLAGS_properties.count(); i += 2) {
|
|
log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
|
|
}
|
|
|
|
if (1 == FLAGS_key.count() % 2) {
|
|
SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
|
|
return 1;
|
|
}
|
|
for (int i = 1; i < FLAGS_key.count(); i += 2) {
|
|
log->key(FLAGS_key[i-1], FLAGS_key[i]);
|
|
}
|
|
|
|
const double overhead = estimate_timer_overhead();
|
|
SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
|
|
|
|
SkTArray<double> samples;
|
|
|
|
if (kAutoTuneLoops != FLAGS_loops) {
|
|
SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
|
|
} else if (FLAGS_quiet) {
|
|
SkDebugf("! -> high variance, ? -> moderate variance\n");
|
|
SkDebugf(" micros \tbench\n");
|
|
} else if (FLAGS_ms) {
|
|
SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
|
|
} else {
|
|
SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
|
|
FLAGS_samples, "samples");
|
|
}
|
|
|
|
SkTArray<Config> configs;
|
|
create_configs(&configs);
|
|
|
|
#ifdef THERMAL_MANAGER_SUPPORTED
|
|
int tmEnabled, tmThreshold, tmSleepTimeMs, tmTimeoutMs;
|
|
if (4 != sscanf(FLAGS_useThermalManager[0], "%d,%d,%d,%d",
|
|
&tmEnabled, &tmThreshold, &tmSleepTimeMs, &tmTimeoutMs)) {
|
|
SkDebugf("Can't parse %s from --useThermalManager.\n", FLAGS_useThermalManager[0]);
|
|
exit(1);
|
|
}
|
|
ThermalManager tm(tmThreshold, tmSleepTimeMs, tmTimeoutMs);
|
|
#endif
|
|
|
|
if (FLAGS_keepAlive) {
|
|
start_keepalive();
|
|
}
|
|
|
|
int runs = 0;
|
|
BenchmarkStream benchStream;
|
|
while (Benchmark* b = benchStream.next()) {
|
|
SkAutoTDelete<Benchmark> bench(b);
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
|
|
continue;
|
|
}
|
|
|
|
if (!configs.empty()) {
|
|
log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
|
|
bench->delayedSetup();
|
|
}
|
|
for (int i = 0; i < configs.count(); ++i) {
|
|
#ifdef THERMAL_MANAGER_SUPPORTED
|
|
if (tmEnabled && !tm.coolOffIfNecessary()) {
|
|
SkDebugf("Could not cool off, timings will be throttled\n");
|
|
}
|
|
#endif
|
|
Target* target = is_enabled(b, configs[i]);
|
|
if (!target) {
|
|
continue;
|
|
}
|
|
|
|
// During HWUI output this canvas may be nullptr.
|
|
SkCanvas* canvas = target->getCanvas();
|
|
const char* config = target->config.name.c_str();
|
|
|
|
if (FLAGS_pre_log || FLAGS_dryRun) {
|
|
SkDebugf("Running %s\t%s\n"
|
|
, bench->getUniqueName()
|
|
, config);
|
|
if (FLAGS_dryRun) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
target->setup();
|
|
bench->perCanvasPreDraw(canvas);
|
|
|
|
int maxFrameLag;
|
|
int loops = target->needsFrameTiming(&maxFrameLag)
|
|
? setup_gpu_bench(target, bench.get(), maxFrameLag)
|
|
: setup_cpu_bench(overhead, target, bench.get());
|
|
|
|
if (FLAGS_ms) {
|
|
samples.reset();
|
|
auto stop = now_ms() + FLAGS_ms;
|
|
do {
|
|
samples.push_back(time(loops, bench, target) / loops);
|
|
} while (now_ms() < stop);
|
|
} else {
|
|
samples.reset(FLAGS_samples);
|
|
for (int s = 0; s < FLAGS_samples; s++) {
|
|
samples[s] = time(loops, bench, target) / loops;
|
|
}
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
SkTArray<SkString> keys;
|
|
SkTArray<double> values;
|
|
bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend;
|
|
if (gpuStatsDump) {
|
|
// TODO cache stats
|
|
bench->getGpuStats(canvas, &keys, &values);
|
|
}
|
|
#endif
|
|
|
|
bench->perCanvasPostDraw(canvas);
|
|
|
|
if (Benchmark::kNonRendering_Backend != target->config.backend &&
|
|
!FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
|
|
SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
|
|
pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
|
|
pngFilename.append(".png");
|
|
write_canvas_png(target, pngFilename);
|
|
}
|
|
|
|
if (kFailedLoops == loops) {
|
|
// Can't be timed. A warning note has already been printed.
|
|
cleanup_run(target);
|
|
continue;
|
|
}
|
|
|
|
Stats stats(samples);
|
|
log->config(config);
|
|
log->configOption("name", bench->getName());
|
|
benchStream.fillCurrentOptions(log.get());
|
|
target->fillOptions(log.get());
|
|
log->metric("min_ms", stats.min);
|
|
#if SK_SUPPORT_GPU
|
|
if (gpuStatsDump) {
|
|
// dump to json, only SKPBench currently returns valid keys / values
|
|
SkASSERT(keys.count() == values.count());
|
|
for (int i = 0; i < keys.count(); i++) {
|
|
log->metric(keys[i].c_str(), values[i]);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if (runs++ % FLAGS_flushEvery == 0) {
|
|
log->flush();
|
|
}
|
|
|
|
if (kAutoTuneLoops != FLAGS_loops) {
|
|
if (configs.count() == 1) {
|
|
config = ""; // Only print the config if we run the same bench on more than one.
|
|
}
|
|
SkDebugf("%4d/%-4dMB\t%s\t%s\n"
|
|
, sk_tools::getCurrResidentSetSizeMB()
|
|
, sk_tools::getMaxResidentSetSizeMB()
|
|
, bench->getUniqueName()
|
|
, config);
|
|
} else if (FLAGS_quiet) {
|
|
const char* mark = " ";
|
|
const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
|
|
if (stddev_percent > 5) mark = "?";
|
|
if (stddev_percent > 10) mark = "!";
|
|
|
|
SkDebugf("%10.2f %s\t%s\t%s\n",
|
|
stats.median*1e3, mark, bench->getUniqueName(), config);
|
|
} else {
|
|
const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
|
|
SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
|
|
, sk_tools::getCurrResidentSetSizeMB()
|
|
, sk_tools::getMaxResidentSetSizeMB()
|
|
, loops
|
|
, HUMANIZE(stats.min)
|
|
, HUMANIZE(stats.median)
|
|
, HUMANIZE(stats.mean)
|
|
, HUMANIZE(stats.max)
|
|
, stddev_percent
|
|
, FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str()
|
|
, config
|
|
, bench->getUniqueName()
|
|
);
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
|
|
GrContext* context = gGrFactory->get(configs[i].ctxType,
|
|
configs[i].ctxOptions);
|
|
context->printCacheStats();
|
|
context->printGpuStats();
|
|
}
|
|
#endif
|
|
|
|
if (FLAGS_verbose) {
|
|
SkDebugf("Samples: ");
|
|
for (int i = 0; i < samples.count(); i++) {
|
|
SkDebugf("%s ", HUMANIZE(samples[i]));
|
|
}
|
|
SkDebugf("%s\n", bench->getUniqueName());
|
|
}
|
|
cleanup_run(target);
|
|
}
|
|
}
|
|
|
|
log->bench("memory_usage", 0,0);
|
|
log->config("meta");
|
|
log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
|
|
|
|
#if SK_SUPPORT_GPU
|
|
// Make sure we clean up the global GrContextFactory here, otherwise we might race with the
|
|
// SkEventTracer destructor
|
|
gGrFactory.reset(nullptr);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
int main(int argc, char** argv) {
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
return nanobench_main();
|
|
}
|
|
#endif
|