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

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

Issue 2867063002: Stability instrumentation Crashpad integration (Closed)
Patch Set: Moar comments and fixups 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
9 #include "base/files/file.h"
10 #include "base/files/file_util.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string16.h"
13 #include "base/time/time.h"
14 // DO NOT SUBMIT: is this ok?
15 #include "chrome/install_static/user_data_dir.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 // DO NOT SUBMIT: move out of test folder.
21 #include "third_party/crashpad/crashpad/minidump/test/minidump_user_extension_st ream_util.h"
22 #include "third_party/crashpad/crashpad/snapshot/process_snapshot.h"
23
24 namespace browser_watcher {
25
26 namespace {
27
28 bool GetStabilityFileName(crashpad::ProcessSnapshot* process_snapshot,
Sigurður Ásgeirsson 2017/05/10 17:46:23 I'd suggest you grab the user data dir from the us
manzagop (departed) 2017/05/10 23:06:11 Done.
29 base::FilePath* stability_file) {
30 DCHECK(process_snapshot);
31 DCHECK(stability_file);
32
33 base::string16 user_data_dir;
34 if (!install_static::GetUserDataDirectory(&user_data_dir, nullptr))
35 return false;
36
37 timeval creation_time{};
38 process_snapshot->ProcessStartTime(&creation_time);
39
40 *stability_file =
41 GetStabilityFileForProcess(process_snapshot->ProcessID(), creation_time,
42 base::FilePath(user_data_dir));
43 return true;
44 }
45
46 } // namespace
47
48 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource>
49 StabilityReportUserStreamDataSource::ProduceStreamData(
50 crashpad::ProcessSnapshot* process_snapshot) {
51 DCHECK(process_snapshot);
52
53 base::FilePath stability_file;
54 GetStabilityFileName(process_snapshot, &stability_file);
55 if (!PathExists(stability_file)) {
56 // Either this is not an instrumented process, or the stability file cannot
57 // be found.
58 return nullptr;
59 }
60
61 StabilityReport report;
Sigurður Ásgeirsson 2017/05/10 17:46:23 make sure this report is deallocated as soon as yo
manzagop (departed) 2017/05/10 23:06:11 Done.
62 CollectionStatus status = Extract(stability_file, &report);
63 if (status != SUCCESS)
64 return nullptr;
65 std::string serialized_report;
66 if (!report.SerializeToString(&serialized_report))
67 return nullptr;
68
69 // Open (with delete) and then immediately close the file by going out of
70 // scope. This should cause the stability debugging file to be deleted prior
71 // to the next execution.
72 // TODO(manzagop): set the persistent allocator file's state to deleted in
73 // case the file can't be deleted.
74 base::File file(stability_file, base::File::FLAG_OPEN |
Sigurður Ásgeirsson 2017/05/10 17:46:23 You probably want to capture a metric for how ofte
manzagop (departed) 2017/05/10 23:06:11 My initial thought was we can't do metrics, but I
75 base::File::FLAG_READ |
76 base::File::FLAG_DELETE_ON_CLOSE);
77
78 return base::WrapUnique(new crashpad::test::BufferExtensionStreamDataSource(
Sigurður Ásgeirsson 2017/05/10 17:46:23 just re-implement the damn thing, and make sure yo
manzagop (departed) 2017/05/10 23:06:11 Done.
79 kStabilityReportStreamType, serialized_report.data(),
80 serialized_report.size()));
81 }
82
83 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698