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 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2229 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage); | 2229 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage); |
2230 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches); | 2230 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches); |
2231 } | 2231 } |
2232 | 2232 |
2233 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) { | 2233 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) { |
2234 return static_cast<base::HistogramBase::Sample>( | 2234 return static_cast<base::HistogramBase::Sample>( |
2235 base::HashMetricName(switch_name)); | 2235 base::HashMetricName(switch_name)); |
2236 } | 2236 } |
2237 | 2237 |
2238 void ReportAboutFlagsHistogram(const std::string& uma_histogram_name, | 2238 void ReportAboutFlagsHistogram(const std::string& uma_histogram_name, |
2239 const std::set<std::string>& flags) { | 2239 const std::set<std::string>& flags) { |
Alexei Svitkine (slow)
2016/09/15 19:59:18
This function is also called from a different plac
lawrencewu
2016/09/16 15:34:56
I needed only one extra parameter for all features
| |
2240 for (const std::string& flag : flags) { | 2240 for (const std::string& flag : flags) { |
2241 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; | 2241 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; |
2242 if (base::StartsWith(flag, "--", base::CompareCase::SENSITIVE)) { | |
2243 // Skip '--' before switch name. | |
2244 std::string switch_name(flag.substr(2)); | |
2245 | 2242 |
2246 // Kill value, if any. | 2243 std::string mutable_flag(flag); |
2247 const size_t value_pos = switch_name.find('='); | 2244 // Kill value, if any. |
2248 if (value_pos != std::string::npos) | 2245 const size_t value_pos = mutable_flag.find('='); |
2249 switch_name.resize(value_pos); | 2246 if (value_pos != std::string::npos) |
2247 mutable_flag.resize(value_pos); | |
2250 | 2248 |
2251 uma_id = GetSwitchUMAId(switch_name); | 2249 uma_id = GetSwitchUMAId(mutable_flag); |
2252 } else { | |
2253 NOTREACHED() << "ReportAboutFlagsHistogram(): flag '" << flag | |
2254 << "' has incorrect format."; | |
2255 } | |
2256 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name | 2250 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name |
2257 << "' '" << flag << "', uma_id=" << uma_id; | 2251 << "' '" << mutable_flag << "', uma_id=" << uma_id; |
2258 | 2252 |
2259 // Sparse histogram macro does not cache the histogram, so it's safe | 2253 // Sparse histogram macro does not cache the histogram, so it's safe |
2260 // to use macro with non-static histogram name here. | 2254 // to use macro with non-static histogram name here. |
2261 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id); | 2255 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id); |
2262 } | 2256 } |
2263 } | 2257 } |
2264 | 2258 |
2265 namespace testing { | 2259 namespace testing { |
2266 | 2260 |
2267 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; | 2261 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; |
2268 | 2262 |
2269 const FeatureEntry* GetFeatureEntries(size_t* count) { | 2263 const FeatureEntry* GetFeatureEntries(size_t* count) { |
2270 *count = arraysize(kFeatureEntries); | 2264 *count = arraysize(kFeatureEntries); |
2271 return kFeatureEntries; | 2265 return kFeatureEntries; |
2272 } | 2266 } |
2273 | 2267 |
2274 } // namespace testing | 2268 } // namespace testing |
2275 | 2269 |
2276 } // namespace about_flags | 2270 } // namespace about_flags |
OLD | NEW |