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

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

Issue 344883002: Collect UMA statistics on which chrome://flags lead to chrome restart on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 4 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>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/metrics/sparse_histogram.h"
15 #include "base/numerics/safe_conversions.h"
14 #include "base/stl_util.h" 16 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 19 #include "base/values.h"
18 #include "cc/base/switches.h" 20 #include "cc/base/switches.h"
19 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" 21 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
20 #include "chrome/browser/flags_storage.h" 22 #include "chrome/browser/flags_storage.h"
21 #include "chrome/common/chrome_content_client.h" 23 #include "chrome/common/chrome_content_client.h"
22 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
23 #include "components/autofill/core/common/autofill_switches.h" 25 #include "components/autofill/core/common/autofill_switches.h"
24 #include "components/cloud_devices/common/cloud_devices_switches.h" 26 #include "components/cloud_devices/common/cloud_devices_switches.h"
27 #include "components/metrics/metrics_hashes.h"
25 #include "components/nacl/common/nacl_switches.h" 28 #include "components/nacl/common/nacl_switches.h"
26 #include "content/public/browser/user_metrics.h" 29 #include "content/public/browser/user_metrics.h"
27 #include "extensions/common/switches.h" 30 #include "extensions/common/switches.h"
28 #include "grit/chromium_strings.h" 31 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
30 #include "grit/google_chrome_strings.h" 33 #include "grit/google_chrome_strings.h"
31 #include "media/base/media_switches.h" 34 #include "media/base/media_switches.h"
32 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/ui_base_switches.h" 36 #include "ui/base/ui_base_switches.h"
34 #include "ui/display/display_switches.h" 37 #include "ui/display/display_switches.h"
(...skipping 19 matching lines...) Expand all
54 #endif 57 #endif
55 58
56 #if defined(ENABLE_APP_LIST) 59 #if defined(ENABLE_APP_LIST)
57 #include "ui/app_list/app_list_switches.h" 60 #include "ui/app_list/app_list_switches.h"
58 #endif 61 #endif
59 62
60 using base::UserMetricsAction; 63 using base::UserMetricsAction;
61 64
62 namespace about_flags { 65 namespace about_flags {
63 66
67 const uint32_t kBadSwitchFormatHistogramId = 0;
68
64 // Macros to simplify specifying the type. 69 // Macros to simplify specifying the type.
65 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ 70 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
66 Experiment::SINGLE_VALUE, \ 71 Experiment::SINGLE_VALUE, \
67 command_line_switch, switch_value, NULL, NULL, NULL, 0 72 command_line_switch, switch_value, NULL, NULL, NULL, 0
68 #define SINGLE_VALUE_TYPE(command_line_switch) \ 73 #define SINGLE_VALUE_TYPE(command_line_switch) \
69 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "") 74 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
70 #define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \ 75 #define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \
71 disable_switch, disable_value) \ 76 disable_switch, disable_value) \
72 Experiment::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \ 77 Experiment::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \
73 disable_switch, disable_value, NULL, 3 78 disable_switch, disable_value, NULL, 3
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 2142
2138 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, 2143 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
2139 CommandLine* command_line, 2144 CommandLine* command_line,
2140 SentinelsMode sentinels) { 2145 SentinelsMode sentinels) {
2141 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, 2146 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
2142 command_line, 2147 command_line,
2143 sentinels); 2148 sentinels);
2144 } 2149 }
2145 2150
2146 bool AreSwitchesIdenticalToCurrentCommandLine( 2151 bool AreSwitchesIdenticalToCurrentCommandLine(
2147 const CommandLine& new_cmdline, const CommandLine& active_cmdline) { 2152 const CommandLine& new_cmdline,
2153 const CommandLine& active_cmdline,
2154 std::set<CommandLine::StringType>* out_difference) {
2148 std::set<CommandLine::StringType> new_flags = 2155 std::set<CommandLine::StringType> new_flags =
2149 ExtractFlagsFromCommandLine(new_cmdline); 2156 ExtractFlagsFromCommandLine(new_cmdline);
2150 std::set<CommandLine::StringType> active_flags = 2157 std::set<CommandLine::StringType> active_flags =
2151 ExtractFlagsFromCommandLine(active_cmdline); 2158 ExtractFlagsFromCommandLine(active_cmdline);
2152 2159
2160 bool result = false;
2153 // Needed because std::equal doesn't check if the 2nd set is empty. 2161 // Needed because std::equal doesn't check if the 2nd set is empty.
2154 if (new_flags.size() != active_flags.size()) 2162 if (new_flags.size() == active_flags.size()) {
2155 return false; 2163 result =
2164 std::equal(new_flags.begin(), new_flags.end(), active_flags.begin());
2165 }
2156 2166
2157 return std::equal(new_flags.begin(), new_flags.end(), active_flags.begin()); 2167 if (out_difference && !result) {
2168 std::set_symmetric_difference(
2169 new_flags.begin(),
2170 new_flags.end(),
2171 active_flags.begin(),
2172 active_flags.end(),
2173 std::inserter(*out_difference, out_difference->begin()));
2174 }
2175
2176 return result;
2158 } 2177 }
2159 2178
2160 void GetFlagsExperimentsData(FlagsStorage* flags_storage, 2179 void GetFlagsExperimentsData(FlagsStorage* flags_storage,
2161 FlagAccess access, 2180 FlagAccess access,
2162 base::ListValue* supported_experiments, 2181 base::ListValue* supported_experiments,
2163 base::ListValue* unsupported_experiments) { 2182 base::ListValue* unsupported_experiments) {
2164 std::set<std::string> enabled_experiments; 2183 std::set<std::string> enabled_experiments;
2165 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); 2184 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments);
2166 2185
2167 int current_platform = GetCurrentPlatform(); 2186 int current_platform = GetCurrentPlatform();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 action += *it; 2274 action += *it;
2256 content::RecordComputedAction(action); 2275 content::RecordComputedAction(action);
2257 } 2276 }
2258 // Since flag metrics are recorded every startup, add a tick so that the 2277 // Since flag metrics are recorded every startup, add a tick so that the
2259 // stats can be made meaningful. 2278 // stats can be made meaningful.
2260 if (flags.size()) 2279 if (flags.size())
2261 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); 2280 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
2262 content::RecordAction(UserMetricsAction("StartupTick")); 2281 content::RecordAction(UserMetricsAction("StartupTick"));
2263 } 2282 }
2264 2283
2284 uint32_t GetSwitchUMAId(const std::string& switch_name) {
2285 return static_cast<uint32_t>(metrics::HashMetricName(switch_name));
2286 }
2287
2288 void ReportCustomFlags(const std::string& uma_histogram_hame,
2289 const std::set<std::string>& command_line_difference) {
2290 for (std::set<std::string>::const_iterator it =
2291 command_line_difference.begin();
2292 it != command_line_difference.end();
2293 ++it) {
2294 int uma_id = about_flags::kBadSwitchFormatHistogramId;
2295 if (StartsWithASCII(*it, "--", true /* case_sensitive */)) {
2296 // Skip '--' before switch name.
2297 std::string switch_name(it->substr(2));
2298
2299 // Kill value, if any.
2300 const size_t value_pos = switch_name.find('=');
2301 if (value_pos != std::string::npos)
2302 switch_name.resize(value_pos);
2303
2304 uma_id = GetSwitchUMAId(switch_name);
2305 } else {
2306 NOTREACHED() << "ReportCustomFlags(): flag '" << *it
2307 << "' has incorrect format.";
2308 }
2309 VLOG(1) << "ReportCustomFlags(): histogram='" << uma_histogram_hame << "' '"
sky 2014/08/11 23:45:44 Is there a reason you want VLOG here and not DVLOG
Alexander Alekseev 2014/08/12 18:02:25 The idea is see the "reason to restart" in verbose
Alexander Alekseev 2014/08/12 18:03:15 "The idea is to see" ...
sky 2014/08/12 19:57:13 Certainly, but why release and not debug? Do you r
Alexander Alekseev 2014/08/13 19:59:34 Running debug build on device is very slow. So it
2310 << *it << "', uma_id=" << uma_id;
2311
2312 // Sparse histogram macro does not cache the histogram, so it's safe
2313 // to use macro with non-static histogram name here.
2314 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_hame, uma_id);
2315 }
2316 }
2317
2265 ////////////////////////////////////////////////////////////////////////////// 2318 //////////////////////////////////////////////////////////////////////////////
2266 // FlagsState implementation. 2319 // FlagsState implementation.
2267 2320
2268 namespace { 2321 namespace {
2269 2322
2270 typedef std::map<std::string, std::pair<std::string, std::string> > 2323 typedef std::map<std::string, std::pair<std::string, std::string> >
2271 NameToSwitchAndValueMap; 2324 NameToSwitchAndValueMap;
2272 2325
2273 void SetFlagToSwitchMapping(const std::string& key, 2326 void SetFlagToSwitchMapping(const std::string& key,
2274 const std::string& switch_name, 2327 const std::string& switch_name,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 } 2507 }
2455 2508
2456 const Experiment* GetExperiments(size_t* count) { 2509 const Experiment* GetExperiments(size_t* count) {
2457 *count = num_experiments; 2510 *count = num_experiments;
2458 return experiments; 2511 return experiments;
2459 } 2512 }
2460 2513
2461 } // namespace testing 2514 } // namespace testing
2462 2515
2463 } // namespace about_flags 2516 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698