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

Unified Diff: net/http/disk_based_cert_cache.cc

Issue 378063002: Adding cache hit/miss histograms to DiskBasedCertCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DBCC_MRU_Implement
Patch Set: Corruption no longer counted as a DiskCache hit, now counted separately. Created 6 years, 5 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: net/http/disk_based_cert_cache.cc
diff --git a/net/http/disk_based_cert_cache.cc b/net/http/disk_based_cert_cache.cc
index 606407999e65eb9339f67504aca2f1fb924573bf..c8370c93a40e3f26dc97826393dc89d5de9e3f85 100644
--- a/net/http/disk_based_cert_cache.cc
+++ b/net/http/disk_based_cert_cache.cc
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/memory/ref_counted.h"
+#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "net/base/io_buffer.h"
@@ -24,7 +25,8 @@ const size_t kMemoryCacheMaxSize = 30;
// Used to obtain a unique cache key for a certificate in the form of
// "cert:<hash>".
-std::string GetCacheKeyToCert(const X509Certificate::OSCertHandle cert_handle) {
+std::string GetCacheKeyForCert(
+ const X509Certificate::OSCertHandle cert_handle) {
SHA1HashValue fingerprint =
X509Certificate::CalculateFingerprint(cert_handle);
@@ -32,6 +34,20 @@ std::string GetCacheKeyToCert(const X509Certificate::OSCertHandle cert_handle) {
base::HexEncode(fingerprint.data, arraysize(fingerprint.data));
}
+enum CacheResult {
+ MEMORY_CACHE_HIT = 0,
+ DISK_CACHE_HIT,
+ DISK_CACHE_CORRUPT,
+ CACHE_MISS,
+ CACHE_ERROR,
wtc 2014/07/10 18:21:38 Nit: without looking at the source code, the meani
+ CACHE_RESULT_MAX
+};
+
+void RecordCacheResult(CacheResult result) {
+ UMA_HISTOGRAM_ENUMERATION(
+ "DiskBasedCertCache.CertIoCacheResult", result, CACHE_RESULT_MAX);
+}
+
} // namespace
// WriteWorkers represent pending Set jobs in the DiskBasedCertCache. Each
@@ -123,7 +139,8 @@ DiskBasedCertCache::WriteWorker::WriteWorker(
}
DiskBasedCertCache::WriteWorker::~WriteWorker() {
- X509Certificate::FreeOSCertHandle(cert_handle_);
+ if (cert_handle_)
+ X509Certificate::FreeOSCertHandle(cert_handle_);
if (entry_)
entry_->Close();
}
@@ -428,8 +445,12 @@ int DiskBasedCertCache::ReadWorker::DoOpen() {
}
int DiskBasedCertCache::ReadWorker::DoOpenComplete(int rv) {
- if (rv < 0)
+ if (rv < 0) {
+ // Errors other than ERR_CACHE_MISS are not recorded as either a hit
+ // or a miss.
+ RecordCacheResult(rv == ERR_CACHE_MISS ? CACHE_MISS : CACHE_ERROR);
return rv;
+ }
state_ = STATE_READ;
return OK;
@@ -449,9 +470,12 @@ int DiskBasedCertCache::ReadWorker::DoReadComplete(int rv) {
cert_handle_ = X509Certificate::CreateOSCertHandleFromBytes(buffer_->data(),
io_buf_len_);
- if (!cert_handle_)
+ if (!cert_handle_) {
+ RecordCacheResult(DISK_CACHE_CORRUPT);
wtc 2014/07/10 18:21:38 This enum value should be named so it's clear only
return ERR_FAILED;
+ }
+ RecordCacheResult(DISK_CACHE_HIT);
return OK;
}
@@ -506,6 +530,7 @@ void DiskBasedCertCache::Get(const std::string& key, const GetCallback& cb) {
// list in the MRU cache.
MRUCertCache::iterator mru_it = mru_cert_cache_.Get(key);
if (mru_it != mru_cert_cache_.end()) {
+ RecordCacheResult(MEMORY_CACHE_HIT);
++mem_cache_hits_;
cb.Run(mru_it->second);
return;
@@ -533,7 +558,7 @@ void DiskBasedCertCache::Set(const X509Certificate::OSCertHandle cert_handle,
const SetCallback& cb) {
DCHECK(!cb.is_null());
DCHECK(cert_handle);
- std::string key = GetCacheKeyToCert(cert_handle);
+ std::string key = GetCacheKeyForCert(cert_handle);
WriteWorkerMap::iterator it = write_worker_map_.find(key);

Powered by Google App Engine
This is Rietveld 408576698