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