aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-27 20:57:44 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-27 20:57:44 +0000
commit3089004cc88e919526e43a8122a74db8f0a7790b (patch)
tree2955a280e1fcc3c2c3ede19f673434c5c45281e9 /bench
parent44f41293ac94530d08fca2ce8484a7248e7a5e97 (diff)
Add JSON logging support to bench_pictures by adding a PictureResultsWriter class (in tools/PictureResultsWriter.h) to process logging information, using a very similar style as bench/ResultsWriter.h
JSON format described in code, above PictureJSONResultsWriter class BUG=skia: R=bensong@google.com, jcgregorio@google.com Author: kelvinly@google.com Review URL: https://codereview.chromium.org/286903025 git-svn-id: http://skia.googlecode.com/svn/trunk@14906 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r--bench/ResultsWriter.cpp33
-rw-r--r--bench/ResultsWriter.h26
-rw-r--r--bench/TimerData.cpp83
-rw-r--r--bench/TimerData.h4
4 files changed, 125 insertions, 21 deletions
diff --git a/bench/ResultsWriter.cpp b/bench/ResultsWriter.cpp
new file mode 100644
index 0000000000..0bfcba8b1e
--- /dev/null
+++ b/bench/ResultsWriter.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Helper functions for result writing operations.
+ */
+
+#include "ResultsWriter.h"
+
+#ifdef SK_BUILD_JSON_WRITER
+
+Json::Value* SkFindNamedNode(Json::Value* root, const char name[]) {
+ Json::Value* search_results = NULL;
+ for(Json::Value::iterator iter = root->begin();
+ iter!= root->end(); ++iter) {
+ if(SkString(name).equals((*iter)["name"].asCString())) {
+ search_results = &(*iter);
+ break;
+ }
+ }
+
+ if(search_results != NULL) {
+ return search_results;
+ } else {
+ Json::Value* new_val = &(root->append(Json::Value()));
+ (*new_val)["name"] = name;
+ return new_val;
+ }
+}
+
+#endif // SK_BUILD_JSON_WRITER
diff --git a/bench/ResultsWriter.h b/bench/ResultsWriter.h
index a9eef802bd..c66593864f 100644
--- a/bench/ResultsWriter.h
+++ b/bench/ResultsWriter.h
@@ -101,26 +101,9 @@ private:
* },
* ...
*/
-class JSONResultsWriter : public ResultsWriter {
-private:
- Json::Value* find_named_node(Json::Value* root, const char name[]) {
- Json::Value* search_results = NULL;
- for(Json::Value::iterator iter = root->begin();
- iter!= root->end(); ++iter) {
- if(SkString(name).equals((*iter)["name"].asCString())) {
- search_results = &(*iter);
- break;
- }
- }
- if(search_results != NULL) {
- return search_results;
- } else {
- Json::Value* new_val = &(root->append(Json::Value()));
- (*new_val)["name"] = name;
- return new_val;
- }
- }
+Json::Value* SkFindNamedNode(Json::Value* root, const char name[]);
+class JSONResultsWriter : public ResultsWriter {
public:
explicit JSONResultsWriter(const char filename[])
: fFilename(filename)
@@ -138,12 +121,12 @@ public:
sk_name.appendS32(x);
sk_name.append("_");
sk_name.appendS32(y);
- Json::Value* bench_node = find_named_node(&fResults, sk_name.c_str());
+ Json::Value* bench_node = SkFindNamedNode(&fResults, sk_name.c_str());
fBench = &(*bench_node)["results"];
}
virtual void config(const char name[]) {
SkASSERT(NULL != fBench);
- fConfig = find_named_node(fBench, name);
+ fConfig = SkFindNamedNode(fBench, name);
}
virtual void timer(const char name[], double ms) {
SkASSERT(NULL != fConfig);
@@ -164,6 +147,7 @@ private:
};
#endif // SK_BUILD_JSON_WRITER
+
/**
* This ResultsWriter writes out to multiple ResultsWriters.
*/
diff --git a/bench/TimerData.cpp b/bench/TimerData.cpp
index a86f29394f..f72319e761 100644
--- a/bench/TimerData.cpp
+++ b/bench/TimerData.cpp
@@ -140,3 +140,86 @@ SkString TimerData::getResult(const char* doubleFormat,
}
return str;
}
+
+Json::Value TimerData::getJSON(uint32_t timerFlags,
+ Result result,
+ int itersPerTiming) {
+ SkASSERT(itersPerTiming >= 1);
+ Json::Value dataNode;
+ Json::Value wallNode, truncWall, cpuNode, truncCpu, gpuNode;
+ if (!fCurrTiming) {
+ return dataNode;
+ }
+
+ int numTimings = fCurrTiming;
+
+ double wallMin = std::numeric_limits<double>::max();
+ double truncWallMin = std::numeric_limits<double>::max();
+ double cpuMin = std::numeric_limits<double>::max();
+ double truncCpuMin = std::numeric_limits<double>::max();
+ double gpuMin = std::numeric_limits<double>::max();
+
+ double wallSum = 0;
+ double truncWallSum = 0;
+ double cpuSum = 0;
+ double truncCpuSum = 0;
+ double gpuSum = 0;
+
+ for (int i = 0; i < numTimings; ++i) {
+ if (kPerIter_Result == result) {
+ wallNode.append(fWallTimes[i] / itersPerTiming);
+ truncWall.append(fTruncatedWallTimes[i] / itersPerTiming);
+ cpuNode.append(fCpuTimes[i] / itersPerTiming);
+ truncCpu.append(fTruncatedCpuTimes[i] / itersPerTiming);
+ gpuNode.append(fGpuTimes[i] / itersPerTiming);
+ } else if (kMin_Result == result) {
+ wallMin = SkTMin(wallMin, fWallTimes[i]);
+ truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]);
+ cpuMin = SkTMin(cpuMin, fCpuTimes[i]);
+ truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]);
+ gpuMin = SkTMin(gpuMin, fGpuTimes[i]);
+ } else {
+ SkASSERT(kAvg_Result == result);
+ wallSum += fWallTimes[i];
+ truncWallSum += fTruncatedWallTimes[i];
+ cpuSum += fCpuTimes[i];
+ truncCpuSum += fTruncatedCpuTimes[i];
+ }
+
+ // We always track the GPU sum because whether it is non-zero indicates if valid gpu times
+ // were recorded at all.
+ gpuSum += fGpuTimes[i];
+ }
+
+ if (kMin_Result == result) {
+ wallNode.append(wallMin / itersPerTiming);
+ truncWall.append(truncWallMin / itersPerTiming);
+ cpuNode.append(cpuMin / itersPerTiming);
+ truncCpu.append(truncCpuMin / itersPerTiming);
+ gpuNode.append(gpuMin / itersPerTiming);
+ } else if (kAvg_Result == result) {
+ int divisor = numTimings * itersPerTiming;
+ wallNode.append(wallSum / divisor);
+ truncWall.append(truncWallSum / divisor);
+ cpuNode.append(cpuSum / divisor);
+ truncCpu.append(truncCpuSum / divisor);
+ gpuNode.append(gpuSum / divisor);
+ }
+
+ if (timerFlags & kWall_Flag) {
+ dataNode["wall"] = wallNode;
+ }
+ if (timerFlags & kTruncatedWall_Flag) {
+ dataNode["truncWall"] = truncWall;
+ }
+ if (timerFlags & kCpu_Flag) {
+ dataNode["cpu"] = cpuNode;
+ }
+ if (timerFlags & kTruncatedCpu_Flag) {
+ dataNode["trucCpu"] = truncCpu;
+ }
+ if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
+ dataNode["gpu"] = gpuNode;
+ }
+ return dataNode;
+}
diff --git a/bench/TimerData.h b/bench/TimerData.h
index ed0ee473c1..50539c7522 100644
--- a/bench/TimerData.h
+++ b/bench/TimerData.h
@@ -9,6 +9,7 @@
#ifndef TimerData_DEFINED
#define TimerData_DEFINED
+#include "SkJSONCPP.h"
#include "SkString.h"
#include "SkTemplates.h"
@@ -58,6 +59,9 @@ public:
const char* configName,
uint32_t timerFlags,
int itersPerTiming = 1);
+ Json::Value getJSON(uint32_t timerFlags,
+ Result result,
+ int itersPerTiming = 1);
private:
int fMaxNumTimings;