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

Side by Side Diff: components/browser_watcher/watcher_metrics_provider_win.cc

Issue 2963573004: [Cleanup] Migrate the WatcherMetricsProvider to use the Task Scheduler. (Closed)
Patch Set: Fix threading in tests? Created 3 years, 5 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) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "components/browser_watcher/watcher_metrics_provider_win.h" 5 #include "components/browser_watcher/watcher_metrics_provider_win.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/feature_list.h" 16 #include "base/feature_list.h"
17 #include "base/metrics/field_trial_params.h" 17 #include "base/metrics/field_trial_params.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/metrics/histogram_base.h" 19 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/metrics/sparse_histogram.h" 21 #include "base/metrics/sparse_histogram.h"
22 #include "base/process/process.h" 22 #include "base/process/process.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/task_scheduler/post_task.h"
27 #include "base/task_scheduler/task_traits.h"
26 #include "base/win/registry.h" 28 #include "base/win/registry.h"
27 #include "components/browser_watcher/features.h" 29 #include "components/browser_watcher/features.h"
28 #include "components/browser_watcher/postmortem_report_collector.h" 30 #include "components/browser_watcher/postmortem_report_collector.h"
29 #include "components/browser_watcher/stability_paths.h" 31 #include "components/browser_watcher/stability_paths.h"
30 #include "components/browser_watcher/system_session_analyzer_win.h" 32 #include "components/browser_watcher/system_session_analyzer_win.h"
31 #include "third_party/crashpad/crashpad/client/crash_report_database.h" 33 #include "third_party/crashpad/crashpad/client/crash_report_database.h"
32 34
33 namespace browser_watcher { 35 namespace browser_watcher {
34 36
35 namespace { 37 namespace {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 GET_STABILITY_FILE_PATH_FAILED = 2, 157 GET_STABILITY_FILE_PATH_FAILED = 2,
156 CRASHPAD_DATABASE_INIT_FAILED = 3, 158 CRASHPAD_DATABASE_INIT_FAILED = 3,
157 INIT_STATUS_MAX = 4 159 INIT_STATUS_MAX = 4
158 }; 160 };
159 161
160 void LogCollectionInitStatus(CollectionInitializationStatus status) { 162 void LogCollectionInitStatus(CollectionInitializationStatus status) {
161 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.Collect.InitStatus", status, 163 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.Collect.InitStatus", status,
162 INIT_STATUS_MAX); 164 INIT_STATUS_MAX);
163 } 165 }
164 166
167 // Returns a task runner appropriate for running background tasks that perform
168 // file I/O.
169 scoped_refptr<base::TaskRunner> CreateBackgroundTaskRunner() {
170 return base::CreateSequencedTaskRunnerWithTraits(
171 {base::MayBlock(), base::TaskPriority::BACKGROUND,
172 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
173 }
174
165 } // namespace 175 } // namespace
166 176
167 const char WatcherMetricsProviderWin::kBrowserExitCodeHistogramName[] = 177 const char WatcherMetricsProviderWin::kBrowserExitCodeHistogramName[] =
168 "Stability.BrowserExitCodes"; 178 "Stability.BrowserExitCodes";
169 179
170 WatcherMetricsProviderWin::WatcherMetricsProviderWin( 180 WatcherMetricsProviderWin::WatcherMetricsProviderWin(
171 const base::string16& registry_path, 181 const base::string16& registry_path,
172 const base::FilePath& user_data_dir, 182 const base::FilePath& user_data_dir,
173 const base::FilePath& crash_dir, 183 const base::FilePath& crash_dir,
174 const GetExecutableDetailsCallback& exe_details_cb, 184 const GetExecutableDetailsCallback& exe_details_cb)
175 base::TaskRunner* io_task_runner)
176 : recording_enabled_(false), 185 : recording_enabled_(false),
177 cleanup_scheduled_(false), 186 cleanup_scheduled_(false),
178 registry_path_(registry_path), 187 registry_path_(registry_path),
179 user_data_dir_(user_data_dir), 188 user_data_dir_(user_data_dir),
180 crash_dir_(crash_dir), 189 crash_dir_(crash_dir),
181 exe_details_cb_(exe_details_cb), 190 exe_details_cb_(exe_details_cb),
182 io_task_runner_(io_task_runner), 191 task_runner_(CreateBackgroundTaskRunner()),
183 weak_ptr_factory_(this) { 192 weak_ptr_factory_(this) {}
184 DCHECK(io_task_runner_);
185 }
186 193
187 WatcherMetricsProviderWin::~WatcherMetricsProviderWin() { 194 WatcherMetricsProviderWin::~WatcherMetricsProviderWin() {
188 } 195 }
189 196
190 void WatcherMetricsProviderWin::OnRecordingEnabled() { 197 void WatcherMetricsProviderWin::OnRecordingEnabled() {
191 recording_enabled_ = true; 198 recording_enabled_ = true;
192 } 199 }
193 200
194 void WatcherMetricsProviderWin::OnRecordingDisabled() { 201 void WatcherMetricsProviderWin::OnRecordingDisabled() {
195 if (!recording_enabled_ && !cleanup_scheduled_) { 202 if (!recording_enabled_ && !cleanup_scheduled_) {
196 // When metrics reporting is disabled, the providers get an 203 // When metrics reporting is disabled, the providers get an
197 // OnRecordingDisabled notification at startup. Use that first notification 204 // OnRecordingDisabled notification at startup. Use that first notification
198 // to issue the cleanup task. 205 // to issue the cleanup task.
199 io_task_runner_->PostTask( 206 task_runner_->PostTask(
200 FROM_HERE, base::Bind(&DeleteExitCodeRegistryKey, registry_path_)); 207 FROM_HERE, base::BindOnce(&DeleteExitCodeRegistryKey, registry_path_));
201 208
202 cleanup_scheduled_ = true; 209 cleanup_scheduled_ = true;
203 } 210 }
204 } 211 }
205 212
206 void WatcherMetricsProviderWin::ProvideStabilityMetrics( 213 void WatcherMetricsProviderWin::ProvideStabilityMetrics(
207 metrics::SystemProfileProto* /* system_profile_proto */) { 214 metrics::SystemProfileProto* /* system_profile_proto */) {
208 // Note that if there are multiple instances of Chrome running in the same 215 // Note that if there are multiple instances of Chrome running in the same
209 // user account, there's a small race that will double-report the exit codes 216 // user account, there's a small race that will double-report the exit codes
210 // from both/multiple instances. This ought to be vanishingly rare and will 217 // from both/multiple instances. This ought to be vanishingly rare and will
211 // only manifest as low-level "random" noise. To work around this it would be 218 // only manifest as low-level "random" noise. To work around this it would be
212 // necessary to implement some form of global locking, which is not worth it 219 // necessary to implement some form of global locking, which is not worth it
213 // here. 220 // here.
214 RecordExitCodes(registry_path_); 221 RecordExitCodes(registry_path_);
215 } 222 }
216 223
217 void WatcherMetricsProviderWin::CollectPostmortemReports( 224 void WatcherMetricsProviderWin::CollectPostmortemReports(
218 const base::Closure& done_callback) { 225 const base::Closure& done_callback) {
219 io_task_runner_->PostTaskAndReply( 226 task_runner_->PostTaskAndReply(
220 FROM_HERE, 227 FROM_HERE,
221 base::Bind( 228 base::BindOnce(&WatcherMetricsProviderWin::CollectPostmortemReportsImpl,
222 &WatcherMetricsProviderWin::CollectPostmortemReportsOnBlockingPool, 229 weak_ptr_factory_.GetWeakPtr()),
223 weak_ptr_factory_.GetWeakPtr()),
224 done_callback); 230 done_callback);
225 } 231 }
226 232
227 // TODO(manzagop): consider mechanisms for partial collection if this is to be 233 // TODO(manzagop): consider mechanisms for partial collection if this is to be
228 // used on a critical path. 234 // used on a critical path.
229 void WatcherMetricsProviderWin::CollectPostmortemReportsOnBlockingPool() { 235 void WatcherMetricsProviderWin::CollectPostmortemReportsImpl() {
230 SCOPED_UMA_HISTOGRAM_TIMER("ActivityTracker.Collect.TotalTime"); 236 SCOPED_UMA_HISTOGRAM_TIMER("ActivityTracker.Collect.TotalTime");
231 237
232 bool is_stability_debugging_on = 238 bool is_stability_debugging_on =
233 base::FeatureList::IsEnabled(browser_watcher::kStabilityDebuggingFeature); 239 base::FeatureList::IsEnabled(browser_watcher::kStabilityDebuggingFeature);
234 if (!is_stability_debugging_on) { 240 if (!is_stability_debugging_on) {
235 return; // TODO(manzagop): scan for possible data to delete? 241 return; // TODO(manzagop): scan for possible data to delete?
236 } 242 }
237 243
238 if (user_data_dir_.empty() || crash_dir_.empty()) { 244 if (user_data_dir_.empty() || crash_dir_.empty()) {
manzagop (departed) 2017/06/30 20:11:43 Sidenote, this reminds me I have a bug to make thi
239 LogCollectionInitStatus(UNKNOWN_DIR); 245 LogCollectionInitStatus(UNKNOWN_DIR);
240 return; 246 return;
241 } 247 }
242 248
243 // Determine which files to harvest. 249 // Determine which files to harvest.
244 base::FilePath stability_dir = GetStabilityDir(user_data_dir_); 250 base::FilePath stability_dir = GetStabilityDir(user_data_dir_);
245 251
246 base::FilePath current_stability_file; 252 base::FilePath current_stability_file;
247 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir_, 253 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir_,
248 &current_stability_file)) { 254 &current_stability_file)) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 291
286 const size_t kSystemSessionsToInspect = 5U; 292 const size_t kSystemSessionsToInspect = 5U;
287 SystemSessionAnalyzer analyzer(kSystemSessionsToInspect); 293 SystemSessionAnalyzer analyzer(kSystemSessionsToInspect);
288 PostmortemReportCollector collector( 294 PostmortemReportCollector collector(
289 base::UTF16ToUTF8(product_name), base::UTF16ToUTF8(version_number), 295 base::UTF16ToUTF8(product_name), base::UTF16ToUTF8(version_number),
290 base::UTF16ToUTF8(channel_name), crashpad_database.get(), &analyzer); 296 base::UTF16ToUTF8(channel_name), crashpad_database.get(), &analyzer);
291 collector.Process(stability_files); 297 collector.Process(stability_files);
292 } 298 }
293 299
294 } // namespace browser_watcher 300 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698