summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/background_sync/background_sync_manager.cc61
-rw-r--r--content/browser/background_sync/background_sync_manager.h3
-rw-r--r--content/browser/background_sync/background_sync_metrics.cc7
-rw-r--r--content/browser/background_sync/background_sync_metrics.h6
-rw-r--r--tools/metrics/histograms/histograms.xml11
5 files changed, 57 insertions, 31 deletions
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index 7903aa4..960c63f8 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -799,29 +799,37 @@ void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) {
}
}
- base::TimeTicks start_time = base::TimeTicks::Now();
-
- // Fire the sync event of the ready registrations and run |callback| once
- // they're all done.
- base::Closure events_fired_barrier_closure =
- base::BarrierClosure(sw_id_and_keys_to_fire.size(), base::Bind(callback));
-
- // Record the total time taken after all events have run to completion.
- base::Closure events_completed_barrier_closure =
- base::BarrierClosure(sw_id_and_keys_to_fire.size(),
- base::Bind(&OnAllSyncEventsCompleted, start_time));
-
- for (const auto& sw_id_and_key : sw_id_and_keys_to_fire) {
- int64 service_worker_id = sw_id_and_key.first;
- const BackgroundSyncRegistration* registration =
- LookupRegistration(service_worker_id, sw_id_and_key.second);
-
- service_worker_context_->FindRegistrationForId(
- service_worker_id, sw_to_registrations_map_[service_worker_id].origin,
- base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration,
- weak_ptr_factory_.GetWeakPtr(), sw_id_and_key.second,
- registration->id(), events_fired_barrier_closure,
- events_completed_barrier_closure));
+ // If there are no registrations currently ready, then just run |callback|.
+ // Otherwise, fire them all, and record the result when done.
+ if (sw_id_and_keys_to_fire.size() == 0) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback));
+ } else {
+ base::TimeTicks start_time = base::TimeTicks::Now();
+
+ // Fire the sync event of the ready registrations and run |callback| once
+ // they're all done.
+ base::Closure events_fired_barrier_closure = base::BarrierClosure(
+ sw_id_and_keys_to_fire.size(), base::Bind(callback));
+
+ // Record the total time taken after all events have run to completion.
+ base::Closure events_completed_barrier_closure =
+ base::BarrierClosure(sw_id_and_keys_to_fire.size(),
+ base::Bind(&OnAllSyncEventsCompleted, start_time,
+ sw_id_and_keys_to_fire.size()));
+
+ for (const auto& sw_id_and_key : sw_id_and_keys_to_fire) {
+ int64 service_worker_id = sw_id_and_key.first;
+ const BackgroundSyncRegistration* registration =
+ LookupRegistration(service_worker_id, sw_id_and_key.second);
+
+ service_worker_context_->FindRegistrationForId(
+ service_worker_id, sw_to_registrations_map_[service_worker_id].origin,
+ base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration,
+ weak_ptr_factory_.GetWeakPtr(), sw_id_and_key.second,
+ registration->id(), events_fired_barrier_closure,
+ events_completed_barrier_closure));
+ }
}
SchedulePendingRegistrations();
@@ -948,10 +956,11 @@ void BackgroundSyncManager::EventCompleteDidStore(
// static
void BackgroundSyncManager::OnAllSyncEventsCompleted(
- const base::TimeTicks& start_time) {
+ const base::TimeTicks& start_time,
+ int number_of_batched_sync_events) {
// Record the combined time taken by all sync events.
- BackgroundSyncMetrics::RecordBatchSyncEventHandlingTime(
- base::TimeTicks::Now() - start_time);
+ BackgroundSyncMetrics::RecordBatchSyncEventComplete(
+ base::TimeTicks::Now() - start_time, number_of_batched_sync_events);
}
void BackgroundSyncManager::OnRegistrationDeletedImpl(
diff --git a/content/browser/background_sync/background_sync_manager.h b/content/browser/background_sync/background_sync_manager.h
index a235dac..ea0236f 100644
--- a/content/browser/background_sync/background_sync_manager.h
+++ b/content/browser/background_sync/background_sync_manager.h
@@ -267,7 +267,8 @@ class CONTENT_EXPORT BackgroundSyncManager
ServiceWorkerStatusCode status_code);
// Called when all sync events have completed.
- static void OnAllSyncEventsCompleted(const base::TimeTicks& start_time);
+ static void OnAllSyncEventsCompleted(const base::TimeTicks& start_time,
+ int number_of_batched_sync_events);
// OnRegistrationDeleted callbacks
void OnRegistrationDeletedImpl(int64 registration_id,
diff --git a/content/browser/background_sync/background_sync_metrics.cc b/content/browser/background_sync/background_sync_metrics.cc
index 97f20b2..7701798 100644
--- a/content/browser/background_sync/background_sync_metrics.cc
+++ b/content/browser/background_sync/background_sync_metrics.cc
@@ -22,13 +22,16 @@ void BackgroundSyncMetrics::RecordEventResult(SyncPeriodicity periodicity,
NOTREACHED();
}
-void BackgroundSyncMetrics::RecordBatchSyncEventHandlingTime(
- const base::TimeDelta& time) {
+void BackgroundSyncMetrics::RecordBatchSyncEventComplete(
+ const base::TimeDelta& time,
+ int number_of_batched_sync_events) {
// The total batch handling time should be under 5 minutes; we'll record up to
// 6 minutes, to be safe.
UMA_HISTOGRAM_CUSTOM_TIMES("BackgroundSync.Event.Time", time,
base::TimeDelta::FromMilliseconds(10),
base::TimeDelta::FromMinutes(6), 50);
+ UMA_HISTOGRAM_COUNTS_100("BackgroundSync.Event.BatchSize",
+ number_of_batched_sync_events);
}
void BackgroundSyncMetrics::CountRegister(
diff --git a/content/browser/background_sync/background_sync_metrics.h b/content/browser/background_sync/background_sync_metrics.h
index 5b74ed5e..290d9f9 100644
--- a/content/browser/background_sync/background_sync_metrics.h
+++ b/content/browser/background_sync/background_sync_metrics.h
@@ -31,8 +31,10 @@ class BackgroundSyncMetrics {
// Records the result of a single sync event firing.
static void RecordEventResult(SyncPeriodicity periodicity, bool result);
- // Records the time spent running a batch of sync events.
- static void RecordBatchSyncEventHandlingTime(const base::TimeDelta& time);
+ // Records the result of running a batch of sync events, including the total
+ // time spent, and the batch size.
+ static void RecordBatchSyncEventComplete(const base::TimeDelta& time,
+ int number_of_batched_sync_events);
// Records the result of trying to register a sync. |could_fire| indicates
// whether the conditions were sufficient for the sync to fire immediately at
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 510b5d3..264bafe 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -2438,6 +2438,17 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
+<histogram name="BackgroundSync.Event.BatchSize">
+ <owner>iclelland@chromium.org</owner>
+ <summary>
+ Records the number of sync events which were fired in a batch. A batch is
+ defined as the set of sync events dispatched at the same time by the
+ BackgroundSyncManager. Periodic syncs often run in a batch. One-shots
+ usually run individually (a batch of one), unless the device was offline and
+ multiple are waiting for the device to go back online.
+ </summary>
+</histogram>
+
<histogram name="BackgroundSync.Event.OneShotResult" enum="BooleanSuccess">
<owner>iclelland@chromium.org</owner>
<summary>Records whether a one-shot sync event succeeded or failed.</summary>