diff options
author | ttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-31 22:46:24 +0000 |
---|---|---|
committer | ttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-31 22:46:24 +0000 |
commit | 4e314a9f15c1f439fae50edeb08dfa45766613b2 (patch) | |
tree | 11090eb10be77c3fb84080de436b00400383f279 /net | |
parent | abb8a16efe84999c5c94a10c5a2f6ac98e794ccb (diff) | |
download | chromium_src-4e314a9f15c1f439fae50edeb08dfa45766613b2.zip chromium_src-4e314a9f15c1f439fae50edeb08dfa45766613b2.tar.gz chromium_src-4e314a9f15c1f439fae50edeb08dfa45766613b2.tar.bz2 |
HttpAuthCache: add eviction histograms.
Add histograms to measure how often realms and paths are evicted from
the HTTP auth cache, along with the time since creation and last use
for evicted realms.
BUG=354187
TEST=HttpAuthCacheTest.* in net_unittests still passes
Review URL: https://codereview.chromium.org/205673003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_auth_cache.cc | 41 | ||||
-rw-r--r-- | net/http/http_auth_cache.h | 6 |
2 files changed, 45 insertions, 2 deletions
diff --git a/net/http/http_auth_cache.cc b/net/http/http_auth_cache.cc index 63bad07..d989830 100644 --- a/net/http/http_auth_cache.cc +++ b/net/http/http_auth_cache.cc @@ -5,6 +5,7 @@ #include "net/http/http_auth_cache.h" #include "base/logging.h" +#include "base/metrics/histogram.h" #include "base/strings/string_util.h" namespace { @@ -57,6 +58,14 @@ struct IsEnclosedBy { const std::string& path; }; +void RecordLookupPosition(int position) { + UMA_HISTOGRAM_COUNTS_100("Net.HttpAuthCacheLookupPosition", position); +} + +void RecordLookupByPathPosition(int position) { + UMA_HISTOGRAM_COUNTS_100("Net.HttpAuthCacheLookupByPathPosition", position); +} + } // namespace namespace net { @@ -73,12 +82,18 @@ HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, HttpAuth::Scheme scheme) { CheckOriginIsValid(origin); + int entries_examined = 0; // Linear scan through the realm entries. for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { + ++entries_examined; if (it->origin() == origin && it->realm() == realm && - it->scheme() == scheme) + it->scheme() == scheme) { + it->last_use_time_ = base::TimeTicks::Now(); + RecordLookupPosition(entries_examined); return &(*it); + } } + RecordLookupPosition(0); return NULL; // No realm entry found. } @@ -89,6 +104,7 @@ HttpAuthCache::Entry* HttpAuthCache::LookupByPath(const GURL& origin, const std::string& path) { HttpAuthCache::Entry* best_match = NULL; size_t best_match_length = 0; + int best_match_position = 0; CheckOriginIsValid(origin); CheckPathIsValid(path); @@ -98,15 +114,21 @@ HttpAuthCache::Entry* HttpAuthCache::LookupByPath(const GURL& origin, // within the protection space ... std::string parent_dir = GetParentDirectory(path); + int entries_examined = 0; // Linear scan through the realm entries. for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { + ++entries_examined; size_t len = 0; if (it->origin() == origin && it->HasEnclosingPath(parent_dir, &len) && (!best_match || len > best_match_length)) { - best_match_length = len; best_match = &(*it); + best_match_length = len; + best_match_position = entries_examined; } } + if (best_match) + best_match->last_use_time_ = base::TimeTicks::Now(); + RecordLookupByPathPosition(best_match_position); return best_match; } @@ -119,20 +141,30 @@ HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin, CheckOriginIsValid(origin); CheckPathIsValid(path); + base::TimeTicks now = base::TimeTicks::Now(); + // Check for existing entry (we will re-use it if present). HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); if (!entry) { + bool evicted = false; // Failsafe to prevent unbounded memory growth of the cache. if (entries_.size() >= kMaxNumRealmEntries) { LOG(WARNING) << "Num auth cache entries reached limit -- evicting"; + UMA_HISTOGRAM_LONG_TIMES("Net.HttpAuthCacheAddEvictedCreation", + now - entries_.back().creation_time_); + UMA_HISTOGRAM_LONG_TIMES("Net.HttpAuthCacheAddEvictedLastUse", + now - entries_.back().last_use_time_); entries_.pop_back(); + evicted = true; } + UMA_HISTOGRAM_BOOLEAN("Net.HttpAuthCacheAddEvicted", evicted); entries_.push_front(Entry()); entry = &entries_.front(); entry->origin_ = origin; entry->realm_ = realm; entry->scheme_ = scheme; + entry->creation_time_ = now; } DCHECK_EQ(origin, entry->origin_); DCHECK_EQ(realm, entry->realm_); @@ -142,6 +174,7 @@ HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin, entry->credentials_ = credentials; entry->nonce_count_ = 1; entry->AddPath(path); + entry->last_use_time_ = now; return entry; } @@ -166,12 +199,15 @@ void HttpAuthCache::Entry::AddPath(const std::string& path) { // Remove any entries that have been subsumed by the new entry. paths_.remove_if(IsEnclosedBy(parent_dir)); + bool evicted = false; // Failsafe to prevent unbounded memory growth of the cache. if (paths_.size() >= kMaxNumPathsPerRealmEntry) { LOG(WARNING) << "Num path entries for " << origin() << " has grown too large -- evicting"; paths_.pop_back(); + evicted = true; } + UMA_HISTOGRAM_BOOLEAN("Net.HttpAuthCacheAddPathEvicted", evicted); // Add new path. paths_.push_front(parent_dir); @@ -221,6 +257,7 @@ bool HttpAuthCache::UpdateStaleChallenge(const GURL& origin, if (!entry) return false; entry->UpdateStaleChallenge(auth_challenge); + entry->last_use_time_ = base::TimeTicks::Now(); return true; } diff --git a/net/http/http_auth_cache.h b/net/http/http_auth_cache.h index 75b379f..707a571 100644 --- a/net/http/http_auth_cache.h +++ b/net/http/http_auth_cache.h @@ -10,6 +10,7 @@ #include "base/gtest_prod_util.h" #include "base/memory/ref_counted.h" +#include "base/time/time.h" #include "net/base/net_export.h" #include "net/http/http_auth.h" #include "url/gurl.h" @@ -96,6 +97,11 @@ class NET_EXPORT_PRIVATE HttpAuthCache { // List of paths that define the realm's protection space. PathList paths_; + + // Times the entry was created and last used (by looking up, adding a path, + // or updating the challenge.) + base::TimeTicks creation_time_; + base::TimeTicks last_use_time_; }; // Prevent unbounded memory growth. These are safeguards for abuse; it is |