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

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

Issue 2345033002: Log base::Features in Launch.FlagsAtStartup (Closed)
Patch Set: Clean up test and localize ReportAboutFlagsHistogram{Switches, Features} 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
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 = about_flags::testing::kBadSwitchFormatHistogramId;
2194
2195 uma_id = GetSwitchUMAId(feature);
Alexei Svitkine (slow) 2016/09/16 20:50:33 Just move this initialization on line 2193 directl
lawrencewu 2016/09/16 21:20:03 Done.
2196 DVLOG(1) << "ReportAboutFlagsHistogram(): histogram='" << uma_histogram_name
2197 << "' '" << feature << "', uma_id=" << uma_id;
2198
2199 // Sparse histogram macro does not cache the histogram, so it's safe
2200 // to use macro with non-static histogram name here.
2201 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_name, uma_id);
2202 }
2203 }
2204
2160 } // namespace 2205 } // namespace
2161 2206
2162 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, 2207 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
2163 base::CommandLine* command_line, 2208 base::CommandLine* command_line,
2164 flags_ui::SentinelsMode sentinels) { 2209 flags_ui::SentinelsMode sentinels) {
2165 if (command_line->HasSwitch(switches::kNoExperiments)) 2210 if (command_line->HasSwitch(switches::kNoExperiments))
2166 return; 2211 return;
2167 2212
2168 FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches( 2213 FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches(
2169 flags_storage, command_line, sentinels, switches::kEnableFeatures, 2214 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); 2265 FlagsStateSingleton::GetFlagsState()->RemoveFlagsSwitches(switch_list);
2221 } 2266 }
2222 2267
2223 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) { 2268 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) {
2224 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage); 2269 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage);
2225 } 2270 }
2226 2271
2227 void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage) { 2272 void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage) {
2228 const std::set<std::string> switches = 2273 const std::set<std::string> switches =
2229 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage); 2274 FlagsStateSingleton::GetFlagsState()->GetSwitchesFromFlags(flags_storage);
2230 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches); 2275 const std::set<std::string> features =
2276 FlagsStateSingleton::GetFlagsState()->GetFeaturesFromFlags(flags_storage);
2277 ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches, features);
2231 } 2278 }
2232 2279
2233 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) { 2280 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name) {
2234 return static_cast<base::HistogramBase::Sample>( 2281 return static_cast<base::HistogramBase::Sample>(
2235 base::HashMetricName(switch_name)); 2282 base::HashMetricName(switch_name));
2236 } 2283 }
2237 2284
2238 void ReportAboutFlagsHistogram(const std::string& uma_histogram_name, 2285 void ReportAboutFlagsHistogram(
2239 const std::set<std::string>& flags) { 2286 const std::string& uma_histogram_name,
2240 for (const std::string& flag : flags) { 2287 const std::set<std::string>& switches,
2241 int uma_id = about_flags::testing::kBadSwitchFormatHistogramId; 2288 const std::set<std::string>& features) {
2242 if (base::StartsWith(flag, "--", base::CompareCase::SENSITIVE)) { 2289 ReportAboutFlagsHistogramSwitches(uma_histogram_name, switches);
2243 // Skip '--' before switch name. 2290 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 } 2291 }
2264 2292
2265 namespace testing { 2293 namespace testing {
2266 2294
2267 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; 2295 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0;
2268 2296
2269 const FeatureEntry* GetFeatureEntries(size_t* count) { 2297 const FeatureEntry* GetFeatureEntries(size_t* count) {
2270 *count = arraysize(kFeatureEntries); 2298 *count = arraysize(kFeatureEntries);
2271 return kFeatureEntries; 2299 return kFeatureEntries;
2272 } 2300 }
2273 2301
2274 } // namespace testing 2302 } // namespace testing
2275 2303
2276 } // namespace about_flags 2304 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698