Index: bench/ResultsWriter.h |
diff --git a/bench/ResultsWriter.h b/bench/ResultsWriter.h |
index dc45f192f5eecfba97ee21d7ca50d044f249313a..56283732ec020f23f39a73d46a2f81d388d96d95 100644 |
--- a/bench/ResultsWriter.h |
+++ b/bench/ResultsWriter.h |
@@ -20,148 +20,31 @@ |
/** |
* Base class for writing out the bench results. |
* |
- * TODO(jcgregorio) Add info if tests fail to converge? |
+ * Default implementation does nothing. |
*/ |
class ResultsWriter : SkNoncopyable { |
public: |
- virtual ~ResultsWriter() {}; |
+ virtual ~ResultsWriter() {} |
- // Records one key value pair that makes up a unique identifier for this run. |
- // All keys must be set before calling bench(). |
- virtual void key(const char name[], const char value[]) = 0; |
+ // Record one key value pair that makes up a unique key for this type of run, e.g. |
+ // builder name, machine type, Debug/Release, etc. |
+ virtual void key(const char name[], const char value[]) {} |
- // Records one option set for this run. All options must be set before |
- // calling bench(). |
- virtual void option(const char name[], const char value[]) = 0; |
+ // Record one key value pair that describes the run instance, e.g. git hash, build number. |
+ virtual void property(const char name[], const char value[]) {} |
- // Denotes the start of a specific benchmark. Once bench is called, |
+ // Denote the start of a specific benchmark. Once bench is called, |
// then config and timer can be called multiple times to record runs. |
- virtual void bench(const char name[], int32_t x, int32_t y) = 0; |
+ virtual void bench(const char name[], int32_t x, int32_t y) {} |
- // Records the specific configuration a bench is run under, such as "8888". |
- virtual void config(const char name[]) = 0; |
+ // Record the specific configuration a bench is run under, such as "8888". |
+ virtual void config(const char name[]) {} |
- // Records the options for a configuration, such as "GL_RENDERER". |
- virtual void configOption(const char name[], const char* value) = 0; |
+ // Record the options for a configuration, such as "GL_RENDERER". |
+ virtual void configOption(const char name[], const char* value) {} |
- // Records a single test metric. |
- virtual void timer(const char name[], double ms) = 0; |
- |
- // Call when all results are finished. |
- virtual void end() = 0; |
-}; |
- |
-/** |
- * This ResultsWriter handles writing out the human readable format of the |
- * bench results. |
- */ |
-class LoggerResultsWriter : public ResultsWriter { |
-public: |
- explicit LoggerResultsWriter(BenchLogger& logger, const char* timeFormat) |
- : fLogger(logger) |
- , fTimeFormat(timeFormat) { |
- fLogger.logProgress("skia bench:"); |
- } |
- virtual void key(const char name[], const char value[]) { |
- // Don't log keys to keep microbench output unchanged. |
- } |
- virtual void option(const char name[], const char value[]) { |
- fLogger.logProgress(SkStringPrintf(" %s=%s", name, value)); |
- } |
- virtual void bench(const char name[], int32_t x, int32_t y) { |
- fLogger.logProgress(SkStringPrintf( |
- "\nrunning bench [%3d %3d] %40s", x, y, name)); |
- } |
- virtual void config(const char name[]) { |
- fLogger.logProgress(SkStringPrintf(" %s:", name)); |
- } |
- virtual void configOption(const char name[], const char* value) { |
- // Don't log configOptions to keep microbench output unchanged. |
- } |
- virtual void timer(const char name[], double ms) { |
- fLogger.logProgress(SkStringPrintf(" %s = ", name)); |
- fLogger.logProgress(SkStringPrintf(fTimeFormat, ms)); |
- } |
- virtual void end() { |
- fLogger.logProgress("\n"); |
- } |
-private: |
- BenchLogger& fLogger; |
- const char* fTimeFormat; |
-}; |
- |
-/** |
- * This ResultsWriter handles writing out the results in JSON. |
- * |
- * The output looks like (except compressed to a single line): |
- * |
- * { |
- * "options" : { |
- * "alpha" : "0xFF", |
- * "scale" : "0", |
- * ... |
- * "system" : "UNIX" |
- * }, |
- * "results" : [ |
- * { |
- * "name" : "Xfermode_Luminosity_640_480", |
- * "results" : [ |
- * { |
- * "name": "565", |
- * "cmsecs" : 143.188128906250, |
- * "msecs" : 143.835957031250 |
- * }, |
- * ... |
- */ |
- |
-Json::Value* SkFindNamedNode(Json::Value* root, const char name[]); |
-Json::Value SkMakeBuilderJSON(const SkString &buildername); |
- |
-class JSONResultsWriter : public ResultsWriter { |
-public: |
- explicit JSONResultsWriter(const char filename[]) |
- : fFilename(filename) |
- , fRoot() |
- , fResults(fRoot["results"]) |
- , fBench(NULL) |
- , fConfig(NULL) { |
- } |
- virtual void key(const char name[], const char value[]) { |
- } |
- virtual void option(const char name[], const char value[]) { |
- fRoot["options"][name] = value; |
- } |
- 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 = SkFindNamedNode(&fResults, sk_name.c_str()); |
- fBench = &(*bench_node)["results"]; |
- } |
- virtual void config(const char name[]) { |
- SkASSERT(NULL != fBench); |
- fConfig = SkFindNamedNode(fBench, name); |
- } |
- virtual void configOption(const char name[], const char* value) { |
- } |
- virtual void timer(const char name[], double ms) { |
- SkASSERT(NULL != fConfig); |
- (*fConfig)[name] = ms; |
- } |
- 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& fResults; |
- Json::Value* fBench; |
- Json::Value* fConfig; |
+ // Record a single test metric. |
+ virtual void timer(const char name[], double ms) {} |
}; |
/** |
@@ -175,11 +58,8 @@ private: |
"os": "Android", |
"model": "GalaxyNexus", |
} |
- "options": { |
- "GL_Version": "3.1", |
- ... |
- }, |
"gitHash": "d1830323662ae8ae06908b97f15180fd25808894", |
+ "build_number": "1234", |
"results" : { |
"Xfermode_Luminosity_640_480" : { |
"8888" : { |
@@ -191,19 +71,26 @@ private: |
*/ |
class NanoJSONResultsWriter : public ResultsWriter { |
public: |
- explicit NanoJSONResultsWriter(const char filename[], const char gitHash[]) |
+ explicit NanoJSONResultsWriter(const char filename[]) |
: fFilename(filename) |
, fRoot() |
, fResults(fRoot["results"]) |
, fBench(NULL) |
- , fConfig(NULL) { |
- fRoot["gitHash"] = gitHash; |
+ , fConfig(NULL) {} |
+ |
+ ~NanoJSONResultsWriter() { |
+ SkFILEWStream stream(fFilename.c_str()); |
+ stream.writeText(Json::StyledWriter().write(fRoot).c_str()); |
+ stream.flush(); |
} |
+ |
+ // Added under "key". |
virtual void key(const char name[], const char value[]) { |
fRoot["key"][name] = value; |
} |
- virtual void option(const char name[], const char value[]) { |
- fRoot["options"][name] = value; |
+ // Inserted directly into the root. |
+ virtual void property(const char name[], const char value[]) { |
+ fRoot[name] = value; |
} |
virtual void bench(const char name[], int32_t x, int32_t y) { |
SkString id = SkStringPrintf( "%s_%d_%d", name, x, y); |
@@ -225,13 +112,8 @@ public: |
SkASSERT(NULL != fConfig); |
(*fConfig)[name] = ms; |
} |
- virtual void end() { |
- SkFILEWStream stream(fFilename.c_str()); |
- stream.writeText(Json::FastWriter().write(fRoot).c_str()); |
- stream.flush(); |
- } |
-private: |
+private: |
SkString fFilename; |
Json::Value fRoot; |
Json::Value& fResults; |
@@ -240,64 +122,4 @@ private: |
}; |
-/** |
- * This ResultsWriter writes out to multiple ResultsWriters. |
- */ |
-class MultiResultsWriter : public ResultsWriter { |
-public: |
- MultiResultsWriter() : writers() { |
- }; |
- void add(ResultsWriter* writer) { |
- writers.push_back(writer); |
- } |
- virtual void key(const char name[], const char value[]) { |
- for (int i = 0; i < writers.count(); ++i) { |
- writers[i]->key(name, value); |
- } |
- } |
- virtual void option(const char name[], const char value[]) { |
- for (int i = 0; i < writers.count(); ++i) { |
- writers[i]->option(name, value); |
- } |
- } |
- 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 config(const char name[]) { |
- for (int i = 0; i < writers.count(); ++i) { |
- writers[i]->config(name); |
- } |
- } |
- virtual void configOption(const char name[], const char* value) { |
- for (int i = 0; i < writers.count(); ++i) { |
- writers[i]->configOption(name, value); |
- } |
- } |
- virtual void timer(const char name[], double ms) { |
- for (int i = 0; i < writers.count(); ++i) { |
- writers[i]->timer(name, ms); |
- } |
- } |
- virtual void end() { |
- for (int i = 0; i < writers.count(); ++i) { |
- writers[i]->end(); |
- } |
- } |
-private: |
- SkTArray<ResultsWriter *> writers; |
-}; |
- |
-/** |
- * Calls the end() method of T on destruction. |
- */ |
-template <typename T> class CallEnd : SkNoncopyable { |
-public: |
- CallEnd(T& obj) : fObj(obj) {} |
- ~CallEnd() { fObj.end(); } |
-private: |
- T& fObj; |
-}; |
- |
#endif |