2015-09-08 14:08:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "VisualLightweightBenchModule.h"
|
|
|
|
|
|
|
|
#include "ProcStats.h"
|
|
|
|
#include "SkApplication.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkGr.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "Stats.h"
|
|
|
|
#include "gl/GrGLInterface.h"
|
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
// Between samples we reset context
|
|
|
|
// Between frames we swap buffers
|
|
|
|
DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
|
|
|
|
DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
|
2015-09-15 20:29:20 +00:00
|
|
|
DEFINE_string(key, "",
|
|
|
|
"Space-separated key/value pairs to add to JSON identifying this builder.");
|
2015-09-08 14:08:11 +00:00
|
|
|
DEFINE_string(properties, "",
|
|
|
|
"Space-separated key/value pairs to add to JSON identifying this run.");
|
2015-10-05 14:23:30 +00:00
|
|
|
DEFINE_int32(samples, 10, "Number of times to time each skp.");
|
2015-09-08 14:08:11 +00:00
|
|
|
|
|
|
|
static SkString humanize(double ms) {
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
|
|
|
|
}
|
|
|
|
return HumanizeMs(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HUMANIZE(time) humanize(time).c_str()
|
|
|
|
|
|
|
|
VisualLightweightBenchModule::VisualLightweightBenchModule(VisualBench* owner)
|
2015-10-14 14:49:28 +00:00
|
|
|
: INHERITED(owner, true)
|
|
|
|
, fCurrentSample(0)
|
2015-09-08 14:08:11 +00:00
|
|
|
, fResults(new ResultsWriter) {
|
|
|
|
// Print header
|
2015-09-24 15:08:23 +00:00
|
|
|
SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tbench\n", FLAGS_samples,
|
|
|
|
"samples");
|
2015-09-08 14:08:11 +00:00
|
|
|
|
|
|
|
// setup json logging if required
|
|
|
|
if (!FLAGS_outResultsFile.isEmpty()) {
|
|
|
|
fResults.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0]));
|
|
|
|
}
|
|
|
|
|
2015-09-15 20:29:20 +00:00
|
|
|
if (1 == FLAGS_key.count() % 2) {
|
|
|
|
SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
|
|
|
|
} else {
|
|
|
|
for (int i = 1; i < FLAGS_key.count(); i += 2) {
|
|
|
|
fResults->key(FLAGS_key[i - 1], FLAGS_key[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-08 14:08:11 +00:00
|
|
|
if (1 == FLAGS_properties.count() % 2) {
|
|
|
|
SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
|
|
|
|
} else {
|
|
|
|
for (int i = 1; i < FLAGS_properties.count(); i += 2) {
|
|
|
|
fResults->property(FLAGS_properties[i - 1], FLAGS_properties[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 14:49:28 +00:00
|
|
|
|
|
|
|
// seed an initial record
|
|
|
|
fRecords.push_back();
|
2015-09-08 14:08:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 14:49:28 +00:00
|
|
|
void VisualLightweightBenchModule::renderFrame(SkCanvas* canvas, Benchmark* benchmark, int loops) {
|
|
|
|
benchmark->draw(loops, canvas);
|
2015-09-08 14:08:11 +00:00
|
|
|
canvas->flush();
|
|
|
|
}
|
|
|
|
|
2015-10-14 14:49:28 +00:00
|
|
|
void VisualLightweightBenchModule::printStats(Benchmark* benchmark, int loops) {
|
2015-09-08 14:08:11 +00:00
|
|
|
const SkTArray<double>& measurements = fRecords.back().fMeasurements;
|
2015-10-14 14:49:28 +00:00
|
|
|
const char* shortName = benchmark->getUniqueName();
|
2015-09-08 14:08:11 +00:00
|
|
|
|
|
|
|
// update log
|
|
|
|
// Note: We currently log only the minimum. It would be interesting to log more information
|
|
|
|
SkString configName;
|
|
|
|
if (FLAGS_msaa > 0) {
|
|
|
|
configName.appendf("msaa_%d", FLAGS_msaa);
|
|
|
|
} else {
|
|
|
|
configName.appendf("gpu");
|
|
|
|
}
|
2015-10-14 14:49:28 +00:00
|
|
|
// Log bench name
|
|
|
|
fResults->bench(shortName, benchmark->getSize().fX, benchmark->getSize().fY);
|
|
|
|
|
2015-09-08 14:08:11 +00:00
|
|
|
fResults->config(configName.c_str());
|
2015-09-24 15:08:23 +00:00
|
|
|
fResults->configOption("name", shortName);
|
2015-09-08 14:08:11 +00:00
|
|
|
SkASSERT(measurements.count());
|
|
|
|
Stats stats(measurements);
|
2015-09-24 15:08:23 +00:00
|
|
|
fResults->metric("min_ms", stats.min);
|
2015-09-08 14:08:11 +00:00
|
|
|
|
|
|
|
// Print output
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
for (int i = 0; i < measurements.count(); i++) {
|
|
|
|
SkDebugf("%s ", HUMANIZE(measurements[i]));
|
|
|
|
}
|
|
|
|
SkDebugf("%s\n", shortName);
|
|
|
|
} else {
|
|
|
|
const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean;
|
2015-09-24 15:08:23 +00:00
|
|
|
SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\n",
|
2015-09-08 14:08:11 +00:00
|
|
|
sk_tools::getCurrResidentSetSizeMB(),
|
|
|
|
sk_tools::getMaxResidentSetSizeMB(),
|
2015-10-14 14:49:28 +00:00
|
|
|
loops,
|
2015-09-08 14:08:11 +00:00
|
|
|
HUMANIZE(stats.min),
|
|
|
|
HUMANIZE(stats.median),
|
|
|
|
HUMANIZE(stats.mean),
|
|
|
|
HUMANIZE(stats.max),
|
|
|
|
stdDevPercent,
|
2015-09-24 15:08:23 +00:00
|
|
|
stats.plot.c_str(),
|
2015-09-08 14:08:11 +00:00
|
|
|
shortName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 14:49:28 +00:00
|
|
|
bool VisualLightweightBenchModule::timingFinished(Benchmark* benchmark, int loops,
|
|
|
|
double measurement) {
|
|
|
|
fRecords.back().fMeasurements.push_back(measurement);
|
|
|
|
if (++fCurrentSample > FLAGS_samples) {
|
|
|
|
this->printStats(benchmark, loops);
|
|
|
|
fRecords.push_back();
|
|
|
|
fCurrentSample = 0;
|
2015-09-08 14:08:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-14 14:49:28 +00:00
|
|
|
return false;
|
2015-09-08 14:08:11 +00:00
|
|
|
}
|
2015-09-15 14:40:56 +00:00
|
|
|
|
|
|
|
bool VisualLightweightBenchModule::onHandleChar(SkUnichar c) {
|
|
|
|
return true;
|
|
|
|
}
|