OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chrome_browser_field_trials_desktop.h" | 5 #include "chrome/browser/chrome_browser_field_trials_desktop.h" |
6 | 6 |
| 7 #include <map> |
7 #include <string> | 8 #include <string> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/debug/activity_tracker.h" | 11 #include "base/debug/activity_tracker.h" |
11 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/files/file_util.h" |
12 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram_macros.h" |
13 #include "base/path_service.h" | 16 #include "base/path_service.h" |
14 #include "chrome/browser/prerender/prerender_field_trial.h" | 17 #include "chrome/browser/prerender/prerender_field_trial.h" |
15 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/variations/variations_util.h" | 20 #include "chrome/common/variations/variations_util.h" |
| 21 #include "components/browser_watcher/features.h" |
18 #include "components/variations/variations_associated_data.h" | 22 #include "components/variations/variations_associated_data.h" |
19 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
20 | 24 |
| 25 #if defined(OS_WIN) |
| 26 #include "components/browser_watcher/stability_debugging_win.h" |
| 27 #endif |
| 28 |
21 namespace chrome { | 29 namespace chrome { |
22 | 30 |
23 namespace { | 31 namespace { |
24 | 32 |
25 const base::Feature kStabilityDebuggingFeature{ | |
26 "StabilityDebugging", base::FEATURE_DISABLED_BY_DEFAULT | |
27 }; | |
28 | |
29 void SetupStunProbeTrial() { | 33 void SetupStunProbeTrial() { |
30 #if defined(ENABLE_WEBRTC) | 34 #if defined(ENABLE_WEBRTC) |
31 std::map<std::string, std::string> params; | 35 std::map<std::string, std::string> params; |
32 if (!variations::GetVariationParams("StunProbeTrial2", ¶ms)) | 36 if (!variations::GetVariationParams("StunProbeTrial2", ¶ms)) |
33 return; | 37 return; |
34 | 38 |
35 // The parameter, used by StartStunFieldTrial, should have the following | 39 // The parameter, used by StartStunFieldTrial, should have the following |
36 // format: "request_per_ip/interval/sharedsocket/batch_size/total_batches/ | 40 // format: "request_per_ip/interval/sharedsocket/batch_size/total_batches/ |
37 // server1:port/server2:port/server3:port/" | 41 // server1:port/server2:port/server3:port/" |
38 std::string cmd_param = params["request_per_ip"] + "/" + params["interval"] + | 42 std::string cmd_param = params["request_per_ip"] + "/" + params["interval"] + |
39 "/" + params["sharedsocket"] + "/" + | 43 "/" + params["sharedsocket"] + "/" + |
40 params["batch_size"] + "/" + params["total_batches"] + | 44 params["batch_size"] + "/" + params["total_batches"] + |
41 "/" + params["server1"] + "/" + params["server2"] + | 45 "/" + params["server1"] + "/" + params["server2"] + |
42 "/" + params["server3"] + "/" + params["server4"] + | 46 "/" + params["server3"] + "/" + params["server4"] + |
43 "/" + params["server5"] + "/" + params["server6"]; | 47 "/" + params["server5"] + "/" + params["server6"]; |
44 | 48 |
45 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 49 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
46 switches::kWebRtcStunProbeTrialParameter, cmd_param); | 50 switches::kWebRtcStunProbeTrialParameter, cmd_param); |
47 #endif | 51 #endif |
48 } | 52 } |
49 | 53 |
| 54 #if defined(OS_WIN) |
| 55 // DO NOT CHANGE VALUES. This is logged persistently in a histogram. |
| 56 enum StabilityDebuggingInitializationStatus { |
| 57 INIT_SUCCESS = 0, |
| 58 CREATE_STABILITY_DIR_FAILED = 1, |
| 59 GET_STABILITY_FILE_PATH_FAILED = 2, |
| 60 INIT_STATUS_MAX = 3 |
| 61 }; |
| 62 |
| 63 void LogStabilityDebuggingInitStatus( |
| 64 StabilityDebuggingInitializationStatus status) { |
| 65 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.Record.InitStatus", status, |
| 66 INIT_STATUS_MAX); |
| 67 } |
| 68 |
50 void SetupStabilityDebugging() { | 69 void SetupStabilityDebugging() { |
51 if (!base::FeatureList::IsEnabled(kStabilityDebuggingFeature)) | 70 if (!base::FeatureList::IsEnabled( |
| 71 browser_watcher::kStabilityDebuggingFeature)) { |
52 return; | 72 return; |
| 73 } |
53 | 74 |
54 // TODO(bcwhite): Adjust these numbers once there is real data to show | 75 // TODO(bcwhite): Adjust these numbers once there is real data to show |
55 // just how much of an arena is necessary. | 76 // just how much of an arena is necessary. |
56 const size_t kMemorySize = 1 << 20; // 1 MiB | 77 const size_t kMemorySize = 1 << 20; // 1 MiB |
57 const int kStackDepth = 4; | 78 const int kStackDepth = 4; |
58 const uint64_t kAllocatorId = 0; | 79 const uint64_t kAllocatorId = 0; |
59 | 80 |
| 81 // Ensure the stability directory exists and determine the stability file's |
| 82 // path. |
| 83 base::FilePath user_data_dir; |
| 84 if (!base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir) || |
| 85 !base::CreateDirectory(browser_watcher::GetStabilityDir(user_data_dir))) { |
| 86 LOG(ERROR) << "Failed to create the stability directory."; |
| 87 LogStabilityDebuggingInitStatus(CREATE_STABILITY_DIR_FAILED); |
| 88 return; |
| 89 } |
| 90 base::FilePath stability_file; |
| 91 if (!browser_watcher::GetStabilityFileForProcess( |
| 92 base::Process::Current(), user_data_dir, &stability_file)) { |
| 93 LOG(ERROR) << "Failed to obtain stability file's path."; |
| 94 LogStabilityDebuggingInitStatus(GET_STABILITY_FILE_PATH_FAILED); |
| 95 return; |
| 96 } |
| 97 LogStabilityDebuggingInitStatus(INIT_SUCCESS); |
| 98 |
60 // Track code activities (such as posting task, blocking on locks, and | 99 // Track code activities (such as posting task, blocking on locks, and |
61 // joining threads) that can cause hanging threads and general instability. | 100 // joining threads) that can cause hanging threads and general instability |
62 base::FilePath user_data_dir; | |
63 bool success = base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
64 DCHECK(success); | |
65 base::debug::GlobalActivityTracker::CreateWithFile( | 101 base::debug::GlobalActivityTracker::CreateWithFile( |
66 user_data_dir | 102 stability_file, kMemorySize, kAllocatorId, |
67 .AppendASCII("StabilityDebugInfo") | 103 browser_watcher::kStabilityDebuggingFeature.name, kStackDepth); |
68 .AddExtension(base::PersistentMemoryAllocator::kFileExtension), | |
69 kMemorySize, kAllocatorId, kStabilityDebuggingFeature.name, kStackDepth); | |
70 } | 104 } |
| 105 #endif // defined(OS_WIN) |
71 | 106 |
72 } // namespace | 107 } // namespace |
73 | 108 |
74 void SetupDesktopFieldTrials(const base::CommandLine& parsed_command_line) { | 109 void SetupDesktopFieldTrials(const base::CommandLine& parsed_command_line) { |
75 prerender::ConfigurePrerender(parsed_command_line); | 110 prerender::ConfigurePrerender(parsed_command_line); |
76 SetupStunProbeTrial(); | 111 SetupStunProbeTrial(); |
| 112 #if defined(OS_WIN) |
77 SetupStabilityDebugging(); | 113 SetupStabilityDebugging(); |
| 114 #endif // defined(OS_WIN) |
78 } | 115 } |
79 | 116 |
80 } // namespace chrome | 117 } // namespace chrome |
OLD | NEW |