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

Side by Side Diff: components/browser_watcher/postmortem_report_collector.h

Issue 2722223002: Separate collection logic from the extraction of the report (Closed)
Patch Set: Address Siggi's comments Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // Following an unclean shutdown, a stability report can be collected and 5 // Following an unclean shutdown, a stability report can be collected and
6 // submitted for upload to a reporter. 6 // submitted for upload to a reporter.
7 7
8 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ 8 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_
9 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ 9 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 #include <memory> 13 #include <memory>
14 #include <set> 14 #include <set>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/debug/activity_analyzer.h" 18 #include "base/debug/activity_analyzer.h"
19 #include "base/files/file.h" 19 #include "base/files/file.h"
20 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
21 #include "base/gtest_prod_util.h" 21 #include "base/gtest_prod_util.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
24 #include "components/browser_watcher/postmortem_report_extractor.h"
24 #include "components/browser_watcher/stability_report.pb.h" 25 #include "components/browser_watcher/stability_report.pb.h"
25 #include "third_party/crashpad/crashpad/client/crash_report_database.h" 26 #include "third_party/crashpad/crashpad/client/crash_report_database.h"
26 27
27 namespace browser_watcher { 28 namespace browser_watcher {
28 29
29 // Collects unclean shutdown information and creates Crashpad minidumps. 30 // Handles postmortem report collection by establishing the set of stability
31 // files to collect, then for each file:
32 // - extracting a report protocol buffer
33 // - registering a crash report with the crash database
34 // - writing a minidump file for the report
30 // TODO(manzagop): throttling, graceful handling of accumulating data. 35 // TODO(manzagop): throttling, graceful handling of accumulating data.
31 // TODO(manzagop): UMA metrics and some error logging.
32 class PostmortemReportCollector { 36 class PostmortemReportCollector {
33 public: 37 public:
34 // DO NOT CHANGE VALUES. This is logged persistently in a histogram.
35 enum CollectionStatus {
36 NONE = 0,
37 SUCCESS = 1, // Successfully registered a report with Crashpad.
38 ANALYZER_CREATION_FAILED = 2,
39 DEBUG_FILE_NO_DATA = 3,
40 PREPARE_NEW_CRASH_REPORT_FAILED = 4,
41 WRITE_TO_MINIDUMP_FAILED = 5,
42 DEBUG_FILE_DELETION_FAILED = 6,
43 FINISHED_WRITING_CRASH_REPORT_FAILED = 7,
44 COLLECTION_STATUS_MAX = 8
45 };
46
47 PostmortemReportCollector(const std::string& product_name, 38 PostmortemReportCollector(const std::string& product_name,
48 const std::string& version_number, 39 const std::string& version_number,
49 const std::string& channel_name); 40 const std::string& channel_name);
50 virtual ~PostmortemReportCollector() = default; 41 virtual ~PostmortemReportCollector();
51 42
52 // Collects postmortem stability reports from files found in |debug_info_dir|, 43 // Collects postmortem stability reports from files found in |debug_info_dir|,
53 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are 44 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are
54 // then wrapped in Crashpad reports, manufactured via |report_database|. 45 // then wrapped in Crashpad reports, manufactured via |report_database|.
55 // Returns the number crash reports successfully registered with the reporter. 46 // Returns the number crash reports successfully registered with the reporter.
56 // TODO(manzagop): consider mechanisms for partial collection if this is to be 47 // TODO(manzagop): consider mechanisms for partial collection if this is to be
57 // used on a critical path. 48 // used on a critical path.
58 int CollectAndSubmitForUpload( 49 int CollectAndSubmitForUpload(
59 const base::FilePath& debug_info_dir, 50 const base::FilePath& debug_info_dir,
60 const base::FilePath::StringType& debug_file_pattern, 51 const base::FilePath::StringType& debug_file_pattern,
(...skipping 28 matching lines...) Expand all
89 virtual std::vector<base::FilePath> GetDebugStateFilePaths( 80 virtual std::vector<base::FilePath> GetDebugStateFilePaths(
90 const base::FilePath& debug_info_dir, 81 const base::FilePath& debug_info_dir,
91 const base::FilePath::StringType& debug_file_pattern, 82 const base::FilePath::StringType& debug_file_pattern,
92 const std::set<base::FilePath>& excluded_debug_files); 83 const std::set<base::FilePath>& excluded_debug_files);
93 84
94 CollectionStatus CollectAndSubmit( 85 CollectionStatus CollectAndSubmit(
95 const crashpad::UUID& client_id, 86 const crashpad::UUID& client_id,
96 const base::FilePath& file, 87 const base::FilePath& file,
97 crashpad::CrashReportDatabase* report_database); 88 crashpad::CrashReportDatabase* report_database);
98 89
99 // Virtual for unittesting. 90 virtual CollectionStatus Collect(const base::FilePath& stability_file,
100 // TODO(manzagop): move this for reuse in live scenario. 91 StabilityReport* report);
101 virtual CollectionStatus Collect(const base::FilePath& debug_state_file,
102 std::unique_ptr<StabilityReport>* report);
103 void CollectThread(
104 const base::debug::ThreadActivityAnalyzer::Snapshot& snapshot,
105 ThreadState* thread_state);
106 92
107 virtual bool WriteReportToMinidump(StabilityReport* report, 93 virtual bool WriteReportToMinidump(StabilityReport* report,
108 const crashpad::UUID& client_id, 94 const crashpad::UUID& client_id,
109 const crashpad::UUID& report_id, 95 const crashpad::UUID& report_id,
110 base::PlatformFile minidump_file); 96 base::PlatformFile minidump_file);
111 97
112 std::string product_name_; 98 std::string product_name_;
113 std::string version_number_; 99 std::string version_number_;
114 std::string channel_name_; 100 std::string channel_name_;
115 101
116 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); 102 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector);
117 }; 103 };
118 104
119 } // namespace browser_watcher 105 } // namespace browser_watcher
120 106
121 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ 107 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_
OLDNEW
« no previous file with comments | « components/browser_watcher/BUILD.gn ('k') | components/browser_watcher/postmortem_report_collector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698