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

Unified Diff: third_party/crashpad/crashpad/handler/handler_main.cc

Issue 2308763002: Integrate Crashpad UMA (Closed)
Patch Set: . Created 4 years, 3 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: third_party/crashpad/crashpad/handler/handler_main.cc
diff --git a/third_party/crashpad/crashpad/handler/handler_main.cc b/third_party/crashpad/crashpad/handler/handler_main.cc
index 3240cd38b37d79d6c915560aa41f325702cf00cd..ccade4b6b56336c8403020bfcb0cd2f29c862092 100644
--- a/third_party/crashpad/crashpad/handler/handler_main.cc
+++ b/third_party/crashpad/crashpad/handler/handler_main.cc
@@ -25,8 +25,10 @@
#include "base/auto_reset.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
+#include "base/metrics/persistent_histogram_allocator.h"
#include "base/scoped_generic.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@@ -118,6 +120,47 @@ void HandleSIGTERM(int sig, siginfo_t* siginfo, void* context) {
#endif // OS_MACOSX
+// This is used as both the file name and the "allocator" name, which is an
+// internal histograms concept.
+const char kMetricsName[] = "CrashpadMetrics";
+const base::FilePath::CharType kMetricsFileExtension[] =
+ FILE_PATH_LITERAL(".pma");
+
+void InitializePersistentMetricsStorage(const char* database_dir) {
+ const base::FilePath dir(
+ ToolSupport::CommandLineArgumentToFilePathStringType(database_dir));
+
+ // Metrics maps one file that we're going to use during this run (the
+ // "-active" one), and provides the previous one to the metrics system for for
+ // association with the previous run. On startup, we move the current -active
+ // to the base name, and then start this session on the -active one. Normally,
+ // when the browser starts it will read and delete the base name one, but in
+ // the case that something goes wrong, we will overwrite/delete any old one.
+ base::FilePath metrics_file =
+ dir.AppendASCII(kMetricsName).AddExtension(kMetricsFileExtension);
+ base::FilePath active_file =
+ dir.AppendASCII(kMetricsName + std::string("-active"))
+ .AddExtension(kMetricsFileExtension);
+
+ if (!base::ReplaceFile(active_file, metrics_file, nullptr))
+ base::DeleteFile(metrics_file, /*recursive=*/false);
+
+ const size_t kSize = 1 << 20;
+ base::GlobalHistogramAllocator::CreateWithFile(
bcwhite 2016/09/13 14:27:48 This file needs to be deleted when the browser exi
scottmg 2016/09/13 19:15:32 Ah, I didn't understand the reporting model. So on
bcwhite 2016/09/13 19:38:24 The model you've selected is that "CrashpadMetrics
+ active_file, kSize, 0, kMetricsName);
+
+ // Get the allocator that was just created and report result. Exit if the
+ // allocator could not be created.
+ base::GlobalHistogramAllocator* allocator =
+ base::GlobalHistogramAllocator::Get();
+ if (!allocator)
+ return;
+
+ // Create tracking histograms for the allocator and record storage file.
+ allocator->CreateTrackingHistograms(kMetricsName);
+ allocator->SetPersistentLocation(active_file);
+}
+
} // namespace
int HandlerMain(int argc, char* argv[]) {
@@ -313,6 +356,15 @@ int HandlerMain(int argc, char* argv[]) {
return EXIT_FAILURE;
}
+ std::unique_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize(
scottmg 2016/09/02 19:33:54 This is moved earlier so that the database directo
+ base::FilePath(ToolSupport::CommandLineArgumentToFilePathStringType(
+ options.database))));
+ if (!database) {
+ return EXIT_FAILURE;
+ }
+
+ InitializePersistentMetricsStorage(options.database);
+
#if defined(OS_MACOSX)
if (options.mach_service.empty()) {
// Don’t do this when being run by launchd. See launchd.plist(5).
@@ -386,13 +438,6 @@ int HandlerMain(int argc, char* argv[]) {
}
#endif // OS_MACOSX
- std::unique_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize(
- base::FilePath(ToolSupport::CommandLineArgumentToFilePathStringType(
- options.database))));
- if (!database) {
- return EXIT_FAILURE;
- }
-
// TODO(scottmg): options.rate_limit should be removed when we have a
// configurable database setting to control upload limiting.
// See https://crashpad.chromium.org/bug/23.

Powered by Google App Engine
This is Rietveld 408576698