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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 * { | 94 * { |
95 * "name" : "Xfermode_Luminosity_640_480", | 95 * "name" : "Xfermode_Luminosity_640_480", |
96 * "results" : [ | 96 * "results" : [ |
97 * { | 97 * { |
98 * "name": "565", | 98 * "name": "565", |
99 * "cmsecs" : 143.188128906250, | 99 * "cmsecs" : 143.188128906250, |
100 * "msecs" : 143.835957031250 | 100 * "msecs" : 143.835957031250 |
101 * }, | 101 * }, |
102 * ... | 102 * ... |
103 */ | 103 */ |
| 104 class JSONResultsWriter : public ResultsWriter { |
| 105 private: |
| 106 Json::Value* find_named_node(Json::Value* root, const char name[]) { |
| 107 Json::Value* search_results = NULL; |
| 108 for(Json::Value::iterator iter = root->begin(); |
| 109 iter!= root->end(); ++iter) { |
| 110 if(SkString(name).equals((*iter)["name"].asCString())) { |
| 111 search_results = &(*iter); |
| 112 break; |
| 113 } |
| 114 } |
104 | 115 |
105 Json::Value* SkFindNamedNode(Json::Value* root, const char name[]); | 116 if(search_results != NULL) { |
106 class JSONResultsWriter : public ResultsWriter { | 117 return search_results; |
| 118 } else { |
| 119 Json::Value* new_val = &(root->append(Json::Value())); |
| 120 (*new_val)["name"] = name; |
| 121 return new_val; |
| 122 } |
| 123 } |
107 public: | 124 public: |
108 explicit JSONResultsWriter(const char filename[]) | 125 explicit JSONResultsWriter(const char filename[]) |
109 : fFilename(filename) | 126 : fFilename(filename) |
110 , fRoot() | 127 , fRoot() |
111 , fResults(fRoot["results"]) | 128 , fResults(fRoot["results"]) |
112 , fBench(NULL) | 129 , fBench(NULL) |
113 , fConfig(NULL) { | 130 , fConfig(NULL) { |
114 } | 131 } |
115 virtual void option(const char name[], const char value[]) { | 132 virtual void option(const char name[], const char value[]) { |
116 fRoot["options"][name] = value; | 133 fRoot["options"][name] = value; |
117 } | 134 } |
118 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) { |
119 SkString sk_name(name); | 136 SkString sk_name(name); |
120 sk_name.append("_"); | 137 sk_name.append("_"); |
121 sk_name.appendS32(x); | 138 sk_name.appendS32(x); |
122 sk_name.append("_"); | 139 sk_name.append("_"); |
123 sk_name.appendS32(y); | 140 sk_name.appendS32(y); |
124 Json::Value* bench_node = SkFindNamedNode(&fResults, sk_name.c_str()); | 141 Json::Value* bench_node = find_named_node(&fResults, sk_name.c_str()); |
125 fBench = &(*bench_node)["results"]; | 142 fBench = &(*bench_node)["results"]; |
126 } | 143 } |
127 virtual void config(const char name[]) { | 144 virtual void config(const char name[]) { |
128 SkASSERT(NULL != fBench); | 145 SkASSERT(NULL != fBench); |
129 fConfig = SkFindNamedNode(fBench, name); | 146 fConfig = find_named_node(fBench, name); |
130 } | 147 } |
131 virtual void timer(const char name[], double ms) { | 148 virtual void timer(const char name[], double ms) { |
132 SkASSERT(NULL != fConfig); | 149 SkASSERT(NULL != fConfig); |
133 (*fConfig)[name] = ms; | 150 (*fConfig)[name] = ms; |
134 } | 151 } |
135 virtual void end() { | 152 virtual void end() { |
136 SkFILEWStream stream(fFilename.c_str()); | 153 SkFILEWStream stream(fFilename.c_str()); |
137 stream.writeText(Json::FastWriter().write(fRoot).c_str()); | 154 stream.writeText(Json::FastWriter().write(fRoot).c_str()); |
138 stream.flush(); | 155 stream.flush(); |
139 } | 156 } |
140 private: | 157 private: |
141 | 158 |
142 SkString fFilename; | 159 SkString fFilename; |
143 Json::Value fRoot; | 160 Json::Value fRoot; |
144 Json::Value& fResults; | 161 Json::Value& fResults; |
145 Json::Value* fBench; | 162 Json::Value* fBench; |
146 Json::Value* fConfig; | 163 Json::Value* fConfig; |
147 }; | 164 }; |
148 | 165 |
149 #endif // SK_BUILD_JSON_WRITER | 166 #endif // SK_BUILD_JSON_WRITER |
150 | |
151 /** | 167 /** |
152 * This ResultsWriter writes out to multiple ResultsWriters. | 168 * This ResultsWriter writes out to multiple ResultsWriters. |
153 */ | 169 */ |
154 class MultiResultsWriter : public ResultsWriter { | 170 class MultiResultsWriter : public ResultsWriter { |
155 public: | 171 public: |
156 MultiResultsWriter() : writers() { | 172 MultiResultsWriter() : writers() { |
157 }; | 173 }; |
158 void add(ResultsWriter* writer) { | 174 void add(ResultsWriter* writer) { |
159 writers.push_back(writer); | 175 writers.push_back(writer); |
160 } | 176 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 */ | 208 */ |
193 template <typename T> class CallEnd : SkNoncopyable { | 209 template <typename T> class CallEnd : SkNoncopyable { |
194 public: | 210 public: |
195 CallEnd(T& obj) : fObj(obj) {} | 211 CallEnd(T& obj) : fObj(obj) {} |
196 ~CallEnd() { fObj.end(); } | 212 ~CallEnd() { fObj.end(); } |
197 private: | 213 private: |
198 T& fObj; | 214 T& fObj; |
199 }; | 215 }; |
200 | 216 |
201 #endif | 217 #endif |
OLD | NEW |