Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, calling into code to extract a report proto, registering a | |
| 32 // crash report with the crash datapbase and calling into code to write out | |
|
Sigurður Ásgeirsson
2017/03/06 19:17:10
nit: datapbase->database.
manzagop (departed)
2017/03/06 21:29:39
Done.
| |
| 33 // the corresponding minidump. | |
| 30 // TODO(manzagop): throttling, graceful handling of accumulating data. | 34 // TODO(manzagop): throttling, graceful handling of accumulating data. |
| 31 // TODO(manzagop): UMA metrics and some error logging. | |
| 32 class PostmortemReportCollector { | 35 class PostmortemReportCollector { |
| 33 public: | 36 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, | 37 PostmortemReportCollector(const std::string& product_name, |
| 48 const std::string& version_number, | 38 const std::string& version_number, |
| 49 const std::string& channel_name); | 39 const std::string& channel_name); |
| 50 virtual ~PostmortemReportCollector() = default; | 40 virtual ~PostmortemReportCollector(); |
| 51 | 41 |
| 52 // Collects postmortem stability reports from files found in |debug_info_dir|, | 42 // Collects postmortem stability reports from files found in |debug_info_dir|, |
| 53 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are | 43 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are |
| 54 // then wrapped in Crashpad reports, manufactured via |report_database|. | 44 // then wrapped in Crashpad reports, manufactured via |report_database|. |
| 55 // Returns the number crash reports successfully registered with the reporter. | 45 // Returns the number crash reports successfully registered with the reporter. |
| 56 // TODO(manzagop): consider mechanisms for partial collection if this is to be | 46 // TODO(manzagop): consider mechanisms for partial collection if this is to be |
| 57 // used on a critical path. | 47 // used on a critical path. |
| 58 int CollectAndSubmitForUpload( | 48 int CollectAndSubmitForUpload( |
| 59 const base::FilePath& debug_info_dir, | 49 const base::FilePath& debug_info_dir, |
| 60 const base::FilePath::StringType& debug_file_pattern, | 50 const base::FilePath::StringType& debug_file_pattern, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 89 virtual std::vector<base::FilePath> GetDebugStateFilePaths( | 79 virtual std::vector<base::FilePath> GetDebugStateFilePaths( |
| 90 const base::FilePath& debug_info_dir, | 80 const base::FilePath& debug_info_dir, |
| 91 const base::FilePath::StringType& debug_file_pattern, | 81 const base::FilePath::StringType& debug_file_pattern, |
| 92 const std::set<base::FilePath>& excluded_debug_files); | 82 const std::set<base::FilePath>& excluded_debug_files); |
| 93 | 83 |
| 94 CollectionStatus CollectAndSubmit( | 84 CollectionStatus CollectAndSubmit( |
| 95 const crashpad::UUID& client_id, | 85 const crashpad::UUID& client_id, |
| 96 const base::FilePath& file, | 86 const base::FilePath& file, |
| 97 crashpad::CrashReportDatabase* report_database); | 87 crashpad::CrashReportDatabase* report_database); |
| 98 | 88 |
| 99 // Virtual for unittesting. | 89 virtual CollectionStatus Collect(const base::FilePath& stability_file, |
| 100 // TODO(manzagop): move this for reuse in live scenario. | 90 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 | 91 |
| 107 virtual bool WriteReportToMinidump(StabilityReport* report, | 92 virtual bool WriteReportToMinidump(StabilityReport* report, |
| 108 const crashpad::UUID& client_id, | 93 const crashpad::UUID& client_id, |
| 109 const crashpad::UUID& report_id, | 94 const crashpad::UUID& report_id, |
| 110 base::PlatformFile minidump_file); | 95 base::PlatformFile minidump_file); |
| 111 | 96 |
| 112 std::string product_name_; | 97 std::string product_name_; |
| 113 std::string version_number_; | 98 std::string version_number_; |
| 114 std::string channel_name_; | 99 std::string channel_name_; |
| 115 | 100 |
| 116 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | 101 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); |
| 117 }; | 102 }; |
| 118 | 103 |
| 119 } // namespace browser_watcher | 104 } // namespace browser_watcher |
| 120 | 105 |
| 121 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 106 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| OLD | NEW |