Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/stability_report_user_stream_data_source.h" | 5 #include "components/browser_watcher/stability_report_user_stream_data_source.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/browser_watcher/minidump_user_streams.h" | 16 #include "components/browser_watcher/minidump_user_streams.h" |
| 17 #include "components/browser_watcher/stability_metrics.h" | |
| 17 #include "components/browser_watcher/stability_paths.h" | 18 #include "components/browser_watcher/stability_paths.h" |
| 18 #include "components/browser_watcher/stability_report_extractor.h" | 19 #include "components/browser_watcher/stability_report_extractor.h" |
| 19 #include "third_party/crashpad/crashpad/minidump/minidump_user_extension_stream_ data_source.h" | 20 #include "third_party/crashpad/crashpad/minidump/minidump_user_extension_stream_ data_source.h" |
| 20 #include "third_party/crashpad/crashpad/snapshot/process_snapshot.h" | 21 #include "third_party/crashpad/crashpad/snapshot/process_snapshot.h" |
| 21 | 22 |
| 22 namespace browser_watcher { | 23 namespace browser_watcher { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 base::FilePath GetStabilityFileName( | 27 base::FilePath GetStabilityFileName( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 DCHECK(!data_.empty()); | 67 DCHECK(!data_.empty()); |
| 67 return data_.size(); | 68 return data_.size(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) { | 71 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) { |
| 71 DCHECK(!data_.empty()); | 72 DCHECK(!data_.empty()); |
| 72 return delegate->ExtensionStreamDataSourceRead( | 73 return delegate->ExtensionStreamDataSourceRead( |
| 73 data_.size() ? data_.data() : nullptr, data_.size()); | 74 data_.size() ? data_.data() : nullptr, data_.size()); |
| 74 } | 75 } |
| 75 | 76 |
| 77 // TODO(manzagop): collection should factor in whether this is a true crash or | |
|
rkaplow
2017/06/01 14:53:48
very minor nit - Collection
manzagop (departed)
2017/06/01 14:58:27
Done.
| |
| 78 // dump without crashing. | |
| 76 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport( | 79 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport( |
| 77 const base::FilePath& path) { | 80 const base::FilePath& path) { |
| 78 StabilityReport report; | 81 StabilityReport report; |
| 79 CollectionStatus status = Extract(path, &report); | 82 CollectionStatus status = Extract(path, &report); |
| 80 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Status", status, | 83 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Status", status, |
| 81 COLLECTION_STATUS_MAX); | 84 COLLECTION_STATUS_MAX); |
| 82 if (status != SUCCESS) | 85 if (status != SUCCESS) |
| 83 return nullptr; | 86 return nullptr; |
| 87 LogCollectOnCrashEvent(CollectOnCrashEvent::kReportExtractionSuccess); | |
| 84 | 88 |
| 85 // Open (with delete) and then immediately close the file by going out of | 89 MarkStabilityFileDeletedOnCrash(path); |
| 86 // scope. This should cause the stability debugging file to be deleted prior | |
| 87 // to the next execution. | |
| 88 // TODO(manzagop): set the persistent allocator file's state to deleted in | |
| 89 // case the file can't be deleted. | |
| 90 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | |
| 91 base::File::FLAG_DELETE_ON_CLOSE); | |
| 92 UMA_HISTOGRAM_BOOLEAN("ActivityTracker.CollectCrash.OpenForDeleteSuccess", | |
| 93 file.IsValid()); | |
| 94 | 90 |
| 95 std::unique_ptr<BufferExtensionStreamDataSource> source( | 91 std::unique_ptr<BufferExtensionStreamDataSource> source( |
| 96 new BufferExtensionStreamDataSource(kStabilityReportStreamType)); | 92 new BufferExtensionStreamDataSource(kStabilityReportStreamType)); |
| 97 return source->Init(report) ? std::move(source) : nullptr; | 93 if (!source->Init(report)) |
| 94 return nullptr; | |
| 95 | |
| 96 LogCollectOnCrashEvent(CollectOnCrashEvent::kSuccess); | |
| 97 return source; | |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource( | 102 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource( |
| 103 const base::FilePath& user_data_dir) | 103 const base::FilePath& user_data_dir) |
| 104 : user_data_dir_(user_data_dir) {} | 104 : user_data_dir_(user_data_dir) {} |
| 105 | 105 |
| 106 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource> | 106 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource> |
| 107 StabilityReportUserStreamDataSource::ProduceStreamData( | 107 StabilityReportUserStreamDataSource::ProduceStreamData( |
| 108 crashpad::ProcessSnapshot* process_snapshot) { | 108 crashpad::ProcessSnapshot* process_snapshot) { |
| 109 DCHECK(process_snapshot); | 109 DCHECK(process_snapshot); |
| 110 LogCollectOnCrashEvent(CollectOnCrashEvent::kCollectAttempt); | |
| 110 | 111 |
| 111 if (user_data_dir_.empty()) | 112 if (user_data_dir_.empty()) |
| 112 return nullptr; | 113 return nullptr; |
| 114 LogCollectOnCrashEvent(CollectOnCrashEvent::kUserDataDirNotEmpty); | |
| 113 | 115 |
| 114 base::FilePath stability_file = | 116 base::FilePath stability_file = |
| 115 GetStabilityFileName(user_data_dir_, process_snapshot); | 117 GetStabilityFileName(user_data_dir_, process_snapshot); |
| 116 if (!PathExists(stability_file)) { | 118 if (!PathExists(stability_file)) { |
| 117 // Either this is not an instrumented process (currently only browser | 119 // Either this is not an instrumented process (currently only browser |
| 118 // processes can be instrumented), or the stability file cannot be found. | 120 // processes can be instrumented), or the stability file cannot be found. |
| 119 return nullptr; | 121 return nullptr; |
| 120 } | 122 } |
| 123 LogCollectOnCrashEvent(CollectOnCrashEvent::kPathExists); | |
| 121 | 124 |
| 122 return CollectReport(stability_file); | 125 return CollectReport(stability_file); |
| 123 } | 126 } |
| 124 | 127 |
| 125 } // namespace browser_watcher | 128 } // namespace browser_watcher |
| OLD | NEW |