Report data from bench_pictures in the same fashion as bench.
Move SkBenchLogger into separate files and make bench_pictures use it.
Remove sk_tools::print_msg, since SkBenchLogger is now used instead.
Combine picture_benchmark with bench_pictures, since that is the
only project that uses it.
Refactor the aggregator for bench timer data into its own class and
make bench_pictures use it.
Consolidate the various virtual PictureBenchmark::run functions
into one for reuse.
BUG=https://code.google.com/p/skia/issues/detail?id=822
Review URL: https://codereview.appspot.com/6488086
git-svn-id: http://skia.googlecode.com/svn/trunk@5432 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/TimerData.cpp b/bench/TimerData.cpp
new file mode 100644
index 0000000..3b4baac
--- /dev/null
+++ b/bench/TimerData.cpp
@@ -0,0 +1,108 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "TimerData.h"
+
+#include "BenchTimer.h"
+#include <limits>
+
+using namespace std;
+
+TimerData::TimerData(const SkString& perIterTimeFormat, const SkString& normalTimeFormat)
+: fWallStr(" msecs = ")
+, fTruncatedWallStr(" Wmsecs = ")
+, fCpuStr(" cmsecs = ")
+, fTruncatedCpuStr(" Cmsecs = ")
+, fGpuStr(" gmsecs = ")
+, fWallSum(0.0)
+, fWallMin(numeric_limits<double>::max())
+, fTruncatedWallSum(0.0)
+, fTruncatedWallMin(numeric_limits<double>::max())
+, fCpuSum(0.0)
+, fCpuMin(numeric_limits<double>::max())
+, fTruncatedCpuSum(0.0)
+, fTruncatedCpuMin(numeric_limits<double>::max())
+, fGpuSum(0.0)
+, fGpuMin(numeric_limits<double>::max())
+, fPerIterTimeFormat(perIterTimeFormat)
+, fNormalTimeFormat(normalTimeFormat)
+{}
+
+static double Min(double a, double b) {
+ return (a < b) ? a : b;
+}
+
+void TimerData::appendTimes(BenchTimer* timer, bool last) {
+ SkASSERT(timer != NULL);
+ SkString formatString(fPerIterTimeFormat);
+ if (!last) {
+ formatString.append(",");
+ }
+ const char* format = formatString.c_str();
+ fWallStr.appendf(format, timer->fWall);
+ fCpuStr.appendf(format, timer->fCpu);
+ fTruncatedWallStr.appendf(format, timer->fTruncatedWall);
+ fTruncatedCpuStr.appendf(format, timer->fTruncatedCpu);
+ fGpuStr.appendf(format, timer->fGpu);
+
+ // Store the minimum values. We do not need to special case the first time since we initialized
+ // to max double.
+ fWallMin = Min(fWallMin, timer->fWall);
+ fCpuMin = Min(fCpuMin, timer->fCpu);
+ fTruncatedWallMin = Min(fTruncatedWallMin, timer->fTruncatedWall);
+ fTruncatedCpuMin = Min(fTruncatedCpuMin, timer->fTruncatedCpu);
+ fGpuMin = Min(fGpuMin, timer->fGpu);
+
+ // Tally the sum of each timer type.
+ fWallSum += timer->fWall;
+ fCpuSum += timer->fCpu;
+ fTruncatedWallSum += timer->fTruncatedWall;
+ fTruncatedCpuSum += timer->fTruncatedCpu;
+ fGpuSum += timer->fGpu;
+
+}
+
+SkString TimerData::getResult(bool logPerIter, bool printMin, int repeatDraw,
+ const char *configName, bool showWallTime, bool showTruncatedWallTime,
+ bool showCpuTime, bool showTruncatedCpuTime, bool showGpuTime) {
+ // output each repeat (no average) if logPerIter is set,
+ // otherwise output only the average
+ if (!logPerIter) {
+ const char* format = fNormalTimeFormat.c_str();
+ fWallStr.set(" msecs = ");
+ fWallStr.appendf(format, printMin ? fWallMin : fWallSum / repeatDraw);
+ fCpuStr.set(" cmsecs = ");
+ fCpuStr.appendf(format, printMin ? fCpuMin : fCpuSum / repeatDraw);
+ fTruncatedWallStr.set(" Wmsecs = ");
+ fTruncatedWallStr.appendf(format,
+ printMin ? fTruncatedWallMin : fTruncatedWallSum / repeatDraw);
+ fTruncatedCpuStr.set(" Cmsecs = ");
+ fTruncatedCpuStr.appendf(format,
+ printMin ? fTruncatedCpuMin : fTruncatedCpuSum / repeatDraw);
+ fGpuStr.set(" gmsecs = ");
+ fGpuStr.appendf(format, printMin ? fGpuMin : fGpuSum / repeatDraw);
+ }
+ SkString str;
+ str.printf(" %4s:", configName);
+ if (showWallTime) {
+ str += fWallStr;
+ }
+ if (showTruncatedWallTime) {
+ str += fTruncatedWallStr;
+ }
+ if (showCpuTime) {
+ str += fCpuStr;
+ }
+ if (showTruncatedCpuTime) {
+ str += fTruncatedCpuStr;
+ }
+ if (showGpuTime && fGpuSum > 0) {
+ str += fGpuStr;
+ }
+ return str;
+}