diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-24 20:29:36 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-24 20:29:36 +0000 |
commit | a30798372912744d643c58ddc61c6c7eabab2e51 (patch) | |
tree | e5768ac7ce0302b12780ba515fba52fe3ff4abae /chrome/browser/metrics | |
parent | 786d75cb93ca798afa23e1f5c548e102b7ede6d5 (diff) | |
download | chromium_src-a30798372912744d643c58ddc61c6c7eabab2e51.zip chromium_src-a30798372912744d643c58ddc61c6c7eabab2e51.tar.gz chromium_src-a30798372912744d643c58ddc61c6c7eabab2e51.tar.bz2 |
Collect metrics data from service process.
MetricsService in browser process sends request for histograms to service process if service is running. Request is called in parallel with requests to other browser child processes.
Service process still loses all data collected after browser process is gone.
BUG=305019
Review URL: https://codereview.chromium.org/26779002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/metrics')
-rw-r--r-- | chrome/browser/metrics/metrics_service.cc | 36 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.h | 3 |
2 files changed, 36 insertions, 3 deletions
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 98bbf81..9c1450d 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -228,6 +228,10 @@ #include "base/win/registry.h" #endif +#if !defined(OS_ANDROID) +#include "chrome/browser/service/service_process_control.h" +#endif + using base::Time; using content::BrowserThread; using content::ChildProcessData; @@ -476,6 +480,7 @@ MetricsService::MetricsService() self_ptr_factory_(this), state_saver_factory_(this), waiting_for_asynchronous_reporting_step_(false), + num_async_histogram_fetches_in_progress_(0), entropy_source_returned_(LAST_ENTROPY_NONE) { DCHECK(IsSingleThreaded()); InitializeMetricsState(); @@ -1306,12 +1311,32 @@ void MetricsService::OnMemoryDetailCollectionDone() { &MetricsService::OnHistogramSynchronizationDone, self_ptr_factory_.GetWeakPtr()); + base::TimeDelta timeout = + base::TimeDelta::FromMilliseconds(kMaxHistogramGatheringWaitDuration); + + DCHECK_EQ(num_async_histogram_fetches_in_progress_, 0); + +#if defined(OS_ANDROID) + // Android has no service process. + num_async_histogram_fetches_in_progress_ = 1; +#else // OS_ANDROID + num_async_histogram_fetches_in_progress_ = 2; + // Run requests to service and content in parallel. + if (!ServiceProcessControl::GetInstance()->GetHistograms(callback, timeout)) { + // Assume |num_async_histogram_fetches_in_progress_| is not changed by + // |GetHistograms()|. + DCHECK_EQ(num_async_histogram_fetches_in_progress_, 2); + // Assign |num_async_histogram_fetches_in_progress_| above and decrement it + // here to make code work even if |GetHistograms()| fired |callback|. + --num_async_histogram_fetches_in_progress_; + } +#endif // OS_ANDROID + // Set up the callback to task to call after we receive histograms from all // child processes. Wait time specifies how long to wait before absolutely // calling us back on the task. - content::FetchHistogramsAsynchronously( - base::MessageLoop::current(), callback, - base::TimeDelta::FromMilliseconds(kMaxHistogramGatheringWaitDuration)); + content::FetchHistogramsAsynchronously(base::MessageLoop::current(), callback, + timeout); } void MetricsService::OnHistogramSynchronizationDone() { @@ -1319,6 +1344,11 @@ void MetricsService::OnHistogramSynchronizationDone() { // This function should only be called as the callback from an ansynchronous // step. DCHECK(waiting_for_asynchronous_reporting_step_); + DCHECK_GT(num_async_histogram_fetches_in_progress_, 0); + + // Check if all expected requests finished. + if (--num_async_histogram_fetches_in_progress_ > 0) + return; waiting_for_asynchronous_reporting_step_ = false; OnFinalLogInfoCollectionDone(); diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h index a827a7e..d468f33 100644 --- a/chrome/browser/metrics/metrics_service.h +++ b/chrome/browser/metrics/metrics_service.h @@ -481,6 +481,9 @@ class MetricsService // This is used only for debugging. bool waiting_for_asynchronous_reporting_step_; + // Number of async histogram fetch requests in progress. + int num_async_histogram_fetches_in_progress_; + #if defined(OS_CHROMEOS) // The external metric service is used to log ChromeOS UMA events. scoped_refptr<chromeos::ExternalMetrics> external_metrics_; |