| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2013 Google Inc. | 2  * Copyright 2013 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  * | 6  * | 
| 7  * Classes for writing out bench results in various formats. | 7  * Classes for writing out bench results in various formats. | 
| 8  */ | 8  */ | 
| 9 #ifndef SkResultsWriter_DEFINED | 9 #ifndef SkResultsWriter_DEFINED | 
| 10 #define SkResultsWriter_DEFINED | 10 #define SkResultsWriter_DEFINED | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 74     } | 74     } | 
| 75 private: | 75 private: | 
| 76     SkBenchLogger& fLogger; | 76     SkBenchLogger& fLogger; | 
| 77     const char* fTimeFormat; | 77     const char* fTimeFormat; | 
| 78 }; | 78 }; | 
| 79 | 79 | 
| 80 #ifdef SK_BUILD_JSON_WRITER | 80 #ifdef SK_BUILD_JSON_WRITER | 
| 81 /** | 81 /** | 
| 82  * This ResultsWriter handles writing out the results in JSON. | 82  * This ResultsWriter handles writing out the results in JSON. | 
| 83  * | 83  * | 
| 84  * The output looks like: | 84  * The output looks like (except compressed to a single line): | 
| 85  * | 85  * | 
| 86  *  { | 86  *  { | 
| 87  *   "options" : { | 87  *   "options" : { | 
| 88  *      "alpha" : "0xFF", | 88  *      "alpha" : "0xFF", | 
| 89  *      "scale" : "0", | 89  *      "scale" : "0", | 
| 90  *      ... | 90  *      ... | 
| 91  *      "system" : "UNIX" | 91  *      "system" : "UNIX" | 
| 92  *   }, | 92  *   }, | 
| 93  *   "results" : { | 93  *   "results" : [ | 
| 94  *      "Xfermode_Luminosity_640_480" : { | 94  *      { | 
| 95  *         "565" : { | 95  *      "name" : "Xfermode_Luminosity_640_480", | 
|  | 96  *      "results" : [ | 
|  | 97  *         { | 
|  | 98  *            "name": "565", | 
| 96  *            "cmsecs" : 143.188128906250, | 99  *            "cmsecs" : 143.188128906250, | 
| 97  *            "msecs" : 143.835957031250 | 100  *            "msecs" : 143.835957031250 | 
| 98  *         }, | 101  *         }, | 
| 99  *         ... | 102  *         ... | 
| 100  */ | 103  */ | 
| 101 class JSONResultsWriter : public ResultsWriter { | 104 class JSONResultsWriter : public ResultsWriter { | 
| 102 private: | 105 private: | 
| 103     Json::Value* find_named_node(Json::Value* root, const char name[]) { | 106     Json::Value* find_named_node(Json::Value* root, const char name[]) { | 
| 104         Json::Value* search_results = NULL; | 107         Json::Value* search_results = NULL; | 
| 105         for(Json::Value::iterator iter = root->begin(); | 108         for(Json::Value::iterator iter = root->begin(); | 
| 106                 iter!= root->end(); ++iter) { | 109                 iter!= root->end(); ++iter) { | 
| 107             if(SkString(name).equals((*iter)["name"].asCString())) { | 110             if(SkString(name).equals((*iter)["name"].asCString())) { | 
| 108                 search_results = &(*iter); | 111                 search_results = &(*iter); | 
| 109                 break; | 112                 break; | 
| 110             } | 113             } | 
| 111         } | 114         } | 
| 112 | 115 | 
| 113         if(search_results != NULL) { | 116         if(search_results != NULL) { | 
| 114             return search_results; | 117             return search_results; | 
| 115         } else { | 118         } else { | 
| 116             return &(root->append(Json::Value())); | 119             Json::Value* new_val = &(root->append(Json::Value())); | 
|  | 120             (*new_val)["name"] = name; | 
|  | 121             return new_val; | 
| 117         } | 122         } | 
| 118     } | 123     } | 
| 119 public: | 124 public: | 
| 120     explicit JSONResultsWriter(const char filename[]) | 125     explicit JSONResultsWriter(const char filename[]) | 
| 121         : fFilename(filename) | 126         : fFilename(filename) | 
| 122         , fRoot() | 127         , fRoot() | 
| 123         , fResults(fRoot["results"]) | 128         , fResults(fRoot["results"]) | 
| 124         , fBench(NULL) | 129         , fBench(NULL) | 
| 125         , fConfig(NULL) { | 130         , fConfig(NULL) { | 
| 126     } | 131     } | 
| 127     virtual void option(const char name[], const char value[]) { | 132     virtual void option(const char name[], const char value[]) { | 
| 128         fRoot["options"][name] = value; | 133         fRoot["options"][name] = value; | 
| 129     } | 134     } | 
| 130     virtual void bench(const char name[], int32_t x, int32_t y) { | 135     virtual void bench(const char name[], int32_t x, int32_t y) { | 
| 131         const char* full_name = SkStringPrintf( "%s_%d_%d", name, x, y).c_str(); | 136         SkString sk_name(name); | 
| 132         Json::Value* bench_node = find_named_node(&fResults, full_name); | 137         sk_name.append("_"); | 
| 133         (*bench_node)["name"] = full_name; | 138         sk_name.appendS32(x); | 
|  | 139         sk_name.append("_"); | 
|  | 140         sk_name.appendS32(y); | 
|  | 141         Json::Value* bench_node = find_named_node(&fResults, sk_name.c_str()); | 
| 134         fBench = &(*bench_node)["results"]; | 142         fBench = &(*bench_node)["results"]; | 
| 135     } | 143     } | 
| 136     virtual void config(const char name[]) { | 144     virtual void config(const char name[]) { | 
| 137         SkASSERT(NULL != fBench); | 145         SkASSERT(NULL != fBench); | 
| 138         fConfig = find_named_node(fBench, name); | 146         fConfig = find_named_node(fBench, name); | 
| 139         (*fConfig)["name"] = name; |  | 
| 140     } | 147     } | 
| 141     virtual void timer(const char name[], double ms) { | 148     virtual void timer(const char name[], double ms) { | 
| 142         SkASSERT(NULL != fConfig); | 149         SkASSERT(NULL != fConfig); | 
| 143         (*fConfig)[name] = ms; | 150         (*fConfig)[name] = ms; | 
| 144     } | 151     } | 
| 145     virtual void end() { | 152     virtual void end() { | 
| 146         SkFILEWStream stream(fFilename.c_str()); | 153         SkFILEWStream stream(fFilename.c_str()); | 
| 147         stream.writeText(fRoot.toStyledString().c_str()); | 154         stream.writeText(Json::FastWriter().write(fRoot).c_str()); | 
| 148         stream.flush(); | 155         stream.flush(); | 
| 149     } | 156     } | 
| 150 private: | 157 private: | 
|  | 158 | 
| 151     SkString fFilename; | 159     SkString fFilename; | 
| 152     Json::Value fRoot; | 160     Json::Value fRoot; | 
| 153     Json::Value& fResults; | 161     Json::Value& fResults; | 
| 154     Json::Value* fBench; | 162     Json::Value* fBench; | 
| 155     Json::Value* fConfig; | 163     Json::Value* fConfig; | 
| 156 }; | 164 }; | 
| 157 | 165 | 
| 158 #endif // SK_BUILD_JSON_WRITER | 166 #endif // SK_BUILD_JSON_WRITER | 
| 159 /** | 167 /** | 
| 160  * This ResultsWriter writes out to multiple ResultsWriters. | 168  * This ResultsWriter writes out to multiple ResultsWriters. | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 200  */ | 208  */ | 
| 201 template <typename T> class CallEnd : SkNoncopyable { | 209 template <typename T> class CallEnd : SkNoncopyable { | 
| 202 public: | 210 public: | 
| 203     CallEnd(T& obj) : fObj(obj) {} | 211     CallEnd(T& obj) : fObj(obj) {} | 
| 204     ~CallEnd() { fObj.end(); } | 212     ~CallEnd() { fObj.end(); } | 
| 205 private: | 213 private: | 
| 206     T&  fObj; | 214     T&  fObj; | 
| 207 }; | 215 }; | 
| 208 | 216 | 
| 209 #endif | 217 #endif | 
| OLD | NEW | 
|---|