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_collector_impl.h" | |
|
Sigurður Ásgeirsson
2017/03/01 20:50:30
like we discussed, the thing you're extracting her
manzagop (departed)
2017/03/01 21:49:53
Done.
| |
| 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 // Collects unclean shutdown information and creates Crashpad minidumps. |
| 30 // TODO(manzagop): throttling, graceful handling of accumulating data. | 31 // TODO(manzagop): throttling, graceful handling of accumulating data. |
| 31 // TODO(manzagop): UMA metrics and some error logging. | 32 // TODO(manzagop): UMA metrics and some error logging. |
| 32 class PostmortemReportCollector { | 33 class PostmortemReportCollector { |
| 33 public: | 34 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, | 35 PostmortemReportCollector(const std::string& product_name, |
| 48 const std::string& version_number, | 36 const std::string& version_number, |
| 49 const std::string& channel_name); | 37 const std::string& channel_name); |
| 50 virtual ~PostmortemReportCollector() = default; | 38 virtual ~PostmortemReportCollector(); |
| 51 | 39 |
| 52 // Collects postmortem stability reports from files found in |debug_info_dir|, | 40 // Collects postmortem stability reports from files found in |debug_info_dir|, |
| 53 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are | 41 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are |
| 54 // then wrapped in Crashpad reports, manufactured via |report_database|. | 42 // then wrapped in Crashpad reports, manufactured via |report_database|. |
| 55 // Returns the number crash reports successfully registered with the reporter. | 43 // Returns the number crash reports successfully registered with the reporter. |
| 56 // TODO(manzagop): consider mechanisms for partial collection if this is to be | 44 // TODO(manzagop): consider mechanisms for partial collection if this is to be |
| 57 // used on a critical path. | 45 // used on a critical path. |
| 58 int CollectAndSubmitForUpload( | 46 int CollectAndSubmitForUpload( |
| 59 const base::FilePath& debug_info_dir, | 47 const base::FilePath& debug_info_dir, |
| 60 const base::FilePath::StringType& debug_file_pattern, | 48 const base::FilePath::StringType& debug_file_pattern, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 84 FRIEND_TEST_ALL_PREFIXES( | 72 FRIEND_TEST_ALL_PREFIXES( |
| 85 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 73 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 86 ModuleCollection); | 74 ModuleCollection); |
| 87 | 75 |
| 88 // Virtual for unittesting. | 76 // Virtual for unittesting. |
| 89 virtual std::vector<base::FilePath> GetDebugStateFilePaths( | 77 virtual std::vector<base::FilePath> GetDebugStateFilePaths( |
| 90 const base::FilePath& debug_info_dir, | 78 const base::FilePath& debug_info_dir, |
| 91 const base::FilePath::StringType& debug_file_pattern, | 79 const base::FilePath::StringType& debug_file_pattern, |
| 92 const std::set<base::FilePath>& excluded_debug_files); | 80 const std::set<base::FilePath>& excluded_debug_files); |
| 93 | 81 |
| 94 CollectionStatus CollectAndSubmit( | 82 impl::CollectionStatus CollectAndSubmit( |
| 95 const crashpad::UUID& client_id, | 83 const crashpad::UUID& client_id, |
| 96 const base::FilePath& file, | 84 const base::FilePath& file, |
| 97 crashpad::CrashReportDatabase* report_database); | 85 crashpad::CrashReportDatabase* report_database); |
| 98 | 86 |
| 99 // Virtual for unittesting. | 87 virtual impl::CollectionStatus Collect(const base::FilePath& stability_file, |
| 100 // TODO(manzagop): move this for reuse in live scenario. | 88 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 | 89 |
| 107 virtual bool WriteReportToMinidump(StabilityReport* report, | 90 virtual bool WriteReportToMinidump(StabilityReport* report, |
| 108 const crashpad::UUID& client_id, | 91 const crashpad::UUID& client_id, |
| 109 const crashpad::UUID& report_id, | 92 const crashpad::UUID& report_id, |
| 110 base::PlatformFile minidump_file); | 93 base::PlatformFile minidump_file); |
| 111 | 94 |
| 112 std::string product_name_; | 95 std::string product_name_; |
| 113 std::string version_number_; | 96 std::string version_number_; |
| 114 std::string channel_name_; | 97 std::string channel_name_; |
| 115 | 98 |
| 116 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | 99 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); |
| 117 }; | 100 }; |
| 118 | 101 |
| 119 } // namespace browser_watcher | 102 } // namespace browser_watcher |
| 120 | 103 |
| 121 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 104 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| OLD | NEW |