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

Side by Side Diff: chrome/browser/about_flags.cc

Issue 2345033002: Log base::Features in Launch.FlagsAtStartup (Closed)
Patch Set: Update comment and add missing feature to histograms.xml Created 4 years, 3 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 | « chrome/browser/about_flags.h ('k') | chrome/browser/about_flags_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 channel != version_info::Channel::BETA && 2150 channel != version_info::Channel::BETA &&
2151 channel != version_info::Channel::DEV && 2151 channel != version_info::Channel::DEV &&
2152 channel != version_info::Channel::CANARY && 2152 channel != version_info::Channel::CANARY &&
2153 channel != version_info::Channel::UNKNOWN) { 2153 channel != version_info::Channel::UNKNOWN) {
2154 return true; 2154 return true;
2155 } 2155 }
2156 2156
2157 return false; 2157 return false;
2158 } 2158 }
2159 2159
2160 // Records a set of feature switches (prefixed with "--").
2161 void ReportAboutFlagsHistogramSwitches(const std::string& uma_histogram_name,
2162 const std::set<std::string>& switches) {
2163 for (const std::string& flag : switches) {
2164 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId;
2165 if (base::StartsWith(flag, "--", base::CompareCase::SENSITIVE)) {
2166 // Skip '--' before switch name.
2167 std::string switch_name(flag.substr(2));
2168
2169 // Kill value, if any.
2170 const size_t value_pos = switch_name.find('=');
2171 if (value_pos != std::string::npos)
2172 switch_name.resize(value_pos);
2173
2174 uma_id = GetSwitchUMAId(switch_name);
2175 } else {
2176 NOTREACHED() << "ReportAboutFlagsHistogram(): flag '" << flag
2177 << "' has incorrect format.";
2178 }
2179 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name
2180 << "' '" << flag << "', uma_id=" << uma_id;
2181
2182 // Sparse histogram macro does not cache the histogram, so it's safe
2183 // to use macro with non-static histogram name here.
2184 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id);
2185 }
2186 }
2187
2188 // Records a set of FEATURE_VALUE_TYPE features (suffixed with ":enabled" or
2189 // "disabled", depending on their state).
2190 void ReportAboutFlagsHistogramFeatures(const std::string& uma_histogram_name,
2191 const std::set<std::string>&features) {
2192 for (const std::string& feature : features) {
2193 int uma_id = GetSwitchUMAId(feature);
2194 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name
2195 << "' '" << feature << "', uma_id=" << uma_id;
2196
2197 // Sparse histogram macro does not cache the histogram, so it's safe
2198 // to use macro with non-static histogram name here.
2199 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id);
2200 }
2201 }
2202
2160 } // namespace 2203 } // namespace
2161 2204
2162 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, 2205 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
2163 base::CommandLine* command_line, 2206 base::CommandLine* command_line,
2164 flags_ui::SentinelsMode sentinels) { 2207 flags_ui::SentinelsMode sentinels) {
2165 if (command_line->HasSwitch(switches::kNoExperiments)) 2208 if (command_line->HasSwitch(switches::kNoExperiments))
2166 return; 2209 return;
2167 2210
2168 FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches( 2211 FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches(
2169 flags_storage, command_line, sentinels, switches::kEnableFeatures, 2212 flags_storage, command_line, sentinels, switches::kEnableFeatures,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2220 FlagsStateSingleton::GetFlagsState()->RemoveFlagsSwitches(switch_list); 2263 FlagsStateSingleton::GetFlagsState()->RemoveFlagsSwitches(switch_list);
2221 } 2264 }
2222 2265
2223 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) { 2266 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) {
2224 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage); 2267 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage);
2225 } 2268 }
2226 2269
2227 void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage) { 2270 void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage) {
2228 const std::set<std::string> switches = 2271 const std::set<std::string> switches =
2229 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage); 2272 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage);
2230 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches); 2273 const std::set<std::string> features =
2274 FlagsStateSingleton::GetFlagsState()->GetFeaturesFromFlags(flags_storage);
2275 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches, features);
2231 } 2276 }
2232 2277
2233 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) { 2278 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) {
2234 return static_cast<base::HistogramBase::Sample>( 2279 return static_cast<base::HistogramBase::Sample>(
2235 base::HashMetricName(switch_name)); 2280 base::HashMetricName(switch_name));
2236 } 2281 }
2237 2282
2238 void ReportAboutFlagsHistogram(const std::string& uma_histogram_name, 2283 void ReportAboutFlagsHistogram(
2239 const std::set<std::string>& flags) { 2284 const std::string& uma_histogram_name,
2240 for (const std::string& flag : flags) { 2285 const std::set<std::string>& switches,
2241 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; 2286 const std::set<std::string>& features) {
2242 if (base::StartsWith(flag, "--", base::CompareCase::SENSITIVE)) { 2287 ReportAboutFlagsHistogramSwitches(uma_histogram_name, switches);
2243 // Skip '--' before switch name. 2288 ReportAboutFlagsHistogramFeatures(uma_histogram_name, features);
2244 std::string switch_name(flag.substr(2));
2245
2246 // Kill value, if any.
2247 const size_t value_pos = switch_name.find('=');
2248 if (value_pos != std::string::npos)
2249 switch_name.resize(value_pos);
2250
2251 uma_id = GetSwitchUMAId(switch_name);
2252 } else {
2253 NOTREACHED() << "ReportAboutFlagsHistogram(): flag '" << flag
2254 << "' has incorrect format.";
2255 }
2256 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name
2257 << "' '" << flag << "', uma_id=" << uma_id;
2258
2259 // Sparse histogram macro does not cache the histogram, so it's safe
2260 // to use macro with non-static histogram name here.
2261 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id);
2262 }
2263 } 2289 }
2264 2290
2265 namespace testing { 2291 namespace testing {
2266 2292
2267 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; 2293 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0;
2268 2294
2269 const FeatureEntry* GetFeatureEntries(size_t* count) { 2295 const FeatureEntry* GetFeatureEntries(size_t* count) {
2270 *count = arraysize(kFeatureEntries); 2296 *count = arraysize(kFeatureEntries);
2271 return kFeatureEntries; 2297 return kFeatureEntries;
2272 } 2298 }
2273 2299
2274 } // namespace testing 2300 } // namespace testing
2275 2301
2276 } // namespace about_flags 2302 } // namespace about_flags
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/about_flags_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698