Commit 45bde6db authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Move some histogram recordings to ServiceWorkerStorage

This CL removes ServiceWorkerMetrics dependency from
ServiceWorkerStorage by embedding UMA recordings into it.
ServiceWorkerStorage will be moved to //components/services/storage
but ServiceWorkerMetrics will remain //content. This means that
ServiceWorkerStorage cannot use ServiceWorkerMetrics.

This CL also applies histogram guidelines
(//tools/metrics/histograms/README.md).

Bug: 1016064
Change-Id: I79ba99c096fc422166b0f0f23d27728804701113
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2394899Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804710}
parent 63a79b92
...@@ -238,10 +238,6 @@ ServiceWorkerMetrics::Site ServiceWorkerMetrics::SiteFromURL(const GURL& url) { ...@@ -238,10 +238,6 @@ ServiceWorkerMetrics::Site ServiceWorkerMetrics::SiteFromURL(const GURL& url) {
return ServiceWorkerMetrics::Site::OTHER; return ServiceWorkerMetrics::Site::OTHER;
} }
void ServiceWorkerMetrics::CountInitDiskCacheResult(bool result) {
UMA_HISTOGRAM_BOOLEAN("ServiceWorker.DiskCache.InitResult", result);
}
void ServiceWorkerMetrics::CountReadResponseResult( void ServiceWorkerMetrics::CountReadResponseResult(
ServiceWorkerMetrics::ReadResponseResult result) { ServiceWorkerMetrics::ReadResponseResult result) {
UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.ReadResponseResult", UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.ReadResponseResult",
...@@ -254,17 +250,6 @@ void ServiceWorkerMetrics::CountWriteResponseResult( ...@@ -254,17 +250,6 @@ void ServiceWorkerMetrics::CountWriteResponseResult(
result, NUM_WRITE_RESPONSE_RESULT_TYPES); result, NUM_WRITE_RESPONSE_RESULT_TYPES);
} }
void ServiceWorkerMetrics::RecordPurgeResourceResult(int net_error) {
base::UmaHistogramSparse("ServiceWorker.Storage.PurgeResourceResult",
std::abs(net_error));
}
void ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
DeleteAndStartOverResult result) {
UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Storage.DeleteAndStartOverResult",
result, NUM_DELETE_AND_START_OVER_RESULT_TYPES);
}
void ServiceWorkerMetrics::CountControlledPageLoad(Site site, void ServiceWorkerMetrics::CountControlledPageLoad(Site site,
bool is_main_frame_load) { bool is_main_frame_load) {
DCHECK_NE(site, Site::OTHER); DCHECK_NE(site, Site::OTHER);
...@@ -565,10 +550,6 @@ void ServiceWorkerMetrics::RecordStartServiceWorkerForNavigationHintResult( ...@@ -565,10 +550,6 @@ void ServiceWorkerMetrics::RecordStartServiceWorkerForNavigationHintResult(
result); result);
} }
void ServiceWorkerMetrics::RecordRegisteredOriginCount(size_t origin_count) {
UMA_HISTOGRAM_COUNTS_1M("ServiceWorker.RegisteredOriginCount", origin_count);
}
void ServiceWorkerMetrics::RecordLookupRegistrationTime( void ServiceWorkerMetrics::RecordLookupRegistrationTime(
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
base::TimeDelta duration) { base::TimeDelta duration) {
......
...@@ -39,14 +39,6 @@ class ServiceWorkerMetrics { ...@@ -39,14 +39,6 @@ class ServiceWorkerMetrics {
NUM_WRITE_RESPONSE_RESULT_TYPES, NUM_WRITE_RESPONSE_RESULT_TYPES,
}; };
// Used for UMA. Append-only.
enum DeleteAndStartOverResult {
DELETE_OK,
DELETE_DATABASE_ERROR,
DELETE_DISK_CACHE_ERROR,
NUM_DELETE_AND_START_OVER_RESULT_TYPES,
};
// Used for UMA. Append-only. // Used for UMA. Append-only.
enum class StopStatus { enum class StopStatus {
NORMAL, NORMAL,
...@@ -179,15 +171,11 @@ class ServiceWorkerMetrics { ...@@ -179,15 +171,11 @@ class ServiceWorkerMetrics {
// If the |url| is not a special site, returns Site::OTHER. // If the |url| is not a special site, returns Site::OTHER.
static Site SiteFromURL(const GURL& url); static Site SiteFromURL(const GURL& url);
// Used for ServiceWorkerDiskCache. // Counts the result of reading a service worker script from storage.
static void CountInitDiskCacheResult(bool result);
static void CountReadResponseResult(ReadResponseResult result); static void CountReadResponseResult(ReadResponseResult result);
// Counts the result of writing a service worker script to storage.
static void CountWriteResponseResult(WriteResponseResult result); static void CountWriteResponseResult(WriteResponseResult result);
// Used for ServiceWorkerStorage.
static void RecordPurgeResourceResult(int net_error);
static void RecordDeleteAndStartOverResult(DeleteAndStartOverResult result);
// Counts the number of page loads controlled by a Service Worker. // Counts the number of page loads controlled by a Service Worker.
static void CountControlledPageLoad(Site site, static void CountControlledPageLoad(Site site,
bool is_main_frame_load); bool is_main_frame_load);
...@@ -246,9 +234,6 @@ class ServiceWorkerMetrics { ...@@ -246,9 +234,6 @@ class ServiceWorkerMetrics {
static void RecordStartServiceWorkerForNavigationHintResult( static void RecordStartServiceWorkerForNavigationHintResult(
StartServiceWorkerForNavigationHintResult result); StartServiceWorkerForNavigationHintResult result);
// Records the number of origins with a registered service worker.
static void RecordRegisteredOriginCount(size_t origin_count);
// Records the duration of looking up an existing registration. // Records the duration of looking up an existing registration.
// |status| is the result of lookup. The records for the cases where // |status| is the result of lookup. The records for the cases where
// the registration is found (kOk), not found (kErrorNotFound), or an error // the registration is found (kOk), not found (kErrorNotFound), or an error
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -60,6 +61,19 @@ const base::FilePath::CharType kDatabaseName[] = FILE_PATH_LITERAL("Database"); ...@@ -60,6 +61,19 @@ const base::FilePath::CharType kDatabaseName[] = FILE_PATH_LITERAL("Database");
const base::FilePath::CharType kDiskCacheName[] = const base::FilePath::CharType kDiskCacheName[] =
FILE_PATH_LITERAL("ScriptCache"); FILE_PATH_LITERAL("ScriptCache");
// Used for UMA. Append-only.
enum class DeleteAndStartOverResult {
kDeleteOk = 0,
kDeleteDatabaseError = 1,
kDeleteDiskCacheError = 2,
kMaxValue = kDeleteDiskCacheError,
};
void RecordDeleteAndStartOverResult(DeleteAndStartOverResult result) {
base::UmaHistogramEnumeration(
"ServiceWorker.Storage.DeleteAndStartOverResult", result);
}
} // namespace } // namespace
ServiceWorkerStorage::InitialData::InitialData() ServiceWorkerStorage::InitialData::InitialData()
...@@ -1069,8 +1083,8 @@ void ServiceWorkerStorage::DidReadInitialData( ...@@ -1069,8 +1083,8 @@ void ServiceWorkerStorage::DidReadInitialData(
next_resource_id_ = data->next_resource_id; next_resource_id_ = data->next_resource_id;
registered_origins_.swap(data->origins); registered_origins_.swap(data->origins);
state_ = STORAGE_STATE_INITIALIZED; state_ = STORAGE_STATE_INITIALIZED;
ServiceWorkerMetrics::RecordRegisteredOriginCount( base::UmaHistogramCounts1M("ServiceWorker.RegisteredOriginCount",
registered_origins_.size()); registered_origins_.size());
} else { } else {
DVLOG(2) << "Failed to initialize: " DVLOG(2) << "Failed to initialize: "
<< ServiceWorkerDatabase::StatusToString(status); << ServiceWorkerDatabase::StatusToString(status);
...@@ -1232,7 +1246,8 @@ void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { ...@@ -1232,7 +1246,8 @@ void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) {
<< net::ErrorToString(rv); << net::ErrorToString(rv);
Disable(); Disable();
} }
ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK); base::UmaHistogramBoolean("ServiceWorker.DiskCache.InitResult",
rv == net::OK);
} }
void ServiceWorkerStorage::StartPurgingResources( void ServiceWorkerStorage::StartPurgingResources(
...@@ -1282,7 +1297,8 @@ void ServiceWorkerStorage::OnResourcePurged(int64_t id, int rv) { ...@@ -1282,7 +1297,8 @@ void ServiceWorkerStorage::OnResourcePurged(int64_t id, int rv) {
DCHECK(is_purge_pending_); DCHECK(is_purge_pending_);
is_purge_pending_ = false; is_purge_pending_ = false;
ServiceWorkerMetrics::RecordPurgeResourceResult(rv); base::UmaHistogramSparse("ServiceWorker.Storage.PurgeResourceResult",
std::abs(rv));
// TODO(falken): Is it always OK to ClearPurgeableResourceIds if |rv| is // TODO(falken): Is it always OK to ClearPurgeableResourceIds if |rv| is
// failure? The disk cache entry might still remain and once we remove its // failure? The disk cache entry might still remain and once we remove its
...@@ -1654,8 +1670,8 @@ void ServiceWorkerStorage::DidDeleteDatabase( ...@@ -1654,8 +1670,8 @@ void ServiceWorkerStorage::DidDeleteDatabase(
// Give up the corruption recovery until the browser restarts. // Give up the corruption recovery until the browser restarts.
LOG(ERROR) << "Failed to delete the database: " LOG(ERROR) << "Failed to delete the database: "
<< ServiceWorkerDatabase::StatusToString(status); << ServiceWorkerDatabase::StatusToString(status);
ServiceWorkerMetrics::RecordDeleteAndStartOverResult( RecordDeleteAndStartOverResult(
ServiceWorkerMetrics::DELETE_DATABASE_ERROR); DeleteAndStartOverResult::kDeleteDatabaseError);
std::move(callback).Run(status); std::move(callback).Run(status);
return; return;
} }
...@@ -1684,14 +1700,13 @@ void ServiceWorkerStorage::DidDeleteDiskCache(DatabaseStatusCallback callback, ...@@ -1684,14 +1700,13 @@ void ServiceWorkerStorage::DidDeleteDiskCache(DatabaseStatusCallback callback,
if (!result) { if (!result) {
// Give up the corruption recovery until the browser restarts. // Give up the corruption recovery until the browser restarts.
LOG(ERROR) << "Failed to delete the diskcache."; LOG(ERROR) << "Failed to delete the diskcache.";
ServiceWorkerMetrics::RecordDeleteAndStartOverResult( RecordDeleteAndStartOverResult(
ServiceWorkerMetrics::DELETE_DISK_CACHE_ERROR); DeleteAndStartOverResult::kDeleteDiskCacheError);
std::move(callback).Run(ServiceWorkerDatabase::Status::kErrorFailed); std::move(callback).Run(ServiceWorkerDatabase::Status::kErrorFailed);
return; return;
} }
DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
ServiceWorkerMetrics::RecordDeleteAndStartOverResult( RecordDeleteAndStartOverResult(DeleteAndStartOverResult::kDeleteOk);
ServiceWorkerMetrics::DELETE_OK);
std::move(callback).Run(ServiceWorkerDatabase::Status::kOk); std::move(callback).Run(ServiceWorkerDatabase::Status::kOk);
} }
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "components/services/storage/public/mojom/local_storage_control.mojom.h" #include "components/services/storage/public/mojom/local_storage_control.mojom.h"
#include "components/services/storage/public/mojom/service_worker_storage_control.mojom.h" #include "components/services/storage/public/mojom/service_worker_storage_control.mojom.h"
#include "content/browser/service_worker/service_worker_database.h" #include "content/browser/service_worker/service_worker_database.h"
#include "content/browser/service_worker/service_worker_metrics.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "url/gurl.h" #include "url/gurl.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment