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

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

Issue 2910003002: Stability instrumentation: metrics for collection on crash (Closed)
Patch Set: Set pma state to deleted Created 3 years, 6 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
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_paths.h" 5 #include "components/browser_watcher/stability_paths.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif // defined(OS_WIN) 9 #endif // defined(OS_WIN)
10 10
11 #include <memory>
11 #include <string> 12 #include <string>
13 #include <utility>
12 14
15 #include "base/debug/activity_tracker.h"
13 #include "base/feature_list.h" 16 #include "base/feature_list.h"
14 #include "base/files/file.h" 17 #include "base/files/file.h"
18 #include "base/files/memory_mapped_file.h"
19 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/persistent_memory_allocator.h" 20 #include "base/metrics/persistent_memory_allocator.h"
16 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
17 #include "base/time/time.h" 22 #include "base/time/time.h"
18 #include "components/browser_watcher/features.h" 23 #include "components/browser_watcher/features.h"
19 24
20 #if defined(OS_WIN) 25 #if defined(OS_WIN)
21 26
22 #include "third_party/crashpad/crashpad/util/win/time.h" 27 #include "third_party/crashpad/crashpad/util/win/time.h"
23 28
24 namespace browser_watcher { 29 namespace browser_watcher {
30
31 using base::FilePersistentMemoryAllocator;
32 using base::MemoryMappedFile;
33 using base::PersistentMemoryAllocator;
34
25 namespace { 35 namespace {
26 36
27 bool GetCreationTime(const base::Process& process, FILETIME* creation_time) { 37 bool GetCreationTime(const base::Process& process, FILETIME* creation_time) {
28 FILETIME ignore; 38 FILETIME ignore;
29 return ::GetProcessTimes(process.Handle(), creation_time, &ignore, &ignore, 39 return ::GetProcessTimes(process.Handle(), creation_time, &ignore, &ignore,
30 &ignore) != 0; 40 &ignore) != 0;
31 } 41 }
32 42
43 bool SetPmaFileDeleted(const base::FilePath& file_path) {
44 // Map the file read-write so it can guarantee consistency between
45 // the analyzer and any trackers that may still be active.
46 std::unique_ptr<MemoryMappedFile> mmfile(new MemoryMappedFile());
47 mmfile->Initialize(file_path, MemoryMappedFile::READ_WRITE);
48 if (!mmfile->IsValid())
49 return false;
50 if (!FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile, true))
51 return false;
52 std::unique_ptr<FilePersistentMemoryAllocator> allocator(
53 new FilePersistentMemoryAllocator(std::move(mmfile), 0, 0,
54 base::StringPiece(), true));
55 allocator->SetMemoryState(PersistentMemoryAllocator::MEMORY_DELETED);
56 return true;
57 }
58
33 } // namespace 59 } // namespace
34 60
35 base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) { 61 base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) {
36 return user_data_dir.AppendASCII("Stability"); 62 return user_data_dir.AppendASCII("Stability");
37 } 63 }
38 64
39 base::FilePath GetStabilityFileForProcess(base::ProcessId pid, 65 base::FilePath GetStabilityFileForProcess(base::ProcessId pid,
40 timeval creation_time, 66 timeval creation_time,
41 const base::FilePath& user_data_dir) { 67 const base::FilePath& user_data_dir) {
42 base::FilePath stability_dir = GetStabilityDir(user_data_dir); 68 base::FilePath stability_dir = GetStabilityDir(user_data_dir);
(...skipping 22 matching lines...) Expand all
65 process.Pid(), crashpad::FiletimeToTimevalEpoch(creation_time), 91 process.Pid(), crashpad::FiletimeToTimevalEpoch(creation_time),
66 user_data_dir); 92 user_data_dir);
67 return true; 93 return true;
68 } 94 }
69 95
70 base::FilePath::StringType GetStabilityFilePattern() { 96 base::FilePath::StringType GetStabilityFilePattern() {
71 return base::FilePath::StringType(FILE_PATH_LITERAL("*-*")) + 97 return base::FilePath::StringType(FILE_PATH_LITERAL("*-*")) +
72 base::PersistentMemoryAllocator::kFileExtension; 98 base::PersistentMemoryAllocator::kFileExtension;
73 } 99 }
74 100
75 void MarkStabilityFileForDeletion(const base::FilePath& user_data_dir) { 101 void MarkOwnStabilityFileDeleted(const base::FilePath& user_data_dir) {
76 if (!base::FeatureList::IsEnabled( 102 base::debug::GlobalActivityTracker* global_tracker =
77 browser_watcher::kStabilityDebuggingFeature)) { 103 base::debug::GlobalActivityTracker::Get();
78 return; 104 if (!global_tracker)
79 } 105 return; // No stability instrumentation.
80 106
81 base::FilePath stability_file; 107 global_tracker->MarkDeleted();
82 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir,
83 &stability_file)) {
84 // TODO(manzagop): add a metric for this.
85 return;
86 }
87 108
88 // Open (with delete) and then immediately close the file by going out of 109 // Open (with delete) and then immediately close the file by going out of
89 // scope. This should cause the stability debugging file to be deleted prior 110 // scope. This should cause the stability debugging file to be deleted prior
90 // to the next execution. 111 // to the next execution.
91 base::File file(stability_file, base::File::FLAG_OPEN | 112 base::FilePath stability_file;
92 base::File::FLAG_READ | 113 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir,
93 base::File::FLAG_DELETE_ON_CLOSE); 114 &stability_file)) {
115 return; // TODO(manzagop): add a metric for this.
116 }
117 base::File deleter(stability_file, base::File::FLAG_OPEN |
118 base::File::FLAG_READ |
119 base::File::FLAG_DELETE_ON_CLOSE);
120 }
121
122 void MarkStabilityFileDeleted(const base::FilePath& file_path) {
123 bool success = SetPmaFileDeleted(file_path);
124 UMA_HISTOGRAM_BOOLEAN("ActivityTracker.Record.SetPmaDeletedSuccess", success);
Sigurður Ásgeirsson 2017/05/30 16:51:18 Yeah, this looks like another event count - I thin
125
126 base::File deleter(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ |
127 base::File::FLAG_DELETE_ON_CLOSE);
94 } 128 }
95 129
96 } // namespace browser_watcher 130 } // namespace browser_watcher
97 131
98 #endif // defined(OS_WIN) 132 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « components/browser_watcher/stability_paths.h ('k') | components/browser_watcher/stability_report_user_stream_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698