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 a2b2d7da315fb5517d4128c18e8f4146241cddec..7b2371ea3d3574ef027f5d6dee8d2ca94640d68a 100644 |
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc |
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc |
@@ -17,6 +17,7 @@ |
#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/metrics/persistent_histogram_allocator.h" |
+#include "base/metrics/persistent_metrics_file_util.h" |
#include "base/path_service.h" |
#include "base/rand_util.h" |
#include "base/strings/string16.h" |
@@ -110,6 +111,10 @@ namespace { |
// data. |
const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
+// Needs to be kept in sync with the writer in |
+// third_party/crashpad/crashpad/handler/handler_main.cc. |
+const char kCrashpadHistogramAllocatorName[] = "CrashpadMetrics"; |
+ |
// Checks whether it is the first time that cellular uploads logic should be |
// enabled based on whether the the preference for that logic is initialized. |
// This should happen only once as the used preference will be initialized |
@@ -124,18 +129,21 @@ bool ShouldClearSavedMetrics() { |
#endif |
} |
-void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
+void RegisterFileMetricsPreferences(PrefRegistrySimple* registry) { |
metrics::FileMetricsProvider::RegisterPrefs( |
registry, ChromeMetricsServiceClient::kBrowserMetricsName); |
+ metrics::FileMetricsProvider::RegisterPrefs(registry, |
+ kCrashpadHistogramAllocatorName); |
+ |
#if defined(OS_WIN) |
metrics::FileMetricsProvider::RegisterPrefs( |
registry, installer::kSetupHistogramAllocatorName); |
#endif |
} |
-std::unique_ptr<metrics::FileMetricsProvider> |
-CreateInstallerFileMetricsProvider(bool metrics_reporting_enabled) { |
+std::unique_ptr<metrics::FileMetricsProvider> CreateFileMetricsProvider( |
+ bool metrics_reporting_enabled) { |
// Fetch a worker-pool for performing I/O tasks that are not allowed on |
// the main UI thread. |
scoped_refptr<base::TaskRunner> task_runner = |
@@ -172,6 +180,40 @@ CreateInstallerFileMetricsProvider(bool metrics_reporting_enabled) { |
} |
} |
+ // Read the Crashpad metrics files. |
+ base::FilePath crash_dump_dir; |
+ if (base::PathService::Get(chrome::DIR_USER_DATA, |
+ &crash_dump_dir)) { |
+ base::FilePath crashpad_metrics_file_prev = |
+ crash_dump_dir.AppendASCII(kCrashpadHistogramAllocatorName) |
+ .AddExtension(base::PersistentMemoryAllocator::kFileExtension); |
+ if (metrics_reporting_enabled) { |
+ // Register the data from the previous run if crashpad_handler didn't exit |
+ // cleanly. |
+ file_metrics_provider->RegisterSource( |
+ crashpad_metrics_file_prev, |
+ metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_FILE, |
+ metrics::FileMetricsProvider::ASSOCIATE_PREVIOUS_RUN, |
+ kCrashpadHistogramAllocatorName); |
+ |
+ // Register data that will be populated for the current run. |
+ base::FilePath crashpad_metrics_file_cur = |
+ crash_dump_dir.AppendASCII(kCrashpadHistogramAllocatorName + |
+ std::string("-active")) |
+ .AddExtension(base::PersistentMemoryAllocator::kFileExtension); |
+ file_metrics_provider->RegisterSource( |
+ crashpad_metrics_file_prev, |
+ metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_FILE, |
+ metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, |
+ kCrashpadHistogramAllocatorName); |
+ } else { |
+ task_runner->PostTask( |
bcwhite
2016/09/14 13:16:12
Comment: This file must be deleted here so it isn'
scottmg
2016/09/14 20:37:01
Done.
|
+ FROM_HERE, |
+ base::Bind(base::IgnoreResult(&base::DeleteFile), |
+ crashpad_metrics_file_prev, /*recursive=*/false)); |
+ } |
+ } |
+ |
#if defined(OS_WIN) |
// Read metrics file from setup.exe. |
base::FilePath program_dir; |
@@ -186,30 +228,6 @@ CreateInstallerFileMetricsProvider(bool metrics_reporting_enabled) { |
return file_metrics_provider; |
} |
-// If there is a global metrics file being updated on disk, mark it to be |
-// deleted when the process exits. A normal shutdown is almost complete |
-// so there is no benefit in keeping a file with no new data to be processed |
-// during the next startup sequence. Deleting the file during shutdown adds |
-// an extra disk-access or two to shutdown but eliminates the unnecessary |
-// processing of the contents during startup only to find nothing. |
-void CleanUpGlobalPersistentHistogramStorage() { |
- base::GlobalHistogramAllocator* allocator = |
- base::GlobalHistogramAllocator::Get(); |
- if (!allocator) |
- return; |
- |
- const base::FilePath& path = allocator->GetPersistentLocation(); |
- if (path.empty()) |
- return; |
- |
- // Open (with delete) and then immediately close the file by going out of |
- // scope. This is the only cross-platform safe way to delete a file that may |
- // be open elsewhere. Open handles will continue to operate normally but |
- // new opens will not be possible. |
- base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
- base::File::FLAG_DELETE_ON_CLOSE); |
-} |
- |
} // namespace |
@@ -241,7 +259,7 @@ ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- CleanUpGlobalPersistentHistogramStorage(); |
+ base::CleanUpGlobalPersistentHistogramStorage(); |
} |
// static |
@@ -261,7 +279,7 @@ void ChromeMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) { |
metrics::MetricsService::RegisterPrefs(registry); |
metrics::StabilityMetricsHelper::RegisterPrefs(registry); |
- RegisterInstallerFileMetricsPreferences(registry); |
+ RegisterFileMetricsPreferences(registry); |
metrics::RegisterMetricsReportingStatePrefs(registry); |
@@ -432,7 +450,7 @@ void ChromeMetricsServiceClient::Initialize() { |
std::unique_ptr<metrics::MetricsProvider>( |
new metrics::ScreenInfoMetricsProvider)); |
- metrics_service_->RegisterMetricsProvider(CreateInstallerFileMetricsProvider( |
+ metrics_service_->RegisterMetricsProvider(CreateFileMetricsProvider( |
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled())); |
drive_metrics_provider_ = new metrics::DriveMetricsProvider( |