Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: tools/PictureResultsWriter.h

Issue 286903025: PictureBenchmark JSON logging (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Switch JSON styles from styled to fast Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/PictureResultsWriter.h
diff --git a/tools/PictureResultsWriter.h b/tools/PictureResultsWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..1c1850645f3a8c335760e01eecd9a1de0cc54295
--- /dev/null
+++ b/tools/PictureResultsWriter.h
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Classes for writing out bench results in various formats.
+ */
+#ifndef SkPictureResultsWriter_DEFINED
+#define SkPictureResultsWriter_DEFINED
+
+#include "SkBenchLogger.h"
+#include "SkJSONCPP.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkTArray.h"
+
+/**
+ * Base class for writing picture bench results.
+ */
+class PictureResultsWriter : SkNoncopyable {
+protected:
+ Json::Value* find_named_node(Json::Value* root, const char name[]) {
jcgregorio 2014/05/27 15:34:25 Why is find_named_node duplicated here?
kelvinly 2014/05/27 16:41:06 I guess I copy and pasted from ResultsWriter, and
+ 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;
+ }
+ }
+
+public:
+ enum TileFlags {kPurging, kAvg};
+
+ PictureResultsWriter() {;}
+ virtual ~PictureResultsWriter() {;}
+
+ virtual void bench(const char name[], int32_t x, int32_t y) = 0;
+ virtual void tileConfig(SkString configName) = 0;
+ virtual void tileMeta(int x, int y, int tx, int ty) = 0;
+ virtual void addTileFlag(PictureResultsWriter::TileFlags flag) = 0;
+ virtual void tileData(
+ TimerData* data,
+ const char format[],
+ const TimerData::Result result,
+ uint32_t timerTypes,
+ int numInnerLoops = 1) = 0;
+ virtual void end() = 0;
+};
+
+class PictureResultsMultiWriter : public PictureResultsWriter {
+public:
+ PictureResultsMultiWriter() : writers() {;}
+ void add(PictureResultsWriter* newWriter) {
+ writers.push_back(newWriter);
+ }
+ virtual ~PictureResultsMultiWriter() {;}
+ virtual void bench(const char name[], int32_t x, int32_t y) {
+ for(int i=0; i<writers.count(); ++i) {
+ writers[i]->bench(name, x, y);
+ }
+ }
+ virtual void tileConfig(SkString configName) {
+ for(int i=0; i<writers.count(); ++i) {
+ writers[i]->tileConfig(configName);
+ }
+ }
+ virtual void tileMeta(int x, int y, int tx, int ty) {
+ for(int i=0; i<writers.count(); ++i) {
+ writers[i]->tileMeta(x, y, tx, ty);
+ }
+ }
+ virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
+ for(int i=0; i<writers.count(); ++i) {
+ writers[i]->addTileFlag(flag);
+ }
+ }
+ virtual void tileData(
+ TimerData* data,
+ const char format[],
+ const TimerData::Result result,
+ uint32_t timerTypes,
+ int numInnerLoops = 1) {
+ for(int i=0; i<writers.count(); ++i) {
+ writers[i]->tileData(data, format, result, timerTypes,
+ numInnerLoops);
+ }
+ }
+ virtual void end() {
+ for(int i=0; i<writers.count(); ++i) {
+ writers[i]->end();
+ }
+ }
+private:
+ SkTArray<PictureResultsWriter*> writers;
+};
+
+/**
+ * Writes to SkBenchLogger to mimic original behavior
+ */
+class PictureResultsLoggerWriter : public PictureResultsWriter {
+private:
+ void logProgress(const char str[]) {
+ if(fLogger != NULL) {
+ fLogger->logProgress(str);
+ }
+ }
+public:
+ PictureResultsLoggerWriter(SkBenchLogger* log)
+ : fLogger(log), currentLine() {;}
+ virtual void bench(const char name[], int32_t x, int32_t y) {
+ SkString result;
+ result.printf("running bench [%i %i] %s ", x, y, name);
+ this->logProgress(result.c_str());
+ }
+ virtual void tileConfig(SkString configName) {
+ currentLine = configName;
+ }
+ virtual void tileMeta(int x, int y, int tx, int ty) {
+ currentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty);
+ }
+ virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
+ if(flag == PictureResultsWriter::kPurging) {
+ currentLine.append(" <withPurging>");
+ } else if(flag == PictureResultsWriter::kAvg) {
+ currentLine.append(" <averaged>");
+ }
+ }
+ virtual void tileData(
+ TimerData* data,
+ const char format[],
+ const TimerData::Result result,
+ uint32_t timerTypes,
+ int numInnerLoops = 1) {
+ SkString results = data->getResult(format, result,
+ currentLine.c_str(), timerTypes, numInnerLoops);
+ results.append("\n");
+ this->logProgress(results.c_str());
+ }
+ virtual void end() {;}
+private:
+ SkBenchLogger* fLogger;
+ SkString currentLine;
+};
+
+#ifdef SK_BUILD_JSON_WRITER
+/**
+ * This ResultsWriter collects data in a JSON node
+ */
+class PictureJSONResultsWriter : public PictureResultsWriter {
+public:
+ PictureJSONResultsWriter(const char filename[])
+ : fFilename(filename),
+ fRoot(),
+ fCurrentBench(NULL),
+ fCurrentTileSet(NULL),
+ fCurrentTile(NULL) {;}
+
+ virtual void bench(const char name[], int32_t x, int32_t y) {
+ SkString sk_name(name);
+ sk_name.append("_");
+ sk_name.appendS32(x);
+ sk_name.append("_");
+ sk_name.appendS32(y);
+ Json::Value* bench_node = find_named_node(&fRoot["benches"], sk_name.c_str());
+ fCurrentBench = &(*bench_node)["tileSets"];
+ }
+ virtual void tileConfig(SkString configName) {
+ SkASSERT(fCurrentBench != NULL);
+ fCurrentTileSet = find_named_node(fCurrentBench, configName.c_str());
+ fCurrentTile = &(*fCurrentTileSet)["tiles"][0];
+ }
+ virtual void tileMeta(int x, int y, int tx, int ty) {
+ SkASSERT(fCurrentTileSet != NULL);
+ (*fCurrentTileSet)["tx"] = tx;
+ (*fCurrentTileSet)["ty"] = ty;
+ fCurrentTile = &(*fCurrentTileSet)["tiles"][x+tx*y];
+ }
+ virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
+ SkASSERT(fCurrentTile != NULL);
+ if(flag == PictureResultsWriter::kPurging) {
+ (*fCurrentTile)["flags"]["purging"] = true;
+ } else if(flag == PictureResultsWriter::kAvg) {
+ (*fCurrentTile)["flags"]["averaged"] = true;
+ }
+ }
+ virtual void tileData(
+ TimerData* data,
+ const char format[],
+ const TimerData::Result result,
+ uint32_t timerTypes,
+ int numInnerLoops = 1) {
+ SkASSERT(fCurrentTile != NULL);
+ (*fCurrentTile)["data"] = data->getJSON(timerTypes, result, numInnerLoops);
+ }
+ virtual void end() {
+ SkFILEWStream stream(fFilename.c_str());
+ stream.writeText(Json::FastWriter().write(fRoot).c_str());
+ stream.flush();
+ }
+private:
+ SkString fFilename;
+ Json::Value fRoot;
+ Json::Value *fCurrentBench;
+ Json::Value *fCurrentTileSet;
+ Json::Value *fCurrentTile;
+};
+#endif // SK_BUILD_JSON_WRITER
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698