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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 DCHECK(!data_.empty()); | 66 DCHECK(!data_.empty()); |
67 return data_.size(); | 67 return data_.size(); |
68 } | 68 } |
69 | 69 |
70 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) { | 70 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) { |
71 DCHECK(!data_.empty()); | 71 DCHECK(!data_.empty()); |
72 return delegate->ExtensionStreamDataSourceRead( | 72 return delegate->ExtensionStreamDataSourceRead( |
73 data_.size() ? data_.data() : nullptr, data_.size()); | 73 data_.size() ? data_.data() : nullptr, data_.size()); |
74 } | 74 } |
75 | 75 |
76 // DO NOT CHANGE VALUES. This is logged persistently in a histogram. | |
77 enum class CollectionEvent { | |
bcwhite
2017/05/31 15:41:19
Do you track failures? You could have a kAttempts
manzagop (departed)
2017/05/31 19:57:23
I've added a bunch of states. Done.
| |
78 kSuccess = 0, | |
bcwhite
2017/05/31 15:41:19
Omit the numbers and just say "do not insert or re
manzagop (departed)
2017/05/31 19:57:23
Done.
| |
79 kPmaSetDeletedFailed = 1, | |
80 kCollectionEventMax = 2 | |
81 }; | |
82 | |
83 void LogCollectionEvent(CollectionEvent event) { | |
84 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Event", event, | |
85 CollectionEvent::kCollectionEventMax); | |
86 } | |
87 | |
88 // TODO(manzagop): collection should factor in whether this is a true crash or | |
89 // dump without crashing. | |
76 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport( | 90 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport( |
77 const base::FilePath& path) { | 91 const base::FilePath& path) { |
78 StabilityReport report; | 92 StabilityReport report; |
79 CollectionStatus status = Extract(path, &report); | 93 CollectionStatus status = Extract(path, &report); |
80 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Status", status, | 94 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Status", status, |
81 COLLECTION_STATUS_MAX); | 95 COLLECTION_STATUS_MAX); |
82 if (status != SUCCESS) | 96 if (status != SUCCESS) |
83 return nullptr; | 97 return nullptr; |
84 | 98 |
85 // Open (with delete) and then immediately close the file by going out of | 99 if (!MarkStabilityFileDeleted(path)) |
86 // scope. This should cause the stability debugging file to be deleted prior | 100 LogCollectionEvent(CollectionEvent::kPmaSetDeletedFailed); |
87 // to the next execution. | 101 LogCollectionEvent(CollectionEvent::kSuccess); |
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 | 102 |
95 std::unique_ptr<BufferExtensionStreamDataSource> source( | 103 std::unique_ptr<BufferExtensionStreamDataSource> source( |
96 new BufferExtensionStreamDataSource(kStabilityReportStreamType)); | 104 new BufferExtensionStreamDataSource(kStabilityReportStreamType)); |
97 return source->Init(report) ? std::move(source) : nullptr; | 105 return source->Init(report) ? std::move(source) : nullptr; |
98 } | 106 } |
99 | 107 |
100 } // namespace | 108 } // namespace |
101 | 109 |
102 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource( | 110 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource( |
103 const base::FilePath& user_data_dir) | 111 const base::FilePath& user_data_dir) |
(...skipping 12 matching lines...) Expand all Loading... | |
116 if (!PathExists(stability_file)) { | 124 if (!PathExists(stability_file)) { |
117 // Either this is not an instrumented process (currently only browser | 125 // Either this is not an instrumented process (currently only browser |
118 // processes can be instrumented), or the stability file cannot be found. | 126 // processes can be instrumented), or the stability file cannot be found. |
119 return nullptr; | 127 return nullptr; |
120 } | 128 } |
121 | 129 |
122 return CollectReport(stability_file); | 130 return CollectReport(stability_file); |
123 } | 131 } |
124 | 132 |
125 } // namespace browser_watcher | 133 } // namespace browser_watcher |
OLD | NEW |