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

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

Issue 2867063002: Stability instrumentation Crashpad integration (Closed)
Patch Set: Merge / Siggi second 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;
Sigurður Ásgeirsson 2017/05/11 15:33:40 return void as this can't fail (at present).
manzagop (departed) 2017/05/11 19:14:53 Done.
38 }
39
40 class BufferExtensionStreamDataSource final
41 : public crashpad::MinidumpUserExtensionStreamDataSource {
42 public:
43 BufferExtensionStreamDataSource(uint32_t stream_type,
44 const StabilityReport& report);
Sigurður Ásgeirsson 2017/05/11 15:33:40 you could also use a "bool Init()" method to initi
manzagop (departed) 2017/05/11 19:14:53 Done.
45
46 size_t StreamDataSize() override;
47 bool ReadStreamData(Delegate* delegate) override;
48
49 private:
50 std::string data_;
51
52 DISALLOW_COPY_AND_ASSIGN(BufferExtensionStreamDataSource);
53 };
54
55 BufferExtensionStreamDataSource::BufferExtensionStreamDataSource(
56 uint32_t stream_type,
57 const StabilityReport& report)
58 : crashpad::MinidumpUserExtensionStreamDataSource(stream_type) {
59 if (!report.SerializeToString(&data_))
60 data_.clear();
61 }
62
63 size_t BufferExtensionStreamDataSource::StreamDataSize() {
64 return data_.size();
65 }
66
67 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) {
68 return delegate->ExtensionStreamDataSourceRead(
69 data_.size() ? data_.data() : nullptr, data_.size());
70 }
71
72 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport(
73 const base::FilePath& path) {
74 StabilityReport report;
75 CollectionStatus status = Extract(path, &report);
Sigurður Ásgeirsson 2017/05/11 15:33:40 You can use histograms here to make sure there's a
manzagop (departed) 2017/05/11 19:14:53 Done.
76 if (status != SUCCESS)
77 return nullptr;
78
79 // Open (with delete) and then immediately close the file by going out of
80 // scope. This should cause the stability debugging file to be deleted prior
81 // to the next execution.
82 // TODO(manzagop): set the persistent allocator file's state to deleted in
83 // case the file can't be deleted.
84 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
Sigurður Ásgeirsson 2017/05/11 15:33:40 also leave a trace of failure here?
manzagop (departed) 2017/05/11 19:14:53 Done.
85 base::File::FLAG_DELETE_ON_CLOSE);
86
87 return base::WrapUnique(
88 new BufferExtensionStreamDataSource(kStabilityReportStreamType, report));
89 }
90
91 } // namespace
92
93 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource(
94 const base::string16& user_data_dir)
95 : user_data_dir_(user_data_dir) {}
96
97 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource>
98 StabilityReportUserStreamDataSource::ProduceStreamData(
99 crashpad::ProcessSnapshot* process_snapshot) {
100 DCHECK(process_snapshot);
101
102 if (user_data_dir_.empty())
103 return nullptr;
104
105 base::FilePath stability_file;
106 GetStabilityFileName(user_data_dir_, process_snapshot, &stability_file);
107 if (!PathExists(stability_file)) {
108 // Either this is not an instrumented process, or the stability file cannot
Sigurður Ásgeirsson 2017/05/11 15:33:40 is this going to be true for e.g. renderers and !b
manzagop (departed) 2017/05/11 19:14:53 Done.
109 // be found.
110 return nullptr;
111 }
112
113 return CollectReport(stability_file);
114 }
115
116 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698