This repository has been archived by the owner on Mar 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
9000-disable-metrics.patch
209 lines (194 loc) · 7.51 KB
/
9000-disable-metrics.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -1225,6 +1225,11 @@ const FeatureEntry::FeatureVariation kSi
//
// When adding a new choice, add it to the end of the list.
const FeatureEntry kFeatureEntries[] = {
+ {"enable-metrics",
+ "Record metrics",
+ "Record histograms and user actions.",
+ kOsAll, SINGLE_VALUE_TYPE("enable-metrics")},
+
{"ignore-gpu-blacklist", flag_descriptions::kIgnoreGpuBlacklistName,
flag_descriptions::kIgnoreGpuBlacklistDescription, kOsAll,
SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)},
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -575,6 +575,8 @@ jumbo_component("base") {
"message_loop/watchable_io_message_pump_posix.h",
"metrics/bucket_ranges.cc",
"metrics/bucket_ranges.h",
+ "metrics/command_line_handler.cc",
+ "metrics/command_line_handler.h",
"metrics/dummy_histogram.cc",
"metrics/dummy_histogram.h",
"metrics/field_trial.cc",
--- a/tools/gn/bootstrap/bootstrap.py
+++ b/tools/gn/bootstrap/bootstrap.py
@@ -535,6 +535,7 @@ def write_gn_ninja(path, root_gen_dir, o
'base/message_loop/message_pump_default.cc',
'base/message_loop/watchable_io_message_pump_posix.cc',
'base/metrics/bucket_ranges.cc',
+ 'base/metrics/command_line_handler.cc',
'base/metrics/dummy_histogram.cc',
'base/metrics/field_trial.cc',
'base/metrics/field_trial_param_associator.cc',
--- /dev/null
+++ b/base/metrics/command_line_handler.cc
@@ -0,0 +1,11 @@
+#include "base/metrics/command_line_handler.h"
+
+#include "base/command_line.h"
+
+namespace base {
+
+bool MetricsEnabled() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch("enable-metrics");
+}
+
+} // namespace base
--- /dev/null
+++ b/base/metrics/command_line_handler.h
@@ -0,0 +1,11 @@
+#ifndef BASE_METRICS_COMMAND_LINE_HANDLER_H_
+#define BASE_METRICS_COMMAND_LINE_HANDLER_H_
+
+namespace base {
+
+// Checks the command-line flag 'enable-metrics'.
+bool MetricsEnabled();
+
+} // namespace base
+
+#endif // BASE_METRICS_COMMAND_LINE_HANDLER_H_
--- a/components/metrics/expired_histograms_checker.cc
+++ b/components/metrics/expired_histograms_checker.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/metrics/command_line_handler.h"
#include "components/metrics/expired_histograms_checker.h"
#include <algorithm>
@@ -15,6 +16,9 @@ ExpiredHistogramsChecker::ExpiredHistogr
ExpiredHistogramsChecker::~ExpiredHistogramsChecker() {}
bool ExpiredHistogramsChecker::ShouldRecord(uint64_t histogram_hash) const {
+ if (!base::MetricsEnabled())
+ return false;
+
return !std::binary_search(array_, array_ + size_, histogram_hash);
}
--- a/base/metrics/user_metrics.cc
+++ b/base/metrics/user_metrics.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/metrics/command_line_handler.h"
#include "base/metrics/user_metrics.h"
#include <stddef.h>
@@ -25,10 +26,16 @@ LazyInstance<scoped_refptr<SingleThreadT
} // namespace
void RecordAction(const UserMetricsAction& action) {
+ if (!MetricsEnabled())
+ return;
+
RecordComputedAction(action.str_);
}
void RecordComputedAction(const std::string& action) {
+ if (!MetricsEnabled())
+ return;
+
if (!g_task_runner.Get()) {
DCHECK(g_callbacks.Get().empty());
return;
@@ -46,6 +53,9 @@ void RecordComputedAction(const std::str
}
void AddActionCallback(const ActionCallback& callback) {
+ if (!MetricsEnabled())
+ return;
+
// Only allow adding a callback if the task runner is set.
DCHECK(g_task_runner.Get());
DCHECK(g_task_runner.Get()->BelongsToCurrentThread());
--- a/chrome/browser/ui/tab_helpers.cc
+++ b/chrome/browser/ui/tab_helpers.cc
@@ -8,6 +8,7 @@
#include <utility>
#include "base/command_line.h"
+#include "base/metrics/command_line_handler.h"
#include "base/feature_list.h"
#include "base/time/default_tick_clock.h"
#include "build/build_config.h"
@@ -204,8 +205,10 @@ void TabHelpers::AttachTabHelpers(WebCon
ClientHintsObserver::CreateForWebContents(web_contents);
ConnectionHelpTabHelper::CreateForWebContents(web_contents);
CoreTabHelper::CreateForWebContents(web_contents);
- data_use_measurement::DataUseWebContentsObserver::CreateForWebContents(
- web_contents);
+ if (base::MetricsEnabled()) {
+ data_use_measurement::DataUseWebContentsObserver::CreateForWebContents(
+ web_contents);
+ }
ExternalProtocolObserver::CreateForWebContents(web_contents);
favicon::CreateContentFaviconDriverForWebContents(web_contents);
FindTabHelper::CreateForWebContents(web_contents);
@@ -220,13 +223,19 @@ void TabHelpers::AttachTabHelpers(WebCon
HistoryTabHelper::CreateForWebContents(web_contents);
InfoBarService::CreateForWebContents(web_contents);
InstallableManager::CreateForWebContents(web_contents);
- metrics::RendererUptimeWebContentsObserver::CreateForWebContents(
- web_contents);
+ if (base::MetricsEnabled()) {
+ metrics::RendererUptimeWebContentsObserver::CreateForWebContents(
+ web_contents);
+ }
MixedContentSettingsTabHelper::CreateForWebContents(web_contents);
NavigationCorrectionTabObserver::CreateForWebContents(web_contents);
- NavigationMetricsRecorder::CreateForWebContents(web_contents);
+ if (base::MetricsEnabled()) {
+ NavigationMetricsRecorder::CreateForWebContents(web_contents);
+ }
OutOfMemoryReporter::CreateForWebContents(web_contents);
- chrome::InitializePageLoadMetricsForWebContents(web_contents);
+ if (base::MetricsEnabled()) {
+ chrome::InitializePageLoadMetricsForWebContents(web_contents);
+ }
PDFPluginPlaceholderObserver::CreateForWebContents(web_contents);
PermissionRequestManager::CreateForWebContents(web_contents);
// The PopupBlockerTabHelper has an implicit dependency on
@@ -251,7 +260,9 @@ void TabHelpers::AttachTabHelpers(WebCon
// is taken over by ChromeContentSettingsClient. http://crbug.com/387075
TabSpecificContentSettings::CreateForWebContents(web_contents);
TabUIHelper::CreateForWebContents(web_contents);
- ukm::InitializeSourceUrlRecorderForWebContents(web_contents);
+ if (base::MetricsEnabled()) {
+ ukm::InitializeSourceUrlRecorderForWebContents(web_contents);
+ }
vr::VrTabHelper::CreateForWebContents(web_contents);
// NO! Do not just add your tab helper here. This is a large alphabetized
@@ -297,7 +308,9 @@ void TabHelpers::AttachTabHelpers(WebCon
#if defined(OS_WIN) || defined(OS_MACOSX) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
- metrics::DesktopSessionDurationObserver::CreateForWebContents(web_contents);
+ if (base::MetricsEnabled()) {
+ metrics::DesktopSessionDurationObserver::CreateForWebContents(web_contents);
+ }
#endif
// --- Feature tab helpers behind flags ---
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc
@@ -17,6 +17,7 @@
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/metrics/command_line_handler.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/persistent_histogram_allocator.h"
@@ -599,6 +600,9 @@ void ChromeMetricsServiceClient::Initial
}
void ChromeMetricsServiceClient::RegisterMetricsServiceProviders() {
+ if (!base::MetricsEnabled())
+ return;
+
PrefService* local_state = g_browser_process->local_state();
// Gets access to persistent metrics shared by sub-processes.