Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: bench/ResultsWriter.h

Issue 290903002: Changed JSON formatting to fit BigQuery requirements (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix for loop problem Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
109 break;
110 }
111 }
112
113 if(search_results != NULL) {
114 return search_results;
115 } else {
116 return &(root->append(Json::Value()));
117 }
118 }
102 public: 119 public:
103 explicit JSONResultsWriter(const char filename[]) 120 explicit JSONResultsWriter(const char filename[])
104 : fFilename(filename) 121 : fFilename(filename)
105 , fRoot() 122 , fRoot()
106 , fResults(fRoot["results"]) 123 , fResults(fRoot["results"])
107 , fBench(NULL) 124 , fBench(NULL)
108 , fConfig(NULL) { 125 , fConfig(NULL) {
109 } 126 }
110 virtual void option(const char name[], const char value[]) { 127 virtual void option(const char name[], const char value[]) {
111 fRoot["options"][name] = value; 128 fRoot["options"][name] = value;
112 } 129 }
113 virtual void bench(const char name[], int32_t x, int32_t y) { 130 virtual void bench(const char name[], int32_t x, int32_t y) {
114 fBench = &fResults[SkStringPrintf( "%s_%d_%d", name, x, y).c_str()]; 131 const char* full_name = SkStringPrintf( "%s_%d_%d", name, x, y).c_str();
132 Json::Value* bench_node = find_named_node(&fResults, full_name);
133 (*bench_node)["name"] = full_name;
134 fBench = &(*bench_node)["results"];
115 } 135 }
116 virtual void config(const char name[]) { 136 virtual void config(const char name[]) {
117 SkASSERT(NULL != fBench); 137 SkASSERT(NULL != fBench);
118 fConfig = &(*fBench)[name]; 138 fConfig = find_named_node(fBench, name);
139 (*fConfig)["name"] = name;
119 } 140 }
120 virtual void timer(const char name[], double ms) { 141 virtual void timer(const char name[], double ms) {
121 SkASSERT(NULL != fConfig); 142 SkASSERT(NULL != fConfig);
122 (*fConfig)[name] = ms; 143 (*fConfig)[name] = ms;
123 } 144 }
124 virtual void end() { 145 virtual void end() {
125 SkFILEWStream stream(fFilename.c_str()); 146 SkFILEWStream stream(fFilename.c_str());
126 stream.writeText(fRoot.toStyledString().c_str()); 147 stream.writeText(fRoot.toStyledString().c_str());
127 stream.flush(); 148 stream.flush();
128 } 149 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 */ 200 */
180 template <typename T> class CallEnd : SkNoncopyable { 201 template <typename T> class CallEnd : SkNoncopyable {
181 public: 202 public:
182 CallEnd(T& obj) : fObj(obj) {} 203 CallEnd(T& obj) : fObj(obj) {}
183 ~CallEnd() { fObj.end(); } 204 ~CallEnd() { fObj.end(); }
184 private: 205 private:
185 T& fObj; 206 T& fObj;
186 }; 207 };
187 208
188 #endif 209 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698