Index: tools/kilobench/kilobench.cpp |
diff --git a/tools/kilobench/kilobench.cpp b/tools/kilobench/kilobench.cpp |
index 438e582324fb2e8c97f1da061e7d9a3f8760d870..940e3cc213a0b2696de0c5b63a364c4bd7e1c2e6 100644 |
--- a/tools/kilobench/kilobench.cpp |
+++ b/tools/kilobench/kilobench.cpp |
@@ -62,6 +62,11 @@ DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str()); |
DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs."); |
+DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
+DEFINE_string(key, "", |
+ "Space-separated key/value pairs to add to JSON identifying this builder."); |
+DEFINE_string(properties, "", |
+ "Space-separated key/value pairs to add to JSON identifying this run."); |
namespace kilobench { |
class BenchmarkStream { |
@@ -327,7 +332,7 @@ static SkString humanize(double ms) { |
} |
#define HUMANIZE(ms) humanize(ms).c_str() |
-void benchmark_inner_loop(Benchmark* bench, GrContextFactory* ctxFactory) { |
+void benchmark_inner_loop(Benchmark* bench, GrContextFactory* ctxFactory, ResultsWriter* log) { |
SkTArray<double> samples; |
GPUTarget target; |
SkAssertResult(target.init(bench, ctxFactory, false, |
@@ -369,16 +374,48 @@ void benchmark_inner_loop(Benchmark* bench, GrContextFactory* ctxFactory) { |
pngFilename.append(".png"); |
write_canvas_png(&target, pngFilename); |
} |
+ |
+ log->config("gpu"); |
+ log->configOption("name", bench->getName()); |
+ log->metric("min_ms", stats.min); |
+ log->metric("median_ms", stats.median); |
} |
} // namespace kilobench |
+static ResultsWriter* setup_log() { |
+ ResultsWriter* log; |
+ if (!FLAGS_outResultsFile.isEmpty()) { |
+ log = new NanoJSONResultsWriter(FLAGS_outResultsFile[0]); |
+ } else { |
+ log = new ResultsWriter; |
+ } |
+ |
+ 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]); |
+ } |
+ return log; |
+} |
int kilobench_main() { |
SkAutoTDelete<GrContextFactory> ctxFactory; |
GrContextOptions grContextOpts; |
ctxFactory.reset(new GrContextFactory(grContextOpts)); |
+ SkAutoTDelete<ResultsWriter> log(setup_log()); |
+ |
kilobench::BenchmarkStream benchStream; |
SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |