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

Unified Diff: components/browser_watcher/stability_paths.cc

Issue 2910003002: Stability instrumentation: metrics for collection on crash (Closed)
Patch Set: address rkaplow comments 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 side-by-side diff with in-line comments
Download patch
Index: components/browser_watcher/stability_paths.cc
diff --git a/components/browser_watcher/stability_paths.cc b/components/browser_watcher/stability_paths.cc
index 66805fa67d12381e81386de3e803adc59aa35f28..329d89c36a2d854daf466cd868658525a0e0cb2b 100644
--- a/components/browser_watcher/stability_paths.cc
+++ b/components/browser_watcher/stability_paths.cc
@@ -8,20 +8,30 @@
#include <windows.h>
#endif // defined(OS_WIN)
+#include <memory>
#include <string>
+#include <utility>
+#include "base/debug/activity_tracker.h"
#include "base/feature_list.h"
#include "base/files/file.h"
+#include "base/files/memory_mapped_file.h"
#include "base/metrics/persistent_memory_allocator.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "components/browser_watcher/features.h"
+#include "components/browser_watcher/stability_metrics.h"
#if defined(OS_WIN)
#include "third_party/crashpad/crashpad/util/win/time.h"
namespace browser_watcher {
+
+using base::FilePersistentMemoryAllocator;
+using base::MemoryMappedFile;
+using base::PersistentMemoryAllocator;
+
namespace {
bool GetCreationTime(const base::Process& process, FILETIME* creation_time) {
@@ -30,6 +40,21 @@ bool GetCreationTime(const base::Process& process, FILETIME* creation_time) {
&ignore) != 0;
}
+bool SetPmaFileDeleted(const base::FilePath& file_path) {
+ // Map the file read-write so it can guarantee consistency between
+ // the analyzer and any trackers that may still be active.
+ std::unique_ptr<MemoryMappedFile> mmfile(new MemoryMappedFile());
+ mmfile->Initialize(file_path, MemoryMappedFile::READ_WRITE);
+ if (!mmfile->IsValid())
+ return false;
+ if (!FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile, true))
+ return false;
+ FilePersistentMemoryAllocator allocator(std::move(mmfile), 0, 0,
+ base::StringPiece(), true);
+ allocator.SetMemoryState(PersistentMemoryAllocator::MEMORY_DELETED);
+ return true;
+}
+
} // namespace
base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) {
@@ -72,25 +97,40 @@ base::FilePath::StringType GetStabilityFilePattern() {
base::PersistentMemoryAllocator::kFileExtension;
}
-void MarkStabilityFileForDeletion(const base::FilePath& user_data_dir) {
- if (!base::FeatureList::IsEnabled(
- browser_watcher::kStabilityDebuggingFeature)) {
- return;
- }
+void MarkOwnStabilityFileDeleted(const base::FilePath& user_data_dir) {
+ base::debug::GlobalActivityTracker* global_tracker =
+ base::debug::GlobalActivityTracker::Get();
+ if (!global_tracker)
+ return; // No stability instrumentation.
+
+ global_tracker->MarkDeleted();
+ LogStabilityRecordEvent(StabilityRecordEvent::kMarkDeleted);
+ // Open (with delete) and then immediately close the file by going out of
+ // scope. This should cause the stability debugging file to be deleted prior
+ // to the next execution.
base::FilePath stability_file;
if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir,
&stability_file)) {
- // TODO(manzagop): add a metric for this.
return;
}
+ LogStabilityRecordEvent(StabilityRecordEvent::kMarkDeletedGotFile);
- // Open (with delete) and then immediately close the file by going out of
- // scope. This should cause the stability debugging file to be deleted prior
- // to the next execution.
- base::File file(stability_file, base::File::FLAG_OPEN |
- base::File::FLAG_READ |
- base::File::FLAG_DELETE_ON_CLOSE);
+ base::File deleter(stability_file, base::File::FLAG_OPEN |
+ base::File::FLAG_READ |
+ base::File::FLAG_DELETE_ON_CLOSE);
+ if (!deleter.IsValid())
+ LogStabilityRecordEvent(StabilityRecordEvent::kOpenForDeleteFailed);
+}
+
+void MarkStabilityFileDeletedOnCrash(const base::FilePath& file_path) {
+ if (!SetPmaFileDeleted(file_path))
+ LogCollectOnCrashEvent(CollectOnCrashEvent::kPmaSetDeletedFailed);
+
+ base::File deleter(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_DELETE_ON_CLOSE);
+ if (!deleter.IsValid())
+ LogCollectOnCrashEvent(CollectOnCrashEvent::kOpenForDeleteFailed);
}
} // namespace browser_watcher
« 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