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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 * }, | 92 * }, |
93 * "results" : { | 93 * "results" : { |
94 * "Xfermode_Luminosity_640_480" : { | 94 * "Xfermode_Luminosity_640_480" : { |
95 * "565" : { | 95 * "565" : { |
96 * "cmsecs" : 143.188128906250, | 96 * "cmsecs" : 143.188128906250, |
97 * "msecs" : 143.835957031250 | 97 * "msecs" : 143.835957031250 |
98 * }, | 98 * }, |
99 * ... | 99 * ... |
100 */ | 100 */ |
101 class JSONResultsWriter : public ResultsWriter { | 101 class JSONResultsWriter : public ResultsWriter { |
102 private: | |
103 Json::Value* find_named_node(Json::Value* root, const char name[]) { | |
104 Json::Value* search_results = NULL; | |
105 for(Json::Value::iterator iter = root->begin(); | |
106 iter!= root->end(); ++iter) { | |
107 if(SkString(name).equals((*iter)["name"].asCString())) { | |
108 search_results = &(*iter); | |
jcgregorio
2014/05/19 17:05:12
break; ?
kelvinly
2014/05/19 17:10:46
Ah, my bad.
Would
return &(*iter);
be better/worse
| |
109 } | |
110 } | |
111 | |
112 if(search_results != NULL) { | |
113 return search_results; | |
114 } else { | |
115 return &(root->append(Json::Value())); | |
116 } | |
117 } | |
102 public: | 118 public: |
103 explicit JSONResultsWriter(const char filename[]) | 119 explicit JSONResultsWriter(const char filename[]) |
104 : fFilename(filename) | 120 : fFilename(filename) |
105 , fRoot() | 121 , fRoot() |
106 , fResults(fRoot["results"]) | 122 , fResults(fRoot["results"]) |
107 , fBench(NULL) | 123 , fBench(NULL) |
108 , fConfig(NULL) { | 124 , fConfig(NULL) { |
109 } | 125 } |
110 virtual void option(const char name[], const char value[]) { | 126 virtual void option(const char name[], const char value[]) { |
111 fRoot["options"][name] = value; | 127 fRoot["options"][name] = value; |
112 } | 128 } |
113 virtual void bench(const char name[], int32_t x, int32_t y) { | 129 virtual void bench(const char name[], int32_t x, int32_t y) { |
114 fBench = &fResults[SkStringPrintf( "%s_%d_%d", name, x, y).c_str()]; | 130 const char* full_name = SkStringPrintf( "%s_%d_%d", name, x, y).c_str(); |
131 Json::Value* bench_node = find_named_node(&fResults, full_name); | |
132 (*bench_node)["name"] = full_name; | |
133 fBench = &(*bench_node)["results"]; | |
115 } | 134 } |
116 virtual void config(const char name[]) { | 135 virtual void config(const char name[]) { |
117 SkASSERT(NULL != fBench); | 136 SkASSERT(NULL != fBench); |
118 fConfig = &(*fBench)[name]; | 137 fConfig = find_named_node(fBench, name); |
138 (*fConfig)["name"] = name; | |
119 } | 139 } |
120 virtual void timer(const char name[], double ms) { | 140 virtual void timer(const char name[], double ms) { |
121 SkASSERT(NULL != fConfig); | 141 SkASSERT(NULL != fConfig); |
122 (*fConfig)[name] = ms; | 142 (*fConfig)[name] = ms; |
123 } | 143 } |
124 virtual void end() { | 144 virtual void end() { |
125 SkFILEWStream stream(fFilename.c_str()); | 145 SkFILEWStream stream(fFilename.c_str()); |
126 stream.writeText(fRoot.toStyledString().c_str()); | 146 stream.writeText(fRoot.toStyledString().c_str()); |
127 stream.flush(); | 147 stream.flush(); |
128 } | 148 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 */ | 199 */ |
180 template <typename T> class CallEnd : SkNoncopyable { | 200 template <typename T> class CallEnd : SkNoncopyable { |
181 public: | 201 public: |
182 CallEnd(T& obj) : fObj(obj) {} | 202 CallEnd(T& obj) : fObj(obj) {} |
183 ~CallEnd() { fObj.end(); } | 203 ~CallEnd() { fObj.end(); } |
184 private: | 204 private: |
185 T& fObj; | 205 T& fObj; |
186 }; | 206 }; |
187 | 207 |
188 #endif | 208 #endif |
OLD | NEW |