Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: components/cronet/host_cache_persistence_manager.cc

Issue 2958023002: Add histograms and NetLog for host cache persistence (Closed)
Patch Set: use scoped timer Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/host_cache_persistence_manager.cc
diff --git a/components/cronet/host_cache_persistence_manager.cc b/components/cronet/host_cache_persistence_manager.cc
index 97e3bdca06adaee546c63c6e3681bf3c278f7b87..a804875224dafea82147b0f6da7557e1cfe18687 100644
--- a/components/cronet/host_cache_persistence_manager.cc
+++ b/components/cronet/host_cache_persistence_manager.cc
@@ -7,8 +7,10 @@
#include <memory>
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram_macros.h"
#include "base/values.h"
#include "components/prefs/pref_service.h"
+#include "net/log/net_log.h"
namespace cronet {
@@ -16,12 +18,16 @@ HostCachePersistenceManager::HostCachePersistenceManager(
net::HostCache* cache,
PrefService* pref_service,
std::string pref_name,
- base::TimeDelta delay)
+ base::TimeDelta delay,
+ net::NetLog* net_log)
: cache_(cache),
pref_service_(pref_service),
pref_name_(pref_name),
writing_pref_(false),
delay_(delay),
+ net_log_(net::NetLogWithSource::Make(
+ net_log,
+ net::NetLogSourceType::HOST_CACHE_PERSISTENCE_MANAGER)),
weak_factory_(this) {
DCHECK(cache_);
DCHECK(pref_service_);
@@ -51,8 +57,14 @@ void HostCachePersistenceManager::ReadFromDisk() {
if (writing_pref_)
return;
+ net_log_.BeginEvent(net::NetLogEventType::HOST_CACHE_PREF_READ);
const base::ListValue* pref_value = pref_service_->GetList(pref_name_);
- cache_->RestoreFromListValue(*pref_value);
+ bool success = cache_->RestoreFromListValue(*pref_value);
+ net_log_.EndEvent(net::NetLogEventType::HOST_CACHE_PREF_READ,
+ net::NetLog::BoolCallback("success", success));
+
+ UMA_HISTOGRAM_BOOLEAN("DNS.HostCache.RestoreSuccess", success);
+ UMA_HISTOGRAM_COUNTS_1000("DNS.HostCache.RestoreSize", pref_value->GetSize());
}
void HostCachePersistenceManager::ScheduleWrite() {
@@ -61,6 +73,7 @@ void HostCachePersistenceManager::ScheduleWrite() {
if (timer_.IsRunning())
return;
+ net_log_.AddEvent(net::NetLogEventType::HOST_CACHE_PERSISTENCE_START_TIMER);
timer_.Start(FROM_HERE, delay_,
base::Bind(&HostCachePersistenceManager::WriteToDisk,
weak_factory_.GetWeakPtr()));
@@ -69,6 +82,7 @@ void HostCachePersistenceManager::ScheduleWrite() {
void HostCachePersistenceManager::WriteToDisk() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ net_log_.AddEvent(net::NetLogEventType::HOST_CACHE_PREF_WRITE);
base::ListValue value;
cache_->GetAsListValue(&value, false);
writing_pref_ = true;
« no previous file with comments | « components/cronet/host_cache_persistence_manager.h ('k') | components/cronet/host_cache_persistence_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698