#include "SkStream.h"
#include "SkString.h"
+template <typename T> const T& Min(const T& a, const T& b) {
+ return (a < b) ? a : b;
+}
+
class SkBenchLogger {
public:
SkBenchLogger() : fFileStream(NULL) {}
static void help() {
SkDebugf("Usage: bench [-o outDir] [-repeat nr] [-logPerIter 1|0] "
"[-timers [wcg]*] [-rotate]\n"
- " [-scale] [-clip] [-forceAA 1|0] [-forceFilter 1|0]\n"
+ " [-scale] [-clip] [-min] [-forceAA 1|0] [-forceFilter 1|0]\n"
" [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n"
" [-match name] [-mode normal|deferred|record|picturerecord]\n"
" [-config 8888|565|GPU|ANGLE|NULLGPU] [-Dfoo bar]\n"
SkDebugf(" -rotate : Rotate before each bench runs.\n");
SkDebugf(" -scale : Scale before each bench runs.\n");
SkDebugf(" -clip : Clip before each bench runs.\n");
+ SkDebugf(" -min : Print the minimum times (instead of average).\n");
SkDebugf(" -forceAA 1|0 : "
"Enable/disable anti-aliased, default is enabled.\n");
SkDebugf(" -forceFilter 1|0 : "
bool doScale = false;
bool doRotate = false;
bool doClip = false;
+ bool printMin = false;
bool hasStrokeWidth = false;
float strokeWidth;
SkTDArray<const char*> fMatches;
doScale = true;
} else if (!strcmp(*argv, "-clip")) {
doClip = true;
+ } else if (!strcmp(*argv, "-min")) {
+ printMin = true;
} else if (strcmp(*argv, "-forceAA") == 0) {
if (!parse_bool_arg(++argv, stop, &forceAA)) {
logger.logError("missing arg for -forceAA\n");
"deferred=%d logperiter=%d",
forceAlpha, forceAA, forceFilter, benchMode == kDeferred_benchModes,
logPerIter);
- str.appendf(" rotate=%d scale=%d clip=%d",
- doRotate, doScale, doClip);
+ str.appendf(" rotate=%d scale=%d clip=%d min=%d",
+ doRotate, doScale, doClip, printMin);
str.appendf(" record=%d picturerecord=%d",
benchMode == kRecord_benchModes,
benchMode == kPictureRecord_benchModes);
SkString fWallStr(" msecs = ");
SkString fCpuStr(" cmsecs = ");
SkString fGpuStr(" gmsecs = ");
- double fWallSum = 0.0;
- double fCpuSum = 0.0;
- double fGpuSum = 0.0;
+ double fWallSum = 0.0, fWallMin;
+ double fCpuSum = 0.0, fCpuMin;
+ double fGpuSum = 0.0, fGpuMin;
for (int i = 0; i < repeatDraw; i++) {
if ((benchMode == kRecord_benchModes
|| benchMode == kPictureRecord_benchModes)) {
fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu);
fGpuStr.appendf(",");
}
+
+ if (0 == i) {
+ fWallMin = timer.fWall;
+ fCpuMin = timer.fCpu;
+ fGpuMin = timer.fGpu;
+ } else {
+ fWallMin = Min(fWallMin, timer.fWall);
+ fCpuMin = Min(fCpuMin, timer.fCpu);
+ fGpuMin = Min(fGpuMin, timer.fGpu);
+ }
+
fWallSum += timer.fWall;
fCpuSum += timer.fCpu;
fGpuSum += timer.fGpu;
// otherwise output only the average
if (!logPerIter) {
fWallStr.set(" msecs = ");
- fWallStr.appendf(normalTimeFormat.c_str(), fWallSum / repeatDraw);
+ fWallStr.appendf(normalTimeFormat.c_str(),
+ printMin ? fWallMin : fWallSum / repeatDraw);
fCpuStr.set(" cmsecs = ");
- fCpuStr.appendf(normalTimeFormat.c_str(), fCpuSum / repeatDraw);
+ fCpuStr.appendf(normalTimeFormat.c_str(),
+ printMin ? fCpuMin : fCpuSum / repeatDraw);
fGpuStr.set(" gmsecs = ");
- fGpuStr.appendf(normalTimeFormat.c_str(), fGpuSum / repeatDraw);
+ fGpuStr.appendf(normalTimeFormat.c_str(),
+ printMin ? fGpuMin : fGpuSum / repeatDraw);
}
SkString str;
str.printf(" %4s:", configName);