diff options
Diffstat (limited to 'bench/ResultsWriter.h')
-rw-r--r-- | bench/ResultsWriter.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/bench/ResultsWriter.h b/bench/ResultsWriter.h index 1ee3616ceb..dc45f192f5 100644 --- a/bench/ResultsWriter.h +++ b/bench/ResultsWriter.h @@ -26,6 +26,10 @@ class ResultsWriter : SkNoncopyable { public: 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; + // 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; @@ -37,6 +41,9 @@ public: // Records the specific configuration a bench is run under, such as "8888". virtual void config(const char name[]) = 0; + // Records the options for a configuration, such as "GL_RENDERER". + virtual void configOption(const char name[], const char* value) = 0; + // Records a single test metric. virtual void timer(const char name[], double ms) = 0; @@ -55,6 +62,9 @@ public: , 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)); } @@ -65,6 +75,9 @@ public: 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)); @@ -113,6 +126,8 @@ public: , 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; } @@ -129,7 +144,84 @@ public: 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; +}; + +/** + NanoJSONResultsWriter writes the test results out in the following + format: + + { + "key": { + "arch": "Arm7", + "gpu": "SGX540", + "os": "Android", + "model": "GalaxyNexus", + } + "options": { + "GL_Version": "3.1", + ... + }, + "gitHash": "d1830323662ae8ae06908b97f15180fd25808894", + "results" : { + "Xfermode_Luminosity_640_480" : { + "8888" : { + "median_ms" : 143.188128906250, + "min_ms" : 143.835957031250, + ... + }, + ... +*/ +class NanoJSONResultsWriter : public ResultsWriter { +public: + explicit NanoJSONResultsWriter(const char filename[], const char gitHash[]) + : fFilename(filename) + , fRoot() + , fResults(fRoot["results"]) + , fBench(NULL) + , fConfig(NULL) { + fRoot["gitHash"] = gitHash; + } + 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; + } + virtual void bench(const char name[], int32_t x, int32_t y) { + SkString id = SkStringPrintf( "%s_%d_%d", name, x, y); + fResults[id.c_str()] = Json::Value(Json::objectValue); + fBench = &fResults[id.c_str()]; + } + virtual void config(const char name[]) { + SkASSERT(NULL != fBench); + fConfig = &(*fBench)[name]; + } + virtual void configOption(const char name[], const char* value) { + (*fConfig)["options"][name] = value; + } virtual void timer(const char name[], double ms) { + // Don't record if nan, or -nan. + if (sk_double_isnan(ms)) { + return; + } SkASSERT(NULL != fConfig); (*fConfig)[name] = ms; } @@ -147,6 +239,7 @@ private: Json::Value* fConfig; }; + /** * This ResultsWriter writes out to multiple ResultsWriters. */ @@ -157,6 +250,11 @@ public: 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); @@ -172,6 +270,11 @@ public: 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); |