diff options
author | mek <mek@chromium.org> | 2016-03-21 17:18:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-22 00:20:07 +0000 |
commit | 34f6cabb27ade557d7aed6ca875a12eab5d65a1f (patch) | |
tree | 19466614eeaaf87e068af6c3f73f9a9c28e91363 /content/browser/service_worker | |
parent | 2be9c60dd057416445c29279844c2133a203d9f8 (diff) | |
download | chromium_src-34f6cabb27ade557d7aed6ca875a12eab5d65a1f.zip chromium_src-34f6cabb27ade557d7aed6ca875a12eab5d65a1f.tar.gz chromium_src-34f6cabb27ade557d7aed6ca875a12eab5d65a1f.tar.bz2 |
Separate out foreign fetch from regular fetch in UMA stats.
BUG=540509
Review URL: https://codereview.chromium.org/1813773004
Cr-Commit-Position: refs/heads/master@{#382451}
Diffstat (limited to 'content/browser/service_worker')
5 files changed, 67 insertions, 34 deletions
diff --git a/content/browser/service_worker/service_worker_fetch_dispatcher.cc b/content/browser/service_worker/service_worker_fetch_dispatcher.cc index d8091b8..dfcce9a 100644 --- a/content/browser/service_worker/service_worker_fetch_dispatcher.cc +++ b/content/browser/service_worker/service_worker_fetch_dispatcher.cc @@ -69,7 +69,7 @@ void ServiceWorkerFetchDispatcher::DidWaitActivation() { return; } version_->RunAfterStartWorker( - ResourceTypeToEventType(resource_type_), + GetEventType(), base::Bind(&ServiceWorkerFetchDispatcher::DispatchFetchEvent, weak_factory_.GetWeakPtr()), base::Bind(&ServiceWorkerFetchDispatcher::DidFail, @@ -94,10 +94,9 @@ void ServiceWorkerFetchDispatcher::DispatchFetchEvent() { base::Closure prepare_callback = prepare_callback_; prepare_callback.Run(); - int request_id = - version_->StartRequest(ServiceWorkerMetrics::EventType::FETCH, - base::Bind(&ServiceWorkerFetchDispatcher::DidFail, - weak_factory_.GetWeakPtr())); + int request_id = version_->StartRequest( + GetEventType(), base::Bind(&ServiceWorkerFetchDispatcher::DidFail, + weak_factory_.GetWeakPtr())); version_->DispatchEvent<ServiceWorkerHostMsg_FetchEventFinished>( request_id, ServiceWorkerMsg_FetchEvent(request_id, *request_.get()), base::Bind(&ServiceWorkerFetchDispatcher::DidFinish, @@ -133,4 +132,11 @@ void ServiceWorkerFetchDispatcher::DidFinish( fetch_callback.Run(SERVICE_WORKER_OK, fetch_result, response, version); } +ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() + const { + if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) + return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; + return ResourceTypeToEventType(resource_type_); +} + } // namespace content diff --git a/content/browser/service_worker/service_worker_fetch_dispatcher.h b/content/browser/service_worker/service_worker_fetch_dispatcher.h index efc3d29..82a4a2d5 100644 --- a/content/browser/service_worker/service_worker_fetch_dispatcher.h +++ b/content/browser/service_worker/service_worker_fetch_dispatcher.h @@ -8,6 +8,7 @@ #include "base/callback.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" +#include "content/browser/service_worker/service_worker_metrics.h" #include "content/common/content_export.h" #include "content/common/service_worker/service_worker_status_code.h" #include "content/common/service_worker/service_worker_types.h" @@ -47,6 +48,8 @@ class CONTENT_EXPORT ServiceWorkerFetchDispatcher { ServiceWorkerFetchEventResult fetch_result, const ServiceWorkerResponse& response); + ServiceWorkerMetrics::EventType GetEventType() const; + scoped_refptr<ServiceWorkerVersion> version_; base::Closure prepare_callback_; FetchCallback fetch_callback_; diff --git a/content/browser/service_worker/service_worker_metrics.cc b/content/browser/service_worker/service_worker_metrics.cc index 2ee60c7..2062d0a 100644 --- a/content/browser/service_worker/service_worker_metrics.cc +++ b/content/browser/service_worker/service_worker_metrics.cc @@ -52,8 +52,6 @@ const char* ServiceWorkerMetrics::EventTypeToString(EventType event_type) { return "Activate"; case EventType::INSTALL: return "Install"; - case EventType::FETCH: - return "Fetch"; case EventType::SYNC: return "Sync"; case EventType::NOTIFICATION_CLICK: @@ -78,6 +76,9 @@ const char* ServiceWorkerMetrics::EventTypeToString(EventType event_type) { return "Fetch Subresource"; case EventType::UNKNOWN: return "Unknown"; + case EventType::FOREIGN_FETCH: + return "Foreign Fetch"; + case EventType::DEPRECATED_FETCH: case EventType::NUM_TYPES: break; } @@ -217,11 +218,24 @@ void ServiceWorkerMetrics::RecordEventHandledRatio(EventType event, else if (handled_events == 0) type = EVENT_HANDLED_NONE; - // For now Fetch is the only type that is recorded. - if (event != EventType::FETCH) - return; - UMA_HISTOGRAM_ENUMERATION("ServiceWorker.EventHandledRatioType.Fetch", type, - NUM_EVENT_HANDLED_RATIO_TYPE); + // For now Fetch and Foreign Fetch are the only types that are recorded. + switch (event) { + case EventType::FETCH_MAIN_FRAME: + case EventType::FETCH_SUB_FRAME: + case EventType::FETCH_SHARED_WORKER: + case EventType::FETCH_SUB_RESOURCE: + UMA_HISTOGRAM_ENUMERATION("ServiceWorker.EventHandledRatioType.Fetch", + type, NUM_EVENT_HANDLED_RATIO_TYPE); + break; + case EventType::FOREIGN_FETCH: + UMA_HISTOGRAM_ENUMERATION( + "ServiceWorker.EventHandledRatioType.ForeignFetch", type, + NUM_EVENT_HANDLED_RATIO_TYPE); + break; + default: + // Do nothing. + break; + } } void ServiceWorkerMetrics::RecordEventTimeout(EventType event) { @@ -240,7 +254,6 @@ void ServiceWorkerMetrics::RecordEventDuration(EventType event, case EventType::INSTALL: UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.InstallEvent.Time", time); break; - case EventType::FETCH: case EventType::FETCH_MAIN_FRAME: case EventType::FETCH_SUB_FRAME: case EventType::FETCH_SHARED_WORKER: @@ -253,6 +266,15 @@ void ServiceWorkerMetrics::RecordEventDuration(EventType event, time); } break; + case EventType::FOREIGN_FETCH: + if (was_handled) { + UMA_HISTOGRAM_MEDIUM_TIMES( + "ServiceWorker.ForeignFetchEvent.HasResponse.Time", time); + } else { + UMA_HISTOGRAM_MEDIUM_TIMES( + "ServiceWorker.ForeignFetchEvent.Fallback.Time", time); + } + break; case EventType::SYNC: UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.BackgroundSyncEvent.Time", time); @@ -278,6 +300,7 @@ void ServiceWorkerMetrics::RecordEventDuration(EventType event, case EventType::SERVICE_PORT_CONNECT: break; + case EventType::DEPRECATED_FETCH: case EventType::UNKNOWN: case EventType::NUM_TYPES: NOTREACHED() << "Invalid event type"; diff --git a/content/browser/service_worker/service_worker_metrics.h b/content/browser/service_worker/service_worker_metrics.h index 6ad0663..6ca3203 100644 --- a/content/browser/service_worker/service_worker_metrics.h +++ b/content/browser/service_worker/service_worker_metrics.h @@ -74,21 +74,22 @@ class ServiceWorkerMetrics { // Used for UMA. Append-only. enum class EventType { - ACTIVATE, - INSTALL, - FETCH, // Deprecated, use a more specific FETCH_ type. - SYNC, - NOTIFICATION_CLICK, - PUSH, - GEOFENCING, - SERVICE_PORT_CONNECT, - MESSAGE, - NOTIFICATION_CLOSE, - FETCH_MAIN_FRAME, - FETCH_SUB_FRAME, - FETCH_SHARED_WORKER, - FETCH_SUB_RESOURCE, - UNKNOWN, // Used when event type is not known. + ACTIVATE = 0, + INSTALL = 1, + DEPRECATED_FETCH = 2, // Deprecated, use a more specific FETCH_ type. + SYNC = 3, + NOTIFICATION_CLICK = 4, + PUSH = 5, + GEOFENCING = 6, + SERVICE_PORT_CONNECT = 7, + MESSAGE = 8, + NOTIFICATION_CLOSE = 9, + FETCH_MAIN_FRAME = 10, + FETCH_SUB_FRAME = 11, + FETCH_SHARED_WORKER = 12, + FETCH_SUB_RESOURCE = 13, + UNKNOWN = 14, // Used when event type is not known. + FOREIGN_FETCH = 15, // Add new events to record here. NUM_TYPES }; diff --git a/content/browser/service_worker/service_worker_version_unittest.cc b/content/browser/service_worker/service_worker_version_unittest.cc index e47df282..06bb32b 100644 --- a/content/browser/service_worker/service_worker_version_unittest.cc +++ b/content/browser/service_worker/service_worker_version_unittest.cc @@ -498,7 +498,7 @@ TEST_F(ServiceWorkerVersionTest, StartUnregisteredButStillLiveWorker) { // Dispatch an event on the unregistered and stopped but still live worker. status = SERVICE_WORKER_ERROR_FAILED; - SimulateDispatchEvent(ServiceWorkerMetrics::EventType::FETCH); + SimulateDispatchEvent(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME); // The worker should be now started again. EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status()); @@ -636,7 +636,7 @@ TEST_F(ServiceWorkerVersionTest, IdleTimeout) { // Completing an event resets the idle time. version_->idle_time_ -= kOneSecond; idle_time = version_->idle_time_; - SimulateDispatchEvent(ServiceWorkerMetrics::EventType::FETCH); + SimulateDispatchEvent(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME); EXPECT_LT(idle_time, version_->idle_time_); // Starting and finishing a request resets the idle time. @@ -820,13 +820,13 @@ TEST_F(ServiceWorkerVersionTest, RequestTimeout) { ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value version_->SetStatus(ServiceWorkerVersion::ACTIVATED); - version_->StartWorker(ServiceWorkerMetrics::EventType::FETCH, + version_->StartWorker(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME, base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); base::RunLoop().RunUntilIdle(); // Create a request. int request_id = - version_->StartRequest(ServiceWorkerMetrics::EventType::FETCH, + version_->StartRequest(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME, CreateReceiverOnCurrentThread(&status)); base::RunLoop().RunUntilIdle(); @@ -903,13 +903,13 @@ TEST_F(ServiceWorkerVersionTest, MixedRequestTimeouts) { SERVICE_WORKER_ERROR_NETWORK; // dummy value version_->SetStatus(ServiceWorkerVersion::ACTIVATED); - version_->StartWorker(ServiceWorkerMetrics::EventType::FETCH, + version_->StartWorker(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME, base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); base::RunLoop().RunUntilIdle(); // Create a fetch request that should expire sometime later. int fetch_request_id = - version_->StartRequest(ServiceWorkerMetrics::EventType::FETCH, + version_->StartRequest(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME, CreateReceiverOnCurrentThread(&fetch_status)); // Create a request that should expire Now(). int sync_request_id = version_->StartRequestWithCustomTimeout( |