summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-08 22:26:48 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-08 22:26:48 +0000
commit0de360c6b0b08c2720bcb64cb9f13dbfeca90451 (patch)
treea4f46ef1bb463c6759fb818ecf96ff5ceceae345
parent64ade3bced12c45802c82cfa065e90d6c5b5d575 (diff)
downloadchromium_src-0de360c6b0b08c2720bcb64cb9f13dbfeca90451.zip
chromium_src-0de360c6b0b08c2720bcb64cb9f13dbfeca90451.tar.gz
chromium_src-0de360c6b0b08c2720bcb64cb9f13dbfeca90451.tar.bz2
[net] Measure DNS.CacheEvicted and DNS.CacheExpired.
On every eviction from HostCache record the time left to expiration (DNS.CacheEvicted) or time since expiration (DNS.CacheExpired). A distinction is made for evictions on Lookup (DNS.CacheExpiredOnGet). Review URL: https://chromiumcodereview.appspot.com/11359053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166781 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/expiring_cache.h33
-rw-r--r--net/base/host_cache.cc22
-rw-r--r--net/base/host_cache.h11
3 files changed, 61 insertions, 5 deletions
diff --git a/net/base/expiring_cache.h b/net/base/expiring_cache.h
index fe2fc65..ee3fc3f 100644
--- a/net/base/expiring_cache.h
+++ b/net/base/expiring_cache.h
@@ -14,6 +14,19 @@
namespace net {
+template <typename KeyType,
+ typename ValueType,
+ typename ExpirationType>
+class NoopEvictionHandler {
+ public:
+ void Handle(const KeyType& key,
+ const ValueType& value,
+ const ExpirationType& expiration,
+ const ExpirationType& now,
+ bool onGet) const {
+ }
+};
+
// Cache implementation where all entries have an explicit expiration policy. As
// new items are added, expired items will be removed first.
// The template types have the following requirements:
@@ -54,7 +67,10 @@ namespace net {
template <typename KeyType,
typename ValueType,
typename ExpirationType,
- typename ExpirationCompare>
+ typename ExpirationCompare,
+ typename EvictionHandler = NoopEvictionHandler<KeyType,
+ ValueType,
+ ExpirationType> >
class ExpiringCache {
private:
// Intentionally violate the C++ Style Guide so that EntryMap is known to be
@@ -113,7 +129,7 @@ class ExpiringCache {
// Immediately remove expired entries.
if (!expiration_comp_(now, it->second.second)) {
- entries_.erase(it);
+ Evict(it, now, true);
return NULL;
}
@@ -163,7 +179,7 @@ class ExpiringCache {
typename EntryMap::iterator it;
for (it = entries_.begin(); it != entries_.end(); ) {
if (!expiration_comp_(now, it->second.second)) {
- entries_.erase(it++);
+ Evict(it++, now, false);
} else {
++it;
}
@@ -175,15 +191,24 @@ class ExpiringCache {
// If the cache is still too full, start deleting items 'randomly'.
for (it = entries_.begin();
it != entries_.end() && entries_.size() >= max_entries_;) {
- entries_.erase(it++);
+ Evict(it++, now, false);
}
}
+ void Evict(typename EntryMap::iterator it,
+ const ExpirationType& now,
+ bool on_get) {
+ eviction_handler_.Handle(it->first, it->second.first, it->second.second,
+ now, on_get);
+ entries_.erase(it);
+ }
+
// Bound on total size of the cache.
size_t max_entries_;
EntryMap entries_;
ExpirationCompare expiration_comp_;
+ EvictionHandler eviction_handler_;
DISALLOW_COPY_AND_ASSIGN(ExpiringCache);
};
diff --git a/net/base/host_cache.cc b/net/base/host_cache.cc
index 1c14da7..fdfc334 100644
--- a/net/base/host_cache.cc
+++ b/net/base/host_cache.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram.h"
#include "base/string_number_conversions.h"
#include "net/base/net_errors.h"
@@ -92,4 +93,25 @@ scoped_ptr<HostCache> HostCache::CreateDefaultCache() {
return make_scoped_ptr(new HostCache(max_entries));
}
+void HostCache::EvictionHandler::Handle(
+ const Key& key,
+ const Entry& entry,
+ const base::TimeTicks& expiration,
+ const base::TimeTicks& now,
+ bool on_get) const {
+ if (on_get) {
+ DCHECK(now >= expiration);
+ UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheExpiredOnGet", now - expiration,
+ base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100);
+ return;
+ }
+ if (expiration > now) {
+ UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheEvicted", expiration - now,
+ base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100);
+ } else {
+ UMA_HISTOGRAM_CUSTOM_TIMES("DNS.CacheExpired", now - expiration,
+ base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 100);
+ }
+}
+
} // namespace net
diff --git a/net/base/host_cache.h b/net/base/host_cache.h
index 3826045..c4b248b 100644
--- a/net/base/host_cache.h
+++ b/net/base/host_cache.h
@@ -61,8 +61,17 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
HostResolverFlags host_resolver_flags;
};
+ struct EvictionHandler {
+ void Handle(const Key& key,
+ const Entry& entry,
+ const base::TimeTicks& expiration,
+ const base::TimeTicks& now,
+ bool onGet) const;
+ };
+
typedef ExpiringCache<Key, Entry, base::TimeTicks,
- std::less<base::TimeTicks> > EntryMap;
+ std::less<base::TimeTicks>,
+ EvictionHandler> EntryMap;
// Constructs a HostCache that stores up to |max_entries|.
explicit HostCache(size_t max_entries);