OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/performance_monitor/key_builder.h" | 5 #include "chrome/browser/performance_monitor/key_builder.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 DCHECK(metric_type_to_metric_key_char_.size() == METRIC_NUMBER_OF_METRICS); | 167 DCHECK(metric_type_to_metric_key_char_.size() == METRIC_NUMBER_OF_METRICS); |
168 | 168 |
169 for (int i = static_cast<int>(METRIC_UNDEFINED); | 169 for (int i = static_cast<int>(METRIC_UNDEFINED); |
170 i <= static_cast<int>(METRIC_NUMBER_OF_METRICS); ++i) { | 170 i <= static_cast<int>(METRIC_NUMBER_OF_METRICS); ++i) { |
171 metric_key_char_to_metric_type_[metric_type_to_metric_key_char_[ | 171 metric_key_char_to_metric_type_[metric_type_to_metric_key_char_[ |
172 static_cast<MetricType>(i)]] = static_cast<MetricType>(i); | 172 static_cast<MetricType>(i)]] = static_cast<MetricType>(i); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 std::string KeyBuilder::CreateActiveIntervalKey(const base::Time& time) { | 176 std::string KeyBuilder::CreateActiveIntervalKey(const base::Time& time) { |
177 return StringPrintf("%016" PRId64, time.ToInternalValue()); | 177 return base::StringPrintf("%016" PRId64, time.ToInternalValue()); |
178 } | 178 } |
179 | 179 |
180 std::string KeyBuilder::CreateMetricKey(const base::Time& time, | 180 std::string KeyBuilder::CreateMetricKey(const base::Time& time, |
181 const MetricType type, | 181 const MetricType type, |
182 const std::string& activity) { | 182 const std::string& activity) { |
183 return StringPrintf("%c%c%016" PRId64 "%c%s", | 183 return base::StringPrintf("%c%c%016" PRId64 "%c%s", |
184 metric_type_to_metric_key_char_[type], | 184 metric_type_to_metric_key_char_[type], |
185 kDelimiter, time.ToInternalValue(), | 185 kDelimiter, time.ToInternalValue(), |
186 kDelimiter, activity.c_str()); | 186 kDelimiter, activity.c_str()); |
187 } | 187 } |
188 | 188 |
189 std::string KeyBuilder::CreateEventKey(const base::Time& time, | 189 std::string KeyBuilder::CreateEventKey(const base::Time& time, |
190 const EventType type) { | 190 const EventType type) { |
191 return StringPrintf("%016" PRId64 "%c%c", | 191 return base::StringPrintf("%016" PRId64 "%c%c", |
192 time.ToInternalValue(), kDelimiter, | 192 time.ToInternalValue(), kDelimiter, |
193 event_type_to_event_key_char_[type]); | 193 event_type_to_event_key_char_[type]); |
194 } | 194 } |
195 | 195 |
196 std::string KeyBuilder::CreateRecentKey(const base::Time& time, | 196 std::string KeyBuilder::CreateRecentKey(const base::Time& time, |
197 const MetricType type, | 197 const MetricType type, |
198 const std::string& activity) { | 198 const std::string& activity) { |
199 return StringPrintf("%016" PRId64 "%c%c%c%s", | 199 return base::StringPrintf("%016" PRId64 "%c%c%c%s", |
200 time.ToInternalValue(), | 200 time.ToInternalValue(), |
201 kDelimiter, metric_type_to_metric_key_char_[type], | 201 kDelimiter, metric_type_to_metric_key_char_[type], |
202 kDelimiter, activity.c_str()); | 202 kDelimiter, activity.c_str()); |
203 } | 203 } |
204 | 204 |
205 std::string KeyBuilder::CreateRecentMapKey(const MetricType type, | 205 std::string KeyBuilder::CreateRecentMapKey(const MetricType type, |
206 const std::string& activity) { | 206 const std::string& activity) { |
207 return StringPrintf("%s%c%c", | 207 return base::StringPrintf("%s%c%c", |
208 activity.c_str(), | 208 activity.c_str(), |
209 kDelimiter, metric_type_to_metric_key_char_[type]); | 209 kDelimiter, metric_type_to_metric_key_char_[type]); |
210 } | 210 } |
211 | 211 |
212 std::string KeyBuilder::CreateMaxValueKey(const MetricType type, | 212 std::string KeyBuilder::CreateMaxValueKey(const MetricType type, |
213 const std::string& activity) { | 213 const std::string& activity) { |
214 return StringPrintf("%c%c%s", | 214 return base::StringPrintf("%c%c%s", |
215 metric_type_to_metric_key_char_[type], | 215 metric_type_to_metric_key_char_[type], |
216 kDelimiter, activity.c_str()); | 216 kDelimiter, activity.c_str()); |
217 } | 217 } |
218 | 218 |
219 EventType KeyBuilder::EventKeyToEventType(const std::string& event_key) { | 219 EventType KeyBuilder::EventKeyToEventType(const std::string& event_key) { |
220 std::vector<std::string> split; | 220 std::vector<std::string> split; |
221 base::SplitString(event_key, kDelimiter, &split); | 221 base::SplitString(event_key, kDelimiter, &split); |
222 DCHECK(split[EVENT_TYPE].size() == 1); | 222 DCHECK(split[EVENT_TYPE].size() == 1); |
223 return event_key_char_to_event_type_[ | 223 return event_key_char_to_event_type_[ |
224 static_cast<int>(split[EVENT_TYPE].at(0))]; | 224 static_cast<int>(split[EVENT_TYPE].at(0))]; |
225 } | 225 } |
226 | 226 |
(...skipping 11 matching lines...) Expand all Loading... |
238 std::vector<std::string> split; | 238 std::vector<std::string> split; |
239 base::SplitString(key, kDelimiter, &split); | 239 base::SplitString(key, kDelimiter, &split); |
240 DCHECK(split[METRIC_TYPE].size() == 1); | 240 DCHECK(split[METRIC_TYPE].size() == 1); |
241 return MetricKey(split[METRIC_TIME], | 241 return MetricKey(split[METRIC_TIME], |
242 metric_key_char_to_metric_type_[ | 242 metric_key_char_to_metric_type_[ |
243 static_cast<int>(split[METRIC_TYPE].at(0))], | 243 static_cast<int>(split[METRIC_TYPE].at(0))], |
244 split[METRIC_ACTIVITY]); | 244 split[METRIC_ACTIVITY]); |
245 } | 245 } |
246 | 246 |
247 } // namespace performance_monitor | 247 } // namespace performance_monitor |
OLD | NEW |