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 | 9 |
10 #ifndef SkResultsWriter_DEFINED | 10 #ifndef SkResultsWriter_DEFINED |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 , fRoot() | 80 , fRoot() |
81 , fResults(fRoot["results"]) | 81 , fResults(fRoot["results"]) |
82 , fBench(nullptr) | 82 , fBench(nullptr) |
83 , fConfig(nullptr) {} | 83 , fConfig(nullptr) {} |
84 | 84 |
85 ~NanoJSONResultsWriter() { | 85 ~NanoJSONResultsWriter() { |
86 this->flush(); | 86 this->flush(); |
87 } | 87 } |
88 | 88 |
89 // Added under "key". | 89 // Added under "key". |
90 virtual void key(const char name[], const char value[]) { | 90 void key(const char name[], const char value[]) override { |
91 fRoot["key"][name] = value; | 91 fRoot["key"][name] = value; |
92 } | 92 } |
93 // Inserted directly into the root. | 93 // Inserted directly into the root. |
94 virtual void property(const char name[], const char value[]) { | 94 void property(const char name[], const char value[]) override { |
95 fRoot[name] = value; | 95 fRoot[name] = value; |
96 } | 96 } |
97 virtual void bench(const char name[], int32_t x, int32_t y) { | 97 void bench(const char name[], int32_t x, int32_t y) override { |
98 SkString id = SkStringPrintf( "%s_%d_%d", name, x, y); | 98 SkString id = SkStringPrintf( "%s_%d_%d", name, x, y); |
99 fResults[id.c_str()] = Json::Value(Json::objectValue); | 99 fResults[id.c_str()] = Json::Value(Json::objectValue); |
100 fBench = &fResults[id.c_str()]; | 100 fBench = &fResults[id.c_str()]; |
101 } | 101 } |
102 virtual void config(const char name[]) { | 102 void config(const char name[]) override { |
103 SkASSERT(fBench); | 103 SkASSERT(fBench); |
104 fConfig = &(*fBench)[name]; | 104 fConfig = &(*fBench)[name]; |
105 } | 105 } |
106 virtual void configOption(const char name[], const char* value) { | 106 void configOption(const char name[], const char* value) override { |
107 (*fConfig)["options"][name] = value; | 107 (*fConfig)["options"][name] = value; |
108 } | 108 } |
109 virtual void metric(const char name[], double ms) { | 109 void metric(const char name[], double ms) override { |
110 // Don't record if nan, or -nan. | 110 // Don't record if nan, or -nan. |
111 if (sk_double_isnan(ms)) { | 111 if (sk_double_isnan(ms)) { |
112 return; | 112 return; |
113 } | 113 } |
114 SkASSERT(fConfig); | 114 SkASSERT(fConfig); |
115 (*fConfig)[name] = ms; | 115 (*fConfig)[name] = ms; |
116 } | 116 } |
117 | 117 |
118 // Flush to storage now please. | 118 // Flush to storage now please. |
119 virtual void flush() { | 119 void flush() override { |
120 SkString dirname = SkOSPath::Dirname(fFilename.c_str()); | 120 SkString dirname = SkOSPath::Dirname(fFilename.c_str()); |
121 if (!sk_exists(dirname.c_str(), kWrite_SkFILE_Flag)) { | 121 if (!sk_exists(dirname.c_str(), kWrite_SkFILE_Flag)) { |
122 if (!sk_mkdir(dirname.c_str())) { | 122 if (!sk_mkdir(dirname.c_str())) { |
123 SkDebugf("Failed to create directory."); | 123 SkDebugf("Failed to create directory."); |
124 } | 124 } |
125 } | 125 } |
126 SkFILEWStream stream(fFilename.c_str()); | 126 SkFILEWStream stream(fFilename.c_str()); |
127 stream.writeText(Json::StyledWriter().write(fRoot).c_str()); | 127 stream.writeText(Json::StyledWriter().write(fRoot).c_str()); |
128 stream.flush(); | 128 stream.flush(); |
129 } | 129 } |
130 | 130 |
131 private: | 131 private: |
132 SkString fFilename; | 132 SkString fFilename; |
133 Json::Value fRoot; | 133 Json::Value fRoot; |
134 Json::Value& fResults; | 134 Json::Value& fResults; |
135 Json::Value* fBench; | 135 Json::Value* fBench; |
136 Json::Value* fConfig; | 136 Json::Value* fConfig; |
137 }; | 137 }; |
138 | 138 |
139 | 139 |
140 #endif | 140 #endif |
OLD | NEW |