summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 01:25:06 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 01:25:06 +0000
commit761d342a5307a6b858a3bfd2feaa14eb4d9830ce (patch)
treee245a933e168c61cbb1af1d6d6883421080e084d
parent952a078a76e9f8c22cc43d5ce47c5c83e2f8e772 (diff)
downloadchromium_src-761d342a5307a6b858a3bfd2feaa14eb4d9830ce.zip
chromium_src-761d342a5307a6b858a3bfd2feaa14eb4d9830ce.tar.gz
chromium_src-761d342a5307a6b858a3bfd2feaa14eb4d9830ce.tar.bz2
Disk cache: Add a few more histograms and stats to figure
out why there are so many users with available cache space. BUG=none TEST=none Review URL: http://codereview.chromium.org/6020008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70575 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/disk_cache/backend_impl.cc51
-rw-r--r--net/disk_cache/backend_impl.h2
-rw-r--r--net/disk_cache/backend_unittest.cc2
-rw-r--r--net/disk_cache/stats.cc11
-rw-r--r--net/disk_cache/stats.h1
5 files changed, 45 insertions, 22 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 96ef7b01..58a6e9e 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -667,16 +667,15 @@ int BackendImpl::SyncDoomEntry(const std::string& key) {
int BackendImpl::SyncDoomAllEntries() {
// This is not really an error, but it is an interesting condition.
ReportError(ERR_CACHE_DOOMED);
+ stats_.OnEvent(Stats::DOOM_CACHE);
if (!num_refs_) {
- PrepareForRestart();
- DeleteCache(path_, false);
- return SyncInit();
+ RestartCache(false);
+ return disabled_ ? net::ERR_FAILED : net::OK;
} else {
if (disabled_)
return net::ERR_FAILED;
eviction_.TrimCache(true);
- stats_.OnEvent(Stats::DOOM_CACHE);
return net::OK;
}
}
@@ -725,6 +724,7 @@ int BackendImpl::SyncDoomEntriesSince(const base::Time initial_time) {
if (disabled_)
return net::ERR_FAILED;
+ stats_.OnEvent(Stats::DOOM_RECENT);
for (;;) {
void* iter = NULL;
EntryImpl* entry = OpenNextEntryImpl(&iter);
@@ -1178,6 +1178,7 @@ void BackendImpl::CriticalError(int error) {
if (disabled_)
return;
+ stats_.OnEvent(Stats::FATAL_ERROR);
LogStats();
ReportError(error);
@@ -1188,7 +1189,7 @@ void BackendImpl::CriticalError(int error) {
if (!num_refs_)
MessageLoop::current()->PostTask(FROM_HERE,
- factory_.NewRunnableMethod(&BackendImpl::RestartCache));
+ factory_.NewRunnableMethod(&BackendImpl::RestartCache, true));
}
void BackendImpl::ReportError(int error) {
@@ -1439,22 +1440,29 @@ void BackendImpl::AdjustMaxCacheSize(int table_len) {
max_size_= current_max_size;
}
-// We always execute this method from the message loop so that we can freely
-// release files, memory pointers etc.
-void BackendImpl::RestartCache() {
- DCHECK(!num_refs_);
- DCHECK(!open_entries_.size());
- PrepareForRestart();
- DelayedCacheCleanup(path_);
-
+void BackendImpl::RestartCache(bool failure) {
int64 errors = stats_.GetCounter(Stats::FATAL_ERROR);
+ int64 full_dooms = stats_.GetCounter(Stats::DOOM_CACHE);
+ int64 partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT);
+
+ PrepareForRestart();
+ if (failure) {
+ DCHECK(!num_refs_);
+ DCHECK(!open_entries_.size());
+ DelayedCacheCleanup(path_);
+ } else {
+ DeleteCache(path_, false);
+ }
// Don't call Init() if directed by the unit test: we are simulating a failure
// trying to re-enable the cache.
if (unit_test_)
init_ = true; // Let the destructor do proper cleanup.
- else if (SyncInit())
- stats_.SetCounter(Stats::FATAL_ERROR, errors + 1);
+ else if (SyncInit() == net::OK) {
+ stats_.SetCounter(Stats::FATAL_ERROR, errors);
+ stats_.SetCounter(Stats::DOOM_CACHE, full_dooms);
+ stats_.SetCounter(Stats::DOOM_RECENT, partial_dooms);
+ }
}
void BackendImpl::PrepareForRestart() {
@@ -1465,6 +1473,7 @@ void BackendImpl::PrepareForRestart() {
if (!(user_flags_ & kNewEviction))
new_eviction_ = false;
+ disabled_ = true;
data_->header.crash = 0;
index_ = NULL;
data_ = NULL;
@@ -1827,7 +1836,7 @@ void BackendImpl::DecreaseNumRefs() {
if (!num_refs_ && disabled_)
MessageLoop::current()->PostTask(FROM_HERE,
- factory_.NewRunnableMethod(&BackendImpl::RestartCache));
+ factory_.NewRunnableMethod(&BackendImpl::RestartCache, true));
}
void BackendImpl::IncreaseNumEntries() {
@@ -1868,18 +1877,26 @@ void BackendImpl::ReportStats() {
static_cast<int>(stats_.GetCounter(Stats::MAX_ENTRIES)));
stats_.SetCounter(Stats::MAX_ENTRIES, 0);
+ CACHE_UMA(COUNTS_10000, "TotalFatalErrors", 0,
+ static_cast<int>(stats_.GetCounter(Stats::FATAL_ERROR)));
+ CACHE_UMA(COUNTS_10000, "TotalDoomCache", 0,
+ static_cast<int>(stats_.GetCounter(Stats::DOOM_CACHE)));
+ CACHE_UMA(COUNTS_10000, "TotalDoomRecentEntries", 0,
+ static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT)));
+
+ int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120;
if (!data_->header.create_time || !data_->header.lru.filled) {
int cause = data_->header.create_time ? 0 : 1;
if (!data_->header.lru.filled)
cause |= 2;
CACHE_UMA(CACHE_ERROR, "ShortReport", 0, cause);
+ CACHE_UMA(HOURS, "TotalTimeNotFull", 0, static_cast<int>(total_hours));
return;
}
// This is an up to date client that will report FirstEviction() data. After
// that event, start reporting this:
- int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120;
CACHE_UMA(HOURS, "TotalTime", 0, static_cast<int>(total_hours));
int64 use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120;
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 05e5016..5637fbd 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -265,7 +265,7 @@ class BackendImpl : public Backend {
void AdjustMaxCacheSize(int table_len);
// Deletes the cache and starts again.
- void RestartCache();
+ void RestartCache(bool failure);
void PrepareForRestart();
// Creates a new entry object and checks to see if it is dirty. Returns zero
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 4703460..9077996 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -226,7 +226,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
TEST_F(DiskCacheBackendTest, ExternalFiles) {
InitCache();
- // First, lets create a file on the folder.
+ // First, let's create a file on the folder.
FilePath filename = GetCacheFilePath().AppendASCII("f_000001");
const int kSize = 50;
diff --git a/net/disk_cache/stats.cc b/net/disk_cache/stats.cc
index f0446fb..5222112 100644
--- a/net/disk_cache/stats.cc
+++ b/net/disk_cache/stats.cc
@@ -20,6 +20,7 @@ struct OnDiskStats {
int data_sizes[disk_cache::Stats::kDataSizesLength];
int64 counters[disk_cache::Stats::MAX_COUNTER];
};
+COMPILE_ASSERT(sizeof(OnDiskStats) < 512, needs_more_than_2_blocks);
// Returns the "floor" (as opposed to "ceiling") of log base 2 of number.
int LogBase2(int32 number) {
@@ -37,6 +38,7 @@ int LogBase2(int32 number) {
return static_cast<int>(result);
}
+// WARNING: Add new stats only at the end, or change LoadStats().
static const char* kCounterNames[] = {
"Open miss",
"Open hit",
@@ -57,7 +59,8 @@ static const char* kCounterNames[] = {
"Get rankings",
"Fatal error",
"Last report",
- "Last report timer"
+ "Last report timer",
+ "Doom recent entries"
};
COMPILE_ASSERT(arraysize(kCounterNames) == disk_cache::Stats::MAX_COUNTER,
update_the_names);
@@ -73,6 +76,7 @@ bool LoadStats(BackendImpl* backend, Addr address, OnDiskStats* stats) {
size_t offset = address.start_block() * address.BlockSize() +
kBlockHeaderSize;
+ memset(stats, 0, sizeof(*stats));
if (!file->Read(stats, sizeof(*stats), offset))
return false;
@@ -80,9 +84,10 @@ bool LoadStats(BackendImpl* backend, Addr address, OnDiskStats* stats) {
return false;
// We don't want to discard the whole cache every time we have one extra
- // counter; just reset them to zero.
- if (stats->size != sizeof(*stats))
+ // counter; we keep old data if we can.
+ if (static_cast<unsigned int>(stats->size) > sizeof(*stats)) {
memset(stats, 0, sizeof(*stats));
+ }
return true;
}
diff --git a/net/disk_cache/stats.h b/net/disk_cache/stats.h
index 3042590..ebf0bc21 100644
--- a/net/disk_cache/stats.h
+++ b/net/disk_cache/stats.h
@@ -45,6 +45,7 @@ class Stats {
FATAL_ERROR,
LAST_REPORT, // Time of the last time we sent a report.
LAST_REPORT_TIMER, // Timer count of the last time we sent a report.
+ DOOM_RECENT, // The cache was partially cleared.
MAX_COUNTER
};