OLD | NEW |
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/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/metrics/histogram_base.h" | 19 #include "base/metrics/histogram_base.h" |
19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
20 #include "base/metrics/sparse_histogram.h" | 21 #include "base/metrics/sparse_histogram.h" |
21 #include "base/process/process.h" | 22 #include "base/process/process.h" |
22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/string_piece.h" | 24 #include "base/strings/string_piece.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
25 #include "base/win/registry.h" | 26 #include "base/win/registry.h" |
26 #include "components/browser_watcher/features.h" | 27 #include "components/browser_watcher/features.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void WatcherMetricsProviderWin::CollectPostmortemReports( | 217 void WatcherMetricsProviderWin::CollectPostmortemReports( |
217 const base::Closure& done_callback) { | 218 const base::Closure& done_callback) { |
218 io_task_runner_->PostTaskAndReply( | 219 io_task_runner_->PostTaskAndReply( |
219 FROM_HERE, | 220 FROM_HERE, |
220 base::Bind( | 221 base::Bind( |
221 &WatcherMetricsProviderWin::CollectPostmortemReportsOnBlockingPool, | 222 &WatcherMetricsProviderWin::CollectPostmortemReportsOnBlockingPool, |
222 weak_ptr_factory_.GetWeakPtr()), | 223 weak_ptr_factory_.GetWeakPtr()), |
223 done_callback); | 224 done_callback); |
224 } | 225 } |
225 | 226 |
| 227 // TODO(manzagop): consider mechanisms for partial collection if this is to be |
| 228 // used on a critical path. |
226 void WatcherMetricsProviderWin::CollectPostmortemReportsOnBlockingPool() { | 229 void WatcherMetricsProviderWin::CollectPostmortemReportsOnBlockingPool() { |
227 // Note: the feature controls both instrumentation and collection. | 230 SCOPED_UMA_HISTOGRAM_TIMER("ActivityTracker.Collect.TotalTime"); |
| 231 |
228 bool is_stability_debugging_on = | 232 bool is_stability_debugging_on = |
229 base::FeatureList::IsEnabled(browser_watcher::kStabilityDebuggingFeature); | 233 base::FeatureList::IsEnabled(browser_watcher::kStabilityDebuggingFeature); |
230 if (!is_stability_debugging_on) { | 234 if (!is_stability_debugging_on) { |
231 // TODO(manzagop): delete possible leftover data. | 235 return; // TODO(manzagop): scan for possible data to delete? |
232 return; | |
233 } | 236 } |
234 | 237 |
235 SCOPED_UMA_HISTOGRAM_TIMER("ActivityTracker.Collect.TotalTime"); | |
236 | |
237 if (user_data_dir_.empty() || crash_dir_.empty()) { | 238 if (user_data_dir_.empty() || crash_dir_.empty()) { |
238 LOG(ERROR) << "User data directory or crash directory is unknown."; | |
239 LogCollectionInitStatus(UNKNOWN_DIR); | 239 LogCollectionInitStatus(UNKNOWN_DIR); |
240 return; | 240 return; |
241 } | 241 } |
242 | 242 |
243 // Determine the stability directory and the stability file for the current | 243 // Determine which files to harvest. |
244 // process. | |
245 base::FilePath stability_dir = GetStabilityDir(user_data_dir_); | 244 base::FilePath stability_dir = GetStabilityDir(user_data_dir_); |
| 245 |
246 base::FilePath current_stability_file; | 246 base::FilePath current_stability_file; |
247 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir_, | 247 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir_, |
248 ¤t_stability_file)) { | 248 ¤t_stability_file)) { |
249 LOG(ERROR) << "Failed to get the current stability file."; | |
250 LogCollectionInitStatus(GET_STABILITY_FILE_PATH_FAILED); | 249 LogCollectionInitStatus(GET_STABILITY_FILE_PATH_FAILED); |
251 return; | 250 return; |
252 } | 251 } |
253 const std::set<base::FilePath>& excluded_debug_files = { | 252 const std::set<base::FilePath>& excluded_stability_files = { |
254 current_stability_file}; | 253 current_stability_file}; |
255 | 254 |
| 255 std::vector<base::FilePath> stability_files = GetStabilityFiles( |
| 256 stability_dir, GetStabilityFilePattern(), excluded_stability_files); |
| 257 UMA_HISTOGRAM_COUNTS_100("ActivityTracker.Collect.StabilityFileCount", |
| 258 stability_files.size()); |
| 259 |
| 260 // If postmortem collection is disabled, delete the files. |
| 261 const bool should_collect = base::GetFieldTrialParamByFeatureAsBool( |
| 262 browser_watcher::kStabilityDebuggingFeature, |
| 263 browser_watcher::kCollectPostmortemParam, false); |
| 264 if (!should_collect) { |
| 265 PostmortemDeleter deleter; |
| 266 deleter.Process(stability_files); |
| 267 return; |
| 268 } |
| 269 |
256 // Create a database. Note: Chrome already has a g_database in crashpad.cc but | 270 // Create a database. Note: Chrome already has a g_database in crashpad.cc but |
257 // it has internal linkage. Create a new one. | 271 // it has internal linkage. Create a new one. |
258 std::unique_ptr<crashpad::CrashReportDatabase> crashpad_database = | 272 std::unique_ptr<crashpad::CrashReportDatabase> crashpad_database = |
259 crashpad::CrashReportDatabase::InitializeWithoutCreating(crash_dir_); | 273 crashpad::CrashReportDatabase::InitializeWithoutCreating(crash_dir_); |
260 if (!crashpad_database) { | 274 if (!crashpad_database) { |
261 LOG(ERROR) << "Failed to initialize a CrashPad database."; | 275 LOG(ERROR) << "Failed to initialize a CrashPad database."; |
262 LogCollectionInitStatus(CRASHPAD_DATABASE_INIT_FAILED); | 276 LogCollectionInitStatus(CRASHPAD_DATABASE_INIT_FAILED); |
263 return; | 277 return; |
264 } | 278 } |
265 | 279 |
266 LogCollectionInitStatus(INIT_SUCCESS); | 280 LogCollectionInitStatus(INIT_SUCCESS); |
267 | 281 |
268 // Get the reporter's version details. | 282 // Get the reporter's version details. |
269 base::string16 product_name, version_number, channel_name; | 283 base::string16 product_name, version_number, channel_name; |
270 exe_details_cb_.Run(&product_name, &version_number, &channel_name); | 284 exe_details_cb_.Run(&product_name, &version_number, &channel_name); |
271 | 285 |
272 const size_t kSystemSessionsToInspect = 5U; | 286 const size_t kSystemSessionsToInspect = 5U; |
273 SystemSessionAnalyzer analyzer(kSystemSessionsToInspect); | 287 SystemSessionAnalyzer analyzer(kSystemSessionsToInspect); |
274 PostmortemReportCollector collector( | 288 PostmortemReportCollector collector( |
275 base::UTF16ToUTF8(product_name), base::UTF16ToUTF8(version_number), | 289 base::UTF16ToUTF8(product_name), base::UTF16ToUTF8(version_number), |
276 base::UTF16ToUTF8(channel_name), &analyzer); | 290 base::UTF16ToUTF8(channel_name), crashpad_database.get(), &analyzer); |
277 collector.CollectAndSubmitAllPendingReports( | 291 collector.Process(stability_files); |
278 stability_dir, GetStabilityFilePattern(), excluded_debug_files, | |
279 crashpad_database.get()); | |
280 } | 292 } |
281 | 293 |
282 } // namespace browser_watcher | 294 } // namespace browser_watcher |
OLD | NEW |