diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-29 17:10:24 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-29 17:10:24 +0000 |
commit | 37c772ae2d96dad9b6e430e9bb6450193a545021 (patch) | |
tree | 43425ca5faeaff32d35f0b1353d075b6dfaef3ec /bench | |
parent | 6ee7a0903f42cf4072126bae371c35839c9d0ce4 (diff) |
BUG=skia:
R=bensong@google.com, epoger@google.com
Author: kelvinly@google.com
Review URL: https://codereview.chromium.org/304613002
git-svn-id: http://skia.googlecode.com/svn/trunk@14966 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r-- | bench/ResultsWriter.cpp | 33 | ||||
-rw-r--r-- | bench/ResultsWriter.h | 26 | ||||
-rw-r--r-- | bench/TimerData.cpp | 86 | ||||
-rw-r--r-- | bench/TimerData.h | 15 |
4 files changed, 138 insertions, 22 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..ba682f0e24 100644 --- a/bench/TimerData.cpp +++ b/bench/TimerData.cpp @@ -5,7 +5,6 @@ * 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" @@ -140,3 +139,88 @@ SkString TimerData::getResult(const char* doubleFormat, } return str; } + +#ifdef SK_BUILD_JSON_WRITER +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; +} +#endif // SK_BUILD_JSON_WRITER diff --git a/bench/TimerData.h b/bench/TimerData.h index ed0ee473c1..8f6a7194ab 100644 --- a/bench/TimerData.h +++ b/bench/TimerData.h @@ -12,6 +12,16 @@ #include "SkString.h" #include "SkTemplates.h" +#ifdef SK_BUILD_FOR_WIN + #pragma warning(push) + #pragma warning(disable : 4530) +#endif + +#include "SkJSONCPP.h" + +#ifdef SK_BUILD_FOR_WIN + #pragma warning(pop) +#endif class BenchTimer; @@ -58,6 +68,11 @@ public: const char* configName, uint32_t timerFlags, int itersPerTiming = 1); +#ifdef SK_BUILD_JSON_WRITER + Json::Value getJSON(uint32_t timerFlags, + Result result, + int itersPerTiming = 1); +#endif // SK_BUILD_JSON_WRITER private: int fMaxNumTimings; |