2014-06-25 21:08:00 +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-07-01 15:43:42 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2014-06-25 21:08:00 +00:00
|
|
|
#include "Benchmark.h"
|
|
|
|
#include "CrashHandler.h"
|
2014-07-31 19:13:48 +00:00
|
|
|
#include "GMBench.h"
|
2014-08-19 22:55:55 +00:00
|
|
|
#include "ProcStats.h"
|
2014-07-14 18:30:37 +00:00
|
|
|
#include "ResultsWriter.h"
|
2014-08-01 14:46:52 +00:00
|
|
|
#include "SKPBench.h"
|
2014-06-25 21:08:00 +00:00
|
|
|
#include "Stats.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
|
Add --bbh (default true) to nanobench.
Chrome's using a bounding box, so it's a good idea for our
bots to do so too.
When set, we'll create an SkTileGrid to match the
parameters of --clip, and so should always hit its fast
path.
This will impose a small overhead (querying the BBH) on all
SKPs, but make large SKPs render more quickly. E.g. on
GPU desk_pokemonwiki should show about a 30% improvement,
tabl_mozilla about 40%, and one very long page from my
personal suite, askmefast.com, gets 5x faster.
(The performance changes are not the point of the CL, but
something we should be aware of.)
BUG=
R=bsalomon@google.com, mtklein@google.com, robertphillips@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/497493003
2014-08-21 22:51:22 +00:00
|
|
|
#include "SkBBHFactory.h"
|
2014-06-25 21:08:00 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-07-22 17:15:34 +00:00
|
|
|
#include "SkCommonFlags.h"
|
2014-06-25 21:08:00 +00:00
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkGraphics.h"
|
Add --bbh (default true) to nanobench.
Chrome's using a bounding box, so it's a good idea for our
bots to do so too.
When set, we'll create an SkTileGrid to match the
parameters of --clip, and so should always hit its fast
path.
This will impose a small overhead (querying the BBH) on all
SKPs, but make large SKPs render more quickly. E.g. on
GPU desk_pokemonwiki should show about a 30% improvement,
tabl_mozilla about 40%, and one very long page from my
personal suite, askmefast.com, gets 5x faster.
(The performance changes are not the point of the CL, but
something we should be aware of.)
BUG=
R=bsalomon@google.com, mtklein@google.com, robertphillips@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/497493003
2014-08-21 22:51:22 +00:00
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
2014-06-25 21:08:00 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-07-17 20:14:16 +00:00
|
|
|
#include "gl/GrGLDefines.h"
|
2014-07-01 15:43:42 +00:00
|
|
|
#include "GrContextFactory.h"
|
2014-08-13 17:46:31 +00:00
|
|
|
SkAutoTDelete<GrContextFactory> gGrFactory;
|
2014-07-01 15:43:42 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-25 21:08:00 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
static const int kAutoTuneLoops = -1;
|
|
|
|
|
2014-08-07 22:20:02 +00:00
|
|
|
static const int kDefaultLoops =
|
2014-08-07 21:28:50 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
1;
|
2014-07-14 19:28:47 +00:00
|
|
|
#else
|
2014-08-07 21:28:50 +00:00
|
|
|
kAutoTuneLoops;
|
2014-07-14 19:28:47 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str());
|
|
|
|
|
2014-06-25 21:08:00 +00:00
|
|
|
DEFINE_int32(samples, 10, "Number of samples to measure for each bench.");
|
|
|
|
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.");
|
2014-07-01 15:43:42 +00:00
|
|
|
DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
|
|
|
|
DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allows to lag.");
|
2014-08-13 19:06:26 +00:00
|
|
|
DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
|
|
|
|
"software path rendering.");
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-14 18:30:37 +00:00
|
|
|
DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
|
2014-07-17 15:38:23 +00:00
|
|
|
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.");
|
2014-08-20 18:45:00 +00:00
|
|
|
DEFINE_string(properties, "",
|
|
|
|
"Space-separated key/value pairs to add to JSON identifying this nanobench run.");
|
Add --options to nanobench, similar to --key but for non-identifying options.
Friends with https://codereview.chromium.org/487233003/
Example of out/Release/nanobench --options build_number 12374 --match patch_grid_texs_small
{
"gitHash":"unknown-revision",
"options":{
"build_number":"12374",
"system":"UNIX"
},
"results":{
"patch_grid_texs_small_640_480":{
"565":{
"max_ms":0.268116,
"mean_ms":0.2318529,
"median_ms":0.235337,
"min_ms":0.219158,
"options":{
"source_type":"bench"
},
"stddev_ms":0.01491263917658814
},
"8888":{
"max_ms":0.231881,
"mean_ms":0.2214668,
"median_ms":0.219356,
"min_ms":0.218887,
"options":{
"source_type":"bench"
},
"stddev_ms":0.004595541070791701
},
"gpu":{
"max_ms":0.1398304782608696,
"mean_ms":0.128833402173913,
"median_ms":0.1316798695652174,
"min_ms":0.1111915434782609,
"options":{
"GL_RENDERER":"Quadro 600/PCIe/SSE2",
"GL_SHADING_LANGUAGE_VERSION":"4.40 NVIDIA via Cg compiler",
"GL_VENDOR":"NVIDIA Corporation",
"GL_VERSION":"4.4.0 NVIDIA 331.79",
"source_type":"bench"
},
"stddev_ms":0.008923738937837156
}
}
}
}
BUG=skia:
R=jcgregorio@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/490683002
2014-08-19 19:41:53 +00:00
|
|
|
DEFINE_string(key, "",
|
|
|
|
"Space-separated key/value pairs to add to JSON identifying this bench config.");
|
2014-07-14 18:30:37 +00:00
|
|
|
|
2014-08-01 14:46:52 +00:00
|
|
|
DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
|
|
|
|
DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
|
Add --bbh (default true) to nanobench.
Chrome's using a bounding box, so it's a good idea for our
bots to do so too.
When set, we'll create an SkTileGrid to match the
parameters of --clip, and so should always hit its fast
path.
This will impose a small overhead (querying the BBH) on all
SKPs, but make large SKPs render more quickly. E.g. on
GPU desk_pokemonwiki should show about a 30% improvement,
tabl_mozilla about 40%, and one very long page from my
personal suite, askmefast.com, gets 5x faster.
(The performance changes are not the point of the CL, but
something we should be aware of.)
BUG=
R=bsalomon@google.com, mtklein@google.com, robertphillips@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/497493003
2014-08-21 22:51:22 +00:00
|
|
|
DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
|
2014-08-01 14:46:52 +00:00
|
|
|
|
2014-06-25 21:08:00 +00:00
|
|
|
static SkString humanize(double ms) {
|
|
|
|
if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
|
|
|
|
if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
|
2014-07-15 17:30:31 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
|
|
|
|
#else
|
2014-06-25 21:08:00 +00:00
|
|
|
if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
|
2014-07-15 17:30:31 +00:00
|
|
|
#endif
|
2014-06-25 21:08:00 +00:00
|
|
|
return SkStringPrintf("%.3gms", ms);
|
|
|
|
}
|
2014-07-17 15:38:23 +00:00
|
|
|
#define HUMANIZE(ms) humanize(ms).c_str()
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHelper* gl) {
|
2014-08-07 21:28:50 +00:00
|
|
|
if (canvas) {
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
}
|
2014-06-25 21:08:00 +00:00
|
|
|
WallTimer timer;
|
2014-07-01 15:43:42 +00:00
|
|
|
timer.start();
|
|
|
|
if (bench) {
|
|
|
|
bench->draw(loops, canvas);
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
if (canvas) {
|
|
|
|
canvas->flush();
|
|
|
|
}
|
2014-07-01 15:43:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (gl) {
|
|
|
|
SK_GL(*gl, Flush());
|
|
|
|
gl->swapBuffers();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
timer.end();
|
|
|
|
return timer.fWall;
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
static double estimate_timer_overhead() {
|
|
|
|
double overhead = 0;
|
|
|
|
for (int i = 0; i < FLAGS_overheadLoops; i++) {
|
|
|
|
overhead += time(1, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
return overhead / FLAGS_overheadLoops;
|
|
|
|
}
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-17 15:38:23 +00:00
|
|
|
static int clamp_loops(int loops) {
|
|
|
|
if (loops < 1) {
|
|
|
|
SkDebugf("ERROR: clamping loops from %d to 1.\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;
|
|
|
|
}
|
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) {
|
|
|
|
if (filename.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (kUnknown_SkColorType == canvas->imageInfo().fColorType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.setInfo(canvas->imageInfo());
|
|
|
|
if (!canvas->readPixels(&bmp, 0, 0)) {
|
|
|
|
SkDebugf("Can't read canvas pixels.\n");
|
|
|
|
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;
|
2014-07-01 15:43:42 +00:00
|
|
|
static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
|
|
|
|
// First figure out approximately how many loops of bench it takes to make overhead negligible.
|
2014-08-04 20:57:39 +00:00
|
|
|
double bench_plus_overhead = 0.0;
|
2014-07-17 15:38:23 +00:00
|
|
|
int round = 0;
|
2014-08-07 21:28:50 +00:00
|
|
|
if (kAutoTuneLoops == FLAGS_loops) {
|
|
|
|
while (bench_plus_overhead < overhead) {
|
|
|
|
if (round++ == FLAGS_maxCalibrationAttempts) {
|
|
|
|
SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
|
|
|
|
bench->getName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
|
|
|
|
return kFailedLoops;
|
|
|
|
}
|
|
|
|
bench_plus_overhead = time(1, bench, canvas, NULL);
|
2014-07-17 15:38:23 +00:00
|
|
|
}
|
2014-08-04 20:57:39 +00:00
|
|
|
}
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
// Later we'll just start and stop the timer once but loop N times.
|
2014-06-25 21:08:00 +00:00
|
|
|
// We'll pick N to make timer overhead negligible:
|
|
|
|
//
|
2014-07-01 15:43:42 +00:00
|
|
|
// overhead
|
|
|
|
// ------------------------- < FLAGS_overheadGoal
|
|
|
|
// overhead + N * Bench Time
|
2014-06-25 21:08:00 +00:00
|
|
|
//
|
2014-07-01 15:43:42 +00:00
|
|
|
// where bench_plus_overhead ≈ overhead + Bench Time.
|
2014-06-25 21:08:00 +00:00
|
|
|
//
|
|
|
|
// Doing some math, we get:
|
|
|
|
//
|
2014-07-01 15:43:42 +00:00
|
|
|
// (overhead / FLAGS_overheadGoal) - overhead
|
|
|
|
// ------------------------------------------ < N
|
|
|
|
// bench_plus_overhead - overhead)
|
2014-06-25 21:08:00 +00:00
|
|
|
//
|
|
|
|
// Luckily, this also works well in practice. :)
|
2014-08-07 21:28:50 +00:00
|
|
|
int loops = FLAGS_loops;
|
|
|
|
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);
|
2014-07-01 15:43:42 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < FLAGS_samples; i++) {
|
|
|
|
samples[i] = time(loops, bench, canvas, NULL) / loops;
|
|
|
|
}
|
|
|
|
return loops;
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
static int gpu_bench(SkGLContextHelper* gl,
|
|
|
|
Benchmark* bench,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
double* samples) {
|
2014-07-22 20:09:05 +00:00
|
|
|
gl->makeCurrent();
|
2014-07-01 15:43:42 +00:00
|
|
|
// Make sure we're done with whatever came before.
|
2014-07-01 17:02:42 +00:00
|
|
|
SK_GL(*gl, Finish());
|
2014-07-01 15:43:42 +00:00
|
|
|
|
|
|
|
// First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
|
2014-08-07 21:28:50 +00:00
|
|
|
int loops = FLAGS_loops;
|
|
|
|
if (kAutoTuneLoops == loops) {
|
|
|
|
loops = 1;
|
2014-07-14 19:28:47 +00:00
|
|
|
double elapsed = 0;
|
|
|
|
do {
|
|
|
|
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. We force this by looping
|
|
|
|
// more times than any reasonable GPU will allow frames to lag.
|
|
|
|
for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
|
|
|
|
elapsed = time(loops, bench, canvas, gl);
|
|
|
|
}
|
|
|
|
} while (elapsed < FLAGS_gpuMs);
|
|
|
|
|
|
|
|
// We've overshot at least a little. Scale back linearly.
|
|
|
|
loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
|
|
|
|
|
|
|
|
// Might as well make sure we're not still timing our calibration.
|
|
|
|
SK_GL(*gl, Finish());
|
|
|
|
}
|
2014-07-17 15:38:23 +00:00
|
|
|
loops = clamp_loops(loops);
|
2014-07-01 15:43:42 +00:00
|
|
|
|
|
|
|
// 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 < FLAGS_gpuFrameLag; i++) {
|
|
|
|
time(loops, bench, canvas, gl);
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
2014-07-01 15:43:42 +00:00
|
|
|
|
|
|
|
// Now, actually do the timing!
|
|
|
|
for (int i = 0; i < FLAGS_samples; i++) {
|
|
|
|
samples[i] = time(loops, bench, canvas, gl) / loops;
|
|
|
|
}
|
|
|
|
return loops;
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
2014-07-01 15:43:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static SkString to_lower(const char* str) {
|
|
|
|
SkString lower(str);
|
|
|
|
for (size_t i = 0; i < lower.size(); i++) {
|
|
|
|
lower[i] = tolower(lower[i]);
|
|
|
|
}
|
|
|
|
return lower;
|
|
|
|
}
|
|
|
|
|
2014-07-22 20:09:05 +00:00
|
|
|
struct Config {
|
|
|
|
const char* name;
|
2014-07-01 15:43:42 +00:00
|
|
|
Benchmark::Backend backend;
|
2014-07-22 20:09:05 +00:00
|
|
|
SkColorType color;
|
|
|
|
SkAlphaType alpha;
|
|
|
|
int samples;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContextFactory::GLContextType ctxType;
|
|
|
|
#else
|
|
|
|
int bogusInt;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Target {
|
|
|
|
explicit Target(const Config& c) : config(c) {}
|
|
|
|
const Config config;
|
2014-07-01 15:43:42 +00:00
|
|
|
SkAutoTDelete<SkSurface> surface;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
SkGLContextHelper* gl;
|
|
|
|
#endif
|
|
|
|
};
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-22 20:09:05 +00:00
|
|
|
static bool is_cpu_config_allowed(const char* name) {
|
2014-07-01 15:43:42 +00:00
|
|
|
for (int i = 0; i < FLAGS_config.count(); i++) {
|
2014-07-22 20:09:05 +00:00
|
|
|
if (to_lower(FLAGS_config[i]).equals(name)) {
|
|
|
|
return true;
|
2014-07-01 15:43:42 +00:00
|
|
|
}
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
2014-07-22 20:09:05 +00:00
|
|
|
return false;
|
2014-07-01 15:43:42 +00:00
|
|
|
}
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-22 20:09:05 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType,
|
|
|
|
int sampleCnt) {
|
|
|
|
if (!is_cpu_config_allowed(name)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-13 17:46:31 +00:00
|
|
|
if (const GrContext* ctx = gGrFactory->get(ctxType)) {
|
2014-07-22 20:09:05 +00:00
|
|
|
return sampleCnt <= ctx->getMaxSampleCount();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#define kBogusGLContextType GrContextFactory::kNative_GLContextType
|
|
|
|
#else
|
|
|
|
#define kBogusGLContextType 0
|
2014-07-31 19:13:48 +00:00
|
|
|
#endif
|
2014-07-22 20:09:05 +00:00
|
|
|
|
|
|
|
// Append all configs that are enabled and supported.
|
|
|
|
static void create_configs(SkTDArray<Config>* configs) {
|
|
|
|
#define CPU_CONFIG(name, backend, color, alpha) \
|
|
|
|
if (is_cpu_config_allowed(#name)) { \
|
|
|
|
Config config = { #name, Benchmark::backend, color, alpha, 0, kBogusGLContextType }; \
|
|
|
|
configs->push(config); \
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
2014-07-31 19:13:48 +00:00
|
|
|
|
2014-07-09 15:46:49 +00:00
|
|
|
if (FLAGS_cpu) {
|
2014-07-22 20:09:05 +00:00
|
|
|
CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType)
|
|
|
|
CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
|
|
|
|
CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType)
|
2014-07-09 15:46:49 +00:00
|
|
|
}
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-07-22 20:09:05 +00:00
|
|
|
#define GPU_CONFIG(name, ctxType, samples) \
|
|
|
|
if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
|
|
|
|
Config config = { \
|
|
|
|
#name, \
|
|
|
|
Benchmark::kGPU_Backend, \
|
|
|
|
kN32_SkColorType, \
|
|
|
|
kPremul_SkAlphaType, \
|
|
|
|
samples, \
|
|
|
|
GrContextFactory::ctxType }; \
|
|
|
|
configs->push(config); \
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
2014-07-31 19:13:48 +00:00
|
|
|
|
2014-07-09 15:46:49 +00:00
|
|
|
if (FLAGS_gpu) {
|
2014-07-22 20:09:05 +00:00
|
|
|
GPU_CONFIG(gpu, kNative_GLContextType, 0)
|
|
|
|
GPU_CONFIG(msaa4, kNative_GLContextType, 4)
|
|
|
|
GPU_CONFIG(msaa16, kNative_GLContextType, 16)
|
|
|
|
GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4)
|
|
|
|
GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16)
|
|
|
|
GPU_CONFIG(debug, kDebug_GLContextType, 0)
|
|
|
|
GPU_CONFIG(nullgpu, kNull_GLContextType, 0)
|
2014-08-06 17:52:33 +00:00
|
|
|
#ifdef SK_ANGLE
|
|
|
|
GPU_CONFIG(angle, kANGLE_GLContextType, 0)
|
|
|
|
#endif
|
2014-07-09 15:46:49 +00:00
|
|
|
}
|
2014-07-01 15:43:42 +00:00
|
|
|
#endif
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 20:09:05 +00:00
|
|
|
// If bench is enabled for config, returns a Target* for it, otherwise NULL.
|
|
|
|
static Target* is_enabled(Benchmark* bench, const Config& config) {
|
|
|
|
if (!bench->isSuitableFor(config.backend)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo info;
|
|
|
|
info.fAlphaType = config.alpha;
|
|
|
|
info.fColorType = config.color;
|
|
|
|
info.fWidth = bench->getSize().fX;
|
|
|
|
info.fHeight = bench->getSize().fY;
|
|
|
|
|
|
|
|
Target* target = new Target(config);
|
|
|
|
|
|
|
|
if (Benchmark::kRaster_Backend == config.backend) {
|
|
|
|
target->surface.reset(SkSurface::NewRaster(info));
|
|
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
else if (Benchmark::kGPU_Backend == config.backend) {
|
2014-08-13 17:46:31 +00:00
|
|
|
target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType), info,
|
2014-07-22 20:09:05 +00:00
|
|
|
config.samples));
|
2014-08-13 17:46:31 +00:00
|
|
|
target->gl = gGrFactory->getGLContext(config.ctxType);
|
2014-07-22 20:09:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) {
|
|
|
|
delete target;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates targets for a benchmark and a set of configs.
|
|
|
|
static void create_targets(SkTDArray<Target*>* targets, Benchmark* b,
|
|
|
|
const SkTDArray<Config>& configs) {
|
|
|
|
for (int i = 0; i < configs.count(); ++i) {
|
|
|
|
if (Target* t = is_enabled(b, configs[i])) {
|
|
|
|
targets->push(t);
|
|
|
|
}
|
2014-07-31 19:13:48 +00:00
|
|
|
|
2014-07-22 20:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 20:14:16 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
static void fill_gpu_options(ResultsWriter* log, SkGLContextHelper* ctx) {
|
2014-07-17 20:54:36 +00:00
|
|
|
const GrGLubyte* version;
|
2014-07-17 20:14:16 +00:00
|
|
|
SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION));
|
|
|
|
log->configOption("GL_VERSION", (const char*)(version));
|
|
|
|
|
|
|
|
SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER));
|
|
|
|
log->configOption("GL_RENDERER", (const char*) version);
|
|
|
|
|
|
|
|
SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
|
|
|
|
log->configOption("GL_VENDOR", (const char*) version);
|
|
|
|
|
|
|
|
SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-31 19:13:48 +00:00
|
|
|
class BenchmarkStream {
|
|
|
|
public:
|
2014-08-01 14:46:52 +00:00
|
|
|
BenchmarkStream() : fBenches(BenchRegistry::Head())
|
|
|
|
, fGMs(skiagm::GMRegistry::Head())
|
|
|
|
, fCurrentScale(0)
|
|
|
|
, fCurrentSKP(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-31 19:13:48 +00:00
|
|
|
|
2014-08-01 14:46:52 +00:00
|
|
|
Benchmark* next() {
|
2014-07-31 19:13:48 +00:00
|
|
|
if (fBenches) {
|
|
|
|
Benchmark* bench = fBenches->factory()(NULL);
|
|
|
|
fBenches = fBenches->next();
|
2014-08-01 14:46:52 +00:00
|
|
|
fSourceType = "bench";
|
2014-07-31 19:13:48 +00:00
|
|
|
return bench;
|
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
|
2014-07-31 19:13:48 +00:00
|
|
|
while (fGMs) {
|
|
|
|
SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
|
|
|
|
fGMs = fGMs->next();
|
|
|
|
if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
|
2014-08-01 14:46:52 +00:00
|
|
|
fSourceType = "gm";
|
2014-07-31 19:13:48 +00:00
|
|
|
return SkNEW_ARGS(GMBench, (gm.detach()));
|
|
|
|
}
|
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
|
|
|
|
while (fCurrentScale < fScales.count()) {
|
|
|
|
while (fCurrentSKP < fSKPs.count()) {
|
|
|
|
const SkString& path = fSKPs[fCurrentSKP++];
|
|
|
|
|
|
|
|
// 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, path.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str()));
|
|
|
|
if (stream.get() == NULL) {
|
|
|
|
SkDebugf("Could not read %s.\n", path.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
|
|
|
|
if (pic.get() == NULL) {
|
|
|
|
SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString name = SkOSPath::Basename(path.c_str());
|
|
|
|
|
Add --bbh (default true) to nanobench.
Chrome's using a bounding box, so it's a good idea for our
bots to do so too.
When set, we'll create an SkTileGrid to match the
parameters of --clip, and so should always hit its fast
path.
This will impose a small overhead (querying the BBH) on all
SKPs, but make large SKPs render more quickly. E.g. on
GPU desk_pokemonwiki should show about a 30% improvement,
tabl_mozilla about 40%, and one very long page from my
personal suite, askmefast.com, gets 5x faster.
(The performance changes are not the point of the CL, but
something we should be aware of.)
BUG=
R=bsalomon@google.com, mtklein@google.com, robertphillips@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/497493003
2014-08-21 22:51:22 +00:00
|
|
|
if (FLAGS_bbh) {
|
|
|
|
// The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
|
|
|
|
// Here we use an SkTileGrid with parameters optimized for FLAGS_clip.
|
|
|
|
const SkTileGridFactory::TileGridInfo info = {
|
|
|
|
SkISize::Make(fClip.width(), fClip.height()), // tile interval
|
|
|
|
SkISize::Make(0,0), // margin
|
|
|
|
SkIPoint::Make(fClip.left(), fClip.top()), // offset
|
|
|
|
};
|
|
|
|
SkTileGridFactory factory(info);
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
pic->draw(recorder.beginRecording(pic->width(), pic->height(), &factory));
|
|
|
|
pic.reset(recorder.endRecording());
|
|
|
|
}
|
|
|
|
|
2014-08-01 14:46:52 +00:00
|
|
|
fSourceType = "skp";
|
|
|
|
return SkNEW_ARGS(SKPBench,
|
|
|
|
(name.c_str(), pic.get(), fClip, fScales[fCurrentScale]));
|
|
|
|
}
|
|
|
|
fCurrentSKP = 0;
|
|
|
|
fCurrentScale++;
|
|
|
|
}
|
|
|
|
|
2014-07-31 19:13:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
|
|
|
|
void fillCurrentOptions(ResultsWriter* log) const {
|
|
|
|
log->configOption("source_type", fSourceType);
|
|
|
|
if (0 == strcmp(fSourceType, "skp")) {
|
|
|
|
log->configOption("clip",
|
|
|
|
SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
|
|
|
|
fClip.fRight, fClip.fBottom).c_str());
|
|
|
|
log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 19:13:48 +00:00
|
|
|
private:
|
|
|
|
const BenchRegistry* fBenches;
|
|
|
|
const skiagm::GMRegistry* fGMs;
|
2014-08-01 14:46:52 +00:00
|
|
|
SkIRect fClip;
|
|
|
|
SkTArray<SkScalar> fScales;
|
|
|
|
SkTArray<SkString> fSKPs;
|
|
|
|
|
|
|
|
const char* fSourceType;
|
|
|
|
int fCurrentScale;
|
|
|
|
int fCurrentSKP;
|
2014-07-31 19:13:48 +00:00
|
|
|
};
|
|
|
|
|
2014-07-22 17:15:34 +00:00
|
|
|
int nanobench_main();
|
|
|
|
int nanobench_main() {
|
2014-06-25 21:08:00 +00:00
|
|
|
SetupCrashHandler();
|
|
|
|
SkAutoGraphics ag;
|
|
|
|
|
2014-08-13 17:46:31 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-08-13 19:06:26 +00:00
|
|
|
GrContext::Options grContextOpts;
|
|
|
|
grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
|
|
|
|
gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
|
2014-08-13 17:46:31 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
if (kAutoTuneLoops != FLAGS_loops) {
|
2014-07-14 19:28:47 +00:00
|
|
|
FLAGS_samples = 1;
|
|
|
|
FLAGS_gpuFrameLag = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
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, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 18:45:00 +00:00
|
|
|
SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter));
|
2014-07-14 18:30:37 +00:00
|
|
|
if (!FLAGS_outResultsFile.isEmpty()) {
|
2014-08-20 18:45:00 +00:00
|
|
|
log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0])));
|
2014-07-14 18:30:37 +00:00
|
|
|
}
|
2014-07-17 20:14:16 +00:00
|
|
|
|
2014-08-20 18:45:00 +00:00
|
|
|
if (1 == FLAGS_properties.count() % 2) {
|
|
|
|
SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
|
2014-07-17 20:14:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-08-20 18:45:00 +00:00
|
|
|
for (int i = 1; i < FLAGS_properties.count(); i += 2) {
|
|
|
|
log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
|
2014-07-17 20:14:16 +00:00
|
|
|
}
|
Add --options to nanobench, similar to --key but for non-identifying options.
Friends with https://codereview.chromium.org/487233003/
Example of out/Release/nanobench --options build_number 12374 --match patch_grid_texs_small
{
"gitHash":"unknown-revision",
"options":{
"build_number":"12374",
"system":"UNIX"
},
"results":{
"patch_grid_texs_small_640_480":{
"565":{
"max_ms":0.268116,
"mean_ms":0.2318529,
"median_ms":0.235337,
"min_ms":0.219158,
"options":{
"source_type":"bench"
},
"stddev_ms":0.01491263917658814
},
"8888":{
"max_ms":0.231881,
"mean_ms":0.2214668,
"median_ms":0.219356,
"min_ms":0.218887,
"options":{
"source_type":"bench"
},
"stddev_ms":0.004595541070791701
},
"gpu":{
"max_ms":0.1398304782608696,
"mean_ms":0.128833402173913,
"median_ms":0.1316798695652174,
"min_ms":0.1111915434782609,
"options":{
"GL_RENDERER":"Quadro 600/PCIe/SSE2",
"GL_SHADING_LANGUAGE_VERSION":"4.40 NVIDIA via Cg compiler",
"GL_VENDOR":"NVIDIA Corporation",
"GL_VERSION":"4.4.0 NVIDIA 331.79",
"source_type":"bench"
},
"stddev_ms":0.008923738937837156
}
}
}
}
BUG=skia:
R=jcgregorio@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/490683002
2014-08-19 19:41:53 +00:00
|
|
|
|
2014-08-20 18:45:00 +00:00
|
|
|
if (1 == FLAGS_key.count() % 2) {
|
|
|
|
SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
|
Add --options to nanobench, similar to --key but for non-identifying options.
Friends with https://codereview.chromium.org/487233003/
Example of out/Release/nanobench --options build_number 12374 --match patch_grid_texs_small
{
"gitHash":"unknown-revision",
"options":{
"build_number":"12374",
"system":"UNIX"
},
"results":{
"patch_grid_texs_small_640_480":{
"565":{
"max_ms":0.268116,
"mean_ms":0.2318529,
"median_ms":0.235337,
"min_ms":0.219158,
"options":{
"source_type":"bench"
},
"stddev_ms":0.01491263917658814
},
"8888":{
"max_ms":0.231881,
"mean_ms":0.2214668,
"median_ms":0.219356,
"min_ms":0.218887,
"options":{
"source_type":"bench"
},
"stddev_ms":0.004595541070791701
},
"gpu":{
"max_ms":0.1398304782608696,
"mean_ms":0.128833402173913,
"median_ms":0.1316798695652174,
"min_ms":0.1111915434782609,
"options":{
"GL_RENDERER":"Quadro 600/PCIe/SSE2",
"GL_SHADING_LANGUAGE_VERSION":"4.40 NVIDIA via Cg compiler",
"GL_VENDOR":"NVIDIA Corporation",
"GL_VERSION":"4.4.0 NVIDIA 331.79",
"source_type":"bench"
},
"stddev_ms":0.008923738937837156
}
}
}
}
BUG=skia:
R=jcgregorio@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/490683002
2014-08-19 19:41:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-08-20 18:45:00 +00:00
|
|
|
for (int i = 1; i < FLAGS_key.count(); i += 2) {
|
|
|
|
log->key(FLAGS_key[i-1], FLAGS_key[i]);
|
Add --options to nanobench, similar to --key but for non-identifying options.
Friends with https://codereview.chromium.org/487233003/
Example of out/Release/nanobench --options build_number 12374 --match patch_grid_texs_small
{
"gitHash":"unknown-revision",
"options":{
"build_number":"12374",
"system":"UNIX"
},
"results":{
"patch_grid_texs_small_640_480":{
"565":{
"max_ms":0.268116,
"mean_ms":0.2318529,
"median_ms":0.235337,
"min_ms":0.219158,
"options":{
"source_type":"bench"
},
"stddev_ms":0.01491263917658814
},
"8888":{
"max_ms":0.231881,
"mean_ms":0.2214668,
"median_ms":0.219356,
"min_ms":0.218887,
"options":{
"source_type":"bench"
},
"stddev_ms":0.004595541070791701
},
"gpu":{
"max_ms":0.1398304782608696,
"mean_ms":0.128833402173913,
"median_ms":0.1316798695652174,
"min_ms":0.1111915434782609,
"options":{
"GL_RENDERER":"Quadro 600/PCIe/SSE2",
"GL_SHADING_LANGUAGE_VERSION":"4.40 NVIDIA via Cg compiler",
"GL_VENDOR":"NVIDIA Corporation",
"GL_VERSION":"4.4.0 NVIDIA 331.79",
"source_type":"bench"
},
"stddev_ms":0.008923738937837156
}
}
}
}
BUG=skia:
R=jcgregorio@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/490683002
2014-08-19 19:41:53 +00:00
|
|
|
}
|
2014-07-14 18:30:37 +00:00
|
|
|
|
2014-06-25 21:08:00 +00:00
|
|
|
const double overhead = estimate_timer_overhead();
|
2014-07-17 15:38:23 +00:00
|
|
|
SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
|
2014-07-16 23:59:32 +00:00
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
SkAutoTMalloc<double> samples(FLAGS_samples);
|
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
if (kAutoTuneLoops != FLAGS_loops) {
|
|
|
|
SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
|
2014-07-14 19:28:47 +00:00
|
|
|
} else if (FLAGS_verbose) {
|
2014-06-25 21:08:00 +00:00
|
|
|
// No header.
|
|
|
|
} else if (FLAGS_quiet) {
|
2014-07-09 15:46:49 +00:00
|
|
|
SkDebugf("median\tbench\tconfig\n");
|
2014-06-25 21:08:00 +00:00
|
|
|
} else {
|
2014-08-19 22:55:55 +00:00
|
|
|
SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 20:09:05 +00:00
|
|
|
SkTDArray<Config> configs;
|
|
|
|
create_configs(&configs);
|
|
|
|
|
2014-08-01 14:46:52 +00:00
|
|
|
BenchmarkStream benchStream;
|
|
|
|
while (Benchmark* b = benchStream.next()) {
|
2014-07-31 19:13:48 +00:00
|
|
|
SkAutoTDelete<Benchmark> bench(b);
|
2014-06-25 21:08:00 +00:00
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-01 15:43:42 +00:00
|
|
|
SkTDArray<Target*> targets;
|
2014-07-22 20:09:05 +00:00
|
|
|
create_targets(&targets, bench.get(), configs);
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-07-17 20:14:16 +00:00
|
|
|
if (!targets.isEmpty()) {
|
2014-08-20 18:45:00 +00:00
|
|
|
log->bench(bench->getName(), bench->getSize().fX, bench->getSize().fY);
|
2014-07-17 20:14:16 +00:00
|
|
|
bench->preDraw();
|
|
|
|
}
|
2014-07-01 15:43:42 +00:00
|
|
|
for (int j = 0; j < targets.count(); j++) {
|
|
|
|
SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
|
2014-07-22 20:09:05 +00:00
|
|
|
const char* config = targets[j]->config.name;
|
2014-07-01 15:43:42 +00:00
|
|
|
|
|
|
|
const int loops =
|
|
|
|
#if SK_SUPPORT_GPU
|
2014-07-22 20:09:05 +00:00
|
|
|
Benchmark::kGPU_Backend == targets[j]->config.backend
|
2014-07-01 15:43:42 +00:00
|
|
|
? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
|
|
|
|
:
|
|
|
|
#endif
|
|
|
|
cpu_bench( overhead, bench.get(), canvas, samples.get());
|
2014-06-25 21:08:00 +00:00
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
if (canvas && !FLAGS_writePath.isEmpty() && NULL != FLAGS_writePath[0]) {
|
|
|
|
SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
|
|
|
|
pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getName());
|
|
|
|
pngFilename.append(".png");
|
|
|
|
write_canvas_png(canvas, pngFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kFailedLoops == loops) {
|
2014-08-04 20:57:39 +00:00
|
|
|
// Can't be timed. A warning note has already been printed.
|
2014-07-15 21:56:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-07-14 18:30:37 +00:00
|
|
|
|
2014-07-15 21:56:37 +00:00
|
|
|
Stats stats(samples.get(), FLAGS_samples);
|
2014-08-20 18:45:00 +00:00
|
|
|
log->config(config);
|
|
|
|
benchStream.fillCurrentOptions(log.get());
|
2014-07-17 20:14:16 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-07-22 20:09:05 +00:00
|
|
|
if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
|
2014-08-20 18:45:00 +00:00
|
|
|
fill_gpu_options(log.get(), targets[j]->gl);
|
2014-07-17 20:14:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-08-20 18:45:00 +00:00
|
|
|
log->timer("min_ms", stats.min);
|
|
|
|
log->timer("median_ms", stats.median);
|
|
|
|
log->timer("mean_ms", stats.mean);
|
|
|
|
log->timer("max_ms", stats.max);
|
|
|
|
log->timer("stddev_ms", sqrt(stats.var));
|
2014-07-14 18:30:37 +00:00
|
|
|
|
2014-08-07 21:28:50 +00:00
|
|
|
if (kAutoTuneLoops != FLAGS_loops) {
|
2014-07-14 19:28:47 +00:00
|
|
|
if (targets.count() == 1) {
|
|
|
|
config = ""; // Only print the config if we run the same bench on more than one.
|
|
|
|
}
|
|
|
|
SkDebugf("%s\t%s\n", bench->getName(), config);
|
|
|
|
} else if (FLAGS_verbose) {
|
2014-06-25 21:08:00 +00:00
|
|
|
for (int i = 0; i < FLAGS_samples; i++) {
|
2014-07-17 15:38:23 +00:00
|
|
|
SkDebugf("%s ", HUMANIZE(samples[i]));
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
SkDebugf("%s\n", bench->getName());
|
|
|
|
} else if (FLAGS_quiet) {
|
2014-07-01 15:43:42 +00:00
|
|
|
if (targets.count() == 1) {
|
2014-06-25 21:08:00 +00:00
|
|
|
config = ""; // Only print the config if we run the same bench on more than one.
|
|
|
|
}
|
2014-07-17 15:38:23 +00:00
|
|
|
SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getName(), config);
|
2014-06-25 21:08:00 +00:00
|
|
|
} else {
|
|
|
|
const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
|
2014-08-19 22:55:55 +00:00
|
|
|
SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
|
|
|
|
, sk_tools::getMaxResidentSetSizeMB()
|
2014-06-25 21:08:00 +00:00
|
|
|
, loops
|
2014-07-17 15:38:23 +00:00
|
|
|
, HUMANIZE(stats.min)
|
|
|
|
, HUMANIZE(stats.median)
|
|
|
|
, HUMANIZE(stats.mean)
|
|
|
|
, HUMANIZE(stats.max)
|
2014-06-25 21:08:00 +00:00
|
|
|
, stddev_percent
|
2014-07-11 18:57:07 +00:00
|
|
|
, stats.plot.c_str()
|
2014-06-25 21:08:00 +00:00
|
|
|
, config
|
2014-07-01 15:43:42 +00:00
|
|
|
, bench->getName()
|
2014-06-25 21:08:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-07-01 15:43:42 +00:00
|
|
|
targets.deleteAll();
|
2014-07-15 17:40:19 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2014-07-28 20:48:36 +00:00
|
|
|
if (FLAGS_abandonGpuContext) {
|
2014-08-13 17:46:31 +00:00
|
|
|
gGrFactory->abandonContexts();
|
2014-07-28 20:48:36 +00:00
|
|
|
}
|
|
|
|
if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
|
2014-08-13 17:46:31 +00:00
|
|
|
gGrFactory->destroyContexts();
|
2014-07-15 17:40:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
2014-07-22 17:15:34 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
return nanobench_main();
|
2014-06-25 21:08:00 +00:00
|
|
|
}
|
|
|
|
#endif
|