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

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

Issue 2867063002: Stability instrumentation Crashpad integration (Closed)
Patch Set: Address Siggi's first round 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/strings/string16.h"
14 #include "base/time/time.h"
15 #include "components/browser_watcher/minidump_user_streams.h"
16 #include "components/browser_watcher/stability_paths.h"
17 #include "components/browser_watcher/stability_report_extractor.h"
18 #include "third_party/crashpad/crashpad/minidump/minidump_user_extension_stream_ data_source.h"
19 #include "third_party/crashpad/crashpad/snapshot/process_snapshot.h"
20
21 namespace browser_watcher {
22
23 namespace {
24
25 bool GetStabilityFileName(const base::string16& user_data_dir,
26 crashpad::ProcessSnapshot* process_snapshot,
27 base::FilePath* stability_file) {
28 DCHECK(process_snapshot);
29 DCHECK(stability_file);
30
31 timeval creation_time{};
32 process_snapshot->ProcessStartTime(&creation_time);
33
34 *stability_file =
35 GetStabilityFileForProcess(process_snapshot->ProcessID(), creation_time,
36 base::FilePath(user_data_dir));
37 return true;
38 }
39
40 std::unique_ptr<std::string> CollectReport(const base::FilePath& path) {
41 StabilityReport report;
42 CollectionStatus status = Extract(path, &report);
43 if (status != SUCCESS)
44 return nullptr;
45
46 std::unique_ptr<std::string> serialized_report(new std::string());
47 if (!report.SerializeToString(serialized_report.get()))
48 return nullptr;
49
50 // Open (with delete) and then immediately close the file by going out of
51 // scope. This should cause the stability debugging file to be deleted prior
52 // to the next execution.
53 // TODO(manzagop): set the persistent allocator file's state to deleted in
54 // case the file can't be deleted.
55 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
56 base::File::FLAG_DELETE_ON_CLOSE);
57
58 return serialized_report;
59 }
60
61 class BufferExtensionStreamDataSource final
62 : public crashpad::MinidumpUserExtensionStreamDataSource {
63 public:
64 BufferExtensionStreamDataSource(uint32_t stream_type,
65 std::unique_ptr<std::string> data);
Sigurður Ásgeirsson 2017/05/11 13:48:32 why not construct this with the StabilityReport pr
manzagop (departed) 2017/05/11 14:54:45 Done. Note the string might be empty if the serial
Sigurður Ásgeirsson 2017/05/11 15:33:40 Interesting distinction, is this helpful or harmfu
manzagop (departed) 2017/05/11 19:14:53 Went with early pruning. Done.
66
67 size_t StreamDataSize() override;
68 bool ReadStreamData(Delegate* delegate) override;
69
70 private:
71 std::unique_ptr<std::string> data_;
72
73 DISALLOW_COPY_AND_ASSIGN(BufferExtensionStreamDataSource);
74 };
75
76 BufferExtensionStreamDataSource::BufferExtensionStreamDataSource(
77 uint32_t stream_type,
78 std::unique_ptr<std::string> data)
79 : crashpad::MinidumpUserExtensionStreamDataSource(stream_type),
80 data_(std::move(data)) {
81 DCHECK(data_);
82 }
83
84 size_t BufferExtensionStreamDataSource::StreamDataSize() {
85 return data_->size();
86 }
87
88 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) {
89 return delegate->ExtensionStreamDataSourceRead(
90 data_->size() ? data_->data() : nullptr, data_->size());
91 }
92
93 } // namespace
94
95 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource(
96 const base::string16& user_data_dir)
97 : user_data_dir_(user_data_dir) {}
98
99 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource>
100 StabilityReportUserStreamDataSource::ProduceStreamData(
101 crashpad::ProcessSnapshot* process_snapshot) {
102 DCHECK(process_snapshot);
103
104 if (user_data_dir_.empty())
105 return nullptr;
106
107 base::FilePath stability_file;
108 GetStabilityFileName(user_data_dir_, process_snapshot, &stability_file);
109 if (!PathExists(stability_file)) {
110 // Either this is not an instrumented process, or the stability file cannot
111 // be found.
112 return nullptr;
113 }
114
115 std::unique_ptr<std::string> report = CollectReport(stability_file);
Sigurður Ásgeirsson 2017/05/11 13:48:32 yups, just return the extension stream thingy from
manzagop (departed) 2017/05/11 14:54:45 Done.
116 if (!report)
117 return nullptr;
118
119 return base::WrapUnique(new BufferExtensionStreamDataSource(
120 kStabilityReportStreamType, std::move(report)));
121 }
122
123 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/stability_report_user_stream_data_source.h ('k') | components/crash/content/app/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698