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