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

Side by Side Diff: components/browser_watcher/stability_report_user_stream_data_source.cc

Issue 2867063002: Stability instrumentation Crashpad integration (Closed)
Patch Set: clang compile Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/browser_watcher/stability_report_user_stream_data_source.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/files/file.h"
11 #include "base/files/file_util.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/string16.h"
15 #include "base/time/time.h"
16 #include "components/browser_watcher/minidump_user_streams.h"
17 #include "components/browser_watcher/stability_paths.h"
18 #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/snapshot/process_snapshot.h"
21
22 namespace browser_watcher {
23
24 namespace {
25
26 base::FilePath GetStabilityFileName(
27 const base::FilePath& user_data_dir,
28 crashpad::ProcessSnapshot* process_snapshot) {
29 DCHECK(process_snapshot);
30
31 timeval creation_time = {};
32 process_snapshot->ProcessStartTime(&creation_time);
33
34 return GetStabilityFileForProcess(process_snapshot->ProcessID(),
35 creation_time, user_data_dir);
36 }
37
38 class BufferExtensionStreamDataSource final
39 : public crashpad::MinidumpUserExtensionStreamDataSource {
40 public:
41 explicit BufferExtensionStreamDataSource(uint32_t stream_type);
42
43 bool Init(const StabilityReport& report);
44
45 size_t StreamDataSize() override;
46 bool ReadStreamData(Delegate* delegate) override;
47
48 private:
49 std::string data_;
50
51 DISALLOW_COPY_AND_ASSIGN(BufferExtensionStreamDataSource);
52 };
53
54 BufferExtensionStreamDataSource::BufferExtensionStreamDataSource(
55 uint32_t stream_type)
56 : crashpad::MinidumpUserExtensionStreamDataSource(stream_type) {}
57
58 bool BufferExtensionStreamDataSource::Init(const StabilityReport& report) {
59 if (report.SerializeToString(&data_))
60 return true;
61 data_.clear();
62 return false;
63 }
64
65 size_t BufferExtensionStreamDataSource::StreamDataSize() {
66 DCHECK(!data_.empty());
67 return data_.size();
68 }
69
70 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) {
71 DCHECK(!data_.empty());
72 return delegate->ExtensionStreamDataSourceRead(
73 data_.size() ? data_.data() : nullptr, data_.size());
74 }
75
76 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport(
77 const base::FilePath& path) {
78 StabilityReport report;
79 CollectionStatus status = Extract(path, &report);
80 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Status", status,
81 COLLECTION_STATUS_MAX);
82 if (status != SUCCESS)
83 return nullptr;
84
85 // Open (with delete) and then immediately close the file by going out of
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
95 std::unique_ptr<BufferExtensionStreamDataSource> source(
96 new BufferExtensionStreamDataSource(kStabilityReportStreamType));
97 return source->Init(report) ? std::move(source) : nullptr;
98 }
99
100 } // namespace
101
102 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource(
103 const base::FilePath& user_data_dir)
104 : user_data_dir_(user_data_dir) {}
105
106 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource>
107 StabilityReportUserStreamDataSource::ProduceStreamData(
108 crashpad::ProcessSnapshot* process_snapshot) {
109 DCHECK(process_snapshot);
110
111 if (user_data_dir_.empty())
112 return nullptr;
113
114 base::FilePath stability_file =
115 GetStabilityFileName(user_data_dir_, process_snapshot);
116 if (!PathExists(stability_file)) {
117 // Either this is not an instrumented process (currently only browser
118 // processes can be instrumented), or the stability file cannot be found.
119 return nullptr;
120 }
121
122 return CollectReport(stability_file);
123 }
124
125 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698