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/about_flags.h" | 5 #include "chrome/browser/about_flags.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2220 FlagsStateSingleton::GetFlagsState()->RemoveFlagsSwitches(switch_list); | 2220 FlagsStateSingleton::GetFlagsState()->RemoveFlagsSwitches(switch_list); |
2221 } | 2221 } |
2222 | 2222 |
2223 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) { | 2223 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) { |
2224 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage); | 2224 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage); |
2225 } | 2225 } |
2226 | 2226 |
2227 void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage) { | 2227 void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage) { |
2228 const std::set<std::string> switches = | 2228 const std::set<std::string> switches = |
2229 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage); | 2229 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage); |
2230 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches); | 2230 const std::set<std::string> features = |
2231 FlagsStateSingleton::GetFlagsState()->GetFeaturesFromFlags(flags_storage); | |
2232 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches, features); | |
2231 } | 2233 } |
2232 | 2234 |
2233 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) { | 2235 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) { |
2234 return static_cast<base::HistogramBase::Sample>( | 2236 return static_cast<base::HistogramBase::Sample>( |
2235 base::HashMetricName(switch_name)); | 2237 base::HashMetricName(switch_name)); |
2236 } | 2238 } |
2237 | 2239 |
2238 void ReportAboutFlagsHistogram(const std::string& uma_histogram_name, | 2240 void ReportAboutFlagsHistogram( |
2239 const std::set<std::string>& flags) { | 2241 const std::string& uma_histogram_name, |
2240 for (const std::string& flag : flags) { | 2242 const std::set<std::string>& switches, |
2243 const std::set<std::string>& features) { | |
2244 ReportAboutFlagsHistogramSwitches(uma_histogram_name, switches); | |
2245 ReportAboutFlagsHistogramFeatures(uma_histogram_name, features); | |
2246 } | |
2247 | |
2248 void ReportAboutFlagsHistogramSwitches(const std::string& uma_histogram_name, | |
2249 const std::set<std::string>& switches) { | |
2250 for (const std::string& flag : switches) { | |
2241 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; | 2251 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; |
2242 if (base::StartsWith(flag, "--", base::CompareCase::SENSITIVE)) { | 2252 if (base::StartsWith(flag, "--", base::CompareCase::SENSITIVE)) { |
2243 // Skip '--' before switch name. | 2253 // Skip '--' before switch name. |
2244 std::string switch_name(flag.substr(2)); | 2254 std::string switch_name(flag.substr(2)); |
2245 | 2255 |
2246 // Kill value, if any. | 2256 // Kill value, if any. |
2247 const size_t value_pos = switch_name.find('='); | 2257 const size_t value_pos = switch_name.find('='); |
2248 if (value_pos != std::string::npos) | 2258 if (value_pos != std::string::npos) |
2249 switch_name.resize(value_pos); | 2259 switch_name.resize(value_pos); |
2250 | 2260 |
2251 uma_id = GetSwitchUMAId(switch_name); | 2261 uma_id = GetSwitchUMAId(switch_name); |
2252 } else { | 2262 } else { |
2253 NOTREACHED() << "ReportAboutFlagsHistogram(): flag '" << flag | 2263 NOTREACHED() << "ReportAboutFlagsHistogram(): flag '" << flag |
2254 << "' has incorrect format."; | 2264 << "' has incorrect format."; |
2255 } | 2265 } |
2256 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name | 2266 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name |
2257 << "' '" << flag << "', uma_id=" << uma_id; | 2267 << "' '" << flag << "', uma_id=" << uma_id; |
2258 | 2268 |
2259 // Sparse histogram macro does not cache the histogram, so it's safe | 2269 // Sparse histogram macro does not cache the histogram, so it's safe |
2260 // to use macro with non-static histogram name here. | 2270 // to use macro with non-static histogram name here. |
2261 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id); | 2271 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id); |
2262 } | 2272 } |
2263 } | 2273 } |
2264 | 2274 |
2275 void ReportAboutFlagsHistogramFeatures(const std::string& uma_histogram_name, | |
Alexei Svitkine (slow)
2016/09/16 15:52:38
If this is not called from anywhere except this fi
lawrencewu
2016/09/16 17:12:57
Done.
| |
2276 const std::set<std::string>&features) { | |
2277 for (const std::string& feature : features) { | |
2278 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; | |
2279 | |
2280 uma_id = GetSwitchUMAId(feature); | |
2281 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name | |
2282 << "' '" << feature << "', uma_id=" << uma_id; | |
2283 | |
2284 // Sparse histogram macro does not cache the histogram, so it's safe | |
2285 // to use macro with non-static histogram name here. | |
2286 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id); | |
2287 } | |
2288 } | |
2289 | |
2265 namespace testing { | 2290 namespace testing { |
2266 | 2291 |
2267 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; | 2292 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; |
2268 | 2293 |
2269 const FeatureEntry* GetFeatureEntries(size_t* count) { | 2294 const FeatureEntry* GetFeatureEntries(size_t* count) { |
2270 *count = arraysize(kFeatureEntries); | 2295 *count = arraysize(kFeatureEntries); |
2271 return kFeatureEntries; | 2296 return kFeatureEntries; |
2272 } | 2297 } |
2273 | 2298 |
2274 } // namespace testing | 2299 } // namespace testing |
2275 | 2300 |
2276 } // namespace about_flags | 2301 } // namespace about_flags |
OLD | NEW |