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

Unified Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Ilya Created 4 years, 8 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: chrome/browser/metrics/chrome_metrics_service_client.cc
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc
index ed4fe07e3de76fd0b621c1c19d21b31f16e43770..1135024c4cbcdb974c903566bcb7713ecc160d05 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc
@@ -15,6 +15,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
+#include "base/metrics/persistent_histogram_allocator.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/strings/string16.h"
@@ -138,6 +139,11 @@ bool ShouldClearSavedMetrics() {
}
void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) {
+ base::GlobalHistogramAllocator* allocator =
+ base::GlobalHistogramAllocator::GetEvenIfDisabled();
+ if (allocator)
Ilya Sherman 2016/04/25 19:48:40 In what case(s) might the allocator be null? (And
bcwhite 2016/04/25 20:37:17 I don't imagine it will be. But this code is so f
Ilya Sherman 2016/04/25 21:12:11 You're trading predictable crashes or DCHECK failu
+ metrics::FileMetricsProvider::RegisterPrefs(registry, allocator->Name());
+
#if defined(OS_WIN)
metrics::FileMetricsProvider::RegisterPrefs(
registry, installer::kSetupHistogramAllocatorName);
@@ -146,22 +152,48 @@ void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) {
void RegisterInstallerFileMetricsProvider(
metrics::MetricsService* metrics_service) {
-#if defined(OS_WIN)
- std::unique_ptr<metrics::FileMetricsProvider> file_metrics(
+ // Create an object to monitor files of metrics and include them in reports.
+ std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider(
new metrics::FileMetricsProvider(
content::BrowserThread::GetBlockingPool()
->GetTaskRunnerWithShutdownBehavior(
base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN),
g_browser_process->local_state()));
+
+ // Build the pathname for browser's persistent metrics file. Set it as the
+ // destination for the GlobalHistogramAllocator during process exit and add
+ // it to the file-metrics-provider so one written from a previous run will
+ // be loaded.
+ base::FilePath metrics_file;
+ if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) {
+ base::GlobalHistogramAllocator* allocator =
+ base::GlobalHistogramAllocator::GetEvenIfDisabled();
+ if (allocator) {
+ const char* allocator_name = allocator->Name();
+ metrics_file = metrics_file.AppendASCII(allocator_name)
+ .AddExtension(FILE_PATH_LITERAL(".pma"));
+ allocator->SetPersistentLocation(metrics_file);
+
+ file_metrics_provider->RegisterFile(
+ metrics_file,
+ metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC,
+ allocator_name);
+ }
+ }
+
+#if defined(OS_WIN)
+ // Read metrics file from setup.exe.
base::FilePath program_dir;
base::PathService::Get(base::DIR_EXE, &program_dir);
- file_metrics->RegisterFile(
+ file_metrics_provider->RegisterFile(
program_dir.AppendASCII(installer::kSetupHistogramAllocatorName)
- .AddExtension(L".pma"),
+ .AddExtension(FILE_PATH_LITERAL(".pma")),
metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC,
installer::kSetupHistogramAllocatorName);
- metrics_service->RegisterMetricsProvider(std::move(file_metrics));
#endif
+
+ // Give the new provider to the metrics service.
+ metrics_service->RegisterMetricsProvider(std::move(file_metrics_provider));
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698