diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-24 23:51:25 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-24 23:51:25 +0000 |
commit | e2951cf3bd7e591a64ad5199a61531dac0ec58d2 (patch) | |
tree | 3039f816f6fa46008865c1ce4b1dd15de7b48d5a /net/disk_cache | |
parent | 0e8db94aef1b57355c3d154cb4682ce2f94c51eb (diff) | |
download | chromium_src-e2951cf3bd7e591a64ad5199a61531dac0ec58d2.zip chromium_src-e2951cf3bd7e591a64ad5199a61531dac0ec58d2.tar.gz chromium_src-e2951cf3bd7e591a64ad5199a61531dac0ec58d2.tar.bz2 |
Use histograms to send interesting parts of the disk cache statistics.
Most of this CL deals with a derived implementation of histograms that just
queries the size stats already generated by the disk cache. The exact number
of buckets, and their distribution, is controlled directly by the new class and
the disk cache stats code.
Review URL: http://codereview.chromium.org/3069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/stats.cc | 33 | ||||
-rw-r--r-- | net/disk_cache/stats.h | 16 | ||||
-rw-r--r-- | net/disk_cache/stats_histogram.cc | 56 | ||||
-rw-r--r-- | net/disk_cache/stats_histogram.h | 46 |
5 files changed, 156 insertions, 4 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 05d017a..c0fa867 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -676,6 +676,15 @@ void BackendImpl::OnStatsTimer() { current /= time; stats_.SetCounter(Stats::OPEN_ENTRIES, current); stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); + + static bool first_time = true; + if (first_time) { + first_time = false; + UMA_HISTOGRAM_COUNTS(L"DiskCache.Entries", data_->header.num_entries); + UMA_HISTOGRAM_COUNTS(L"DiskCache.Size", + data_->header.num_bytes / (1024 * 1024)); + UMA_HISTOGRAM_COUNTS(L"DiskCache.MaxSize", max_size_ / (1024 * 1024)); + } } void BackendImpl::IncrementIoCount() { diff --git a/net/disk_cache/stats.cc b/net/disk_cache/stats.cc index d57a0bb..83448d5 100644 --- a/net/disk_cache/stats.cc +++ b/net/disk_cache/stats.cc @@ -120,6 +120,8 @@ bool Stats::Init(BackendImpl* backend, uint32* storage_addr) { storage_addr_ = address.value(); backend_ = backend; + size_histogram_.reset(new StatsHistogram(L"DiskCache.SizeStats")); + size_histogram_->Init(this); memcpy(data_sizes_, stats.data_sizes, sizeof(data_sizes_)); memcpy(counters_, stats.counters, sizeof(counters_)); @@ -184,6 +186,37 @@ int Stats::GetStatsBucket(int32 size) { return result; } +int Stats::GetBucketRange(size_t i) const { + if (i < 2) + return static_cast<int>(1024 * i); + + if (i < 12) + return static_cast<int>(2048 * (i - 1)); + + if (i < 17) + return static_cast<int>(4096 * (i - 11)) + 20 * 1024; + + int n = 64 * 1024; + if (i > static_cast<size_t>(kDataSizesLength)) { + NOTREACHED(); + i = kDataSizesLength; + } + + i -= 17; + n <<= i; + return n; +} + +void Stats::Snapshot(StatsHistogram::StatsSamples* samples) const { + samples->GetCounts()->resize(kDataSizesLength); + for (int i = 0; i < kDataSizesLength; i++) { + int count = data_sizes_[i]; + if (count < 0) + count = 0; + samples->GetCounts()->at(i) = count; + } +} + void Stats::ModifyStorageStats(int32 old_size, int32 new_size) { // We keep a counter of the data block size on an array where each entry is // the adjusted log base 2 of the size. The first entry counts blocks of 256 diff --git a/net/disk_cache/stats.h b/net/disk_cache/stats.h index 24f99bc..a811e3f 100644 --- a/net/disk_cache/stats.h +++ b/net/disk_cache/stats.h @@ -2,13 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_DISK_CACHE_STATS_H__ -#define NET_DISK_CACHE_STATS_H__ +#ifndef NET_DISK_CACHE_STATS_H_ +#define NET_DISK_CACHE_STATS_H_ #include <string> #include <vector> #include "base/basictypes.h" +#include "base/scoped_ptr.h" +#include "net/disk_cache/stats_histogram.h" namespace disk_cache { @@ -57,6 +59,11 @@ class Stats { void GetItems(StatsItems* items); + // Support for StatsHistograms. Together, these methods allow StatsHistograms + // to take a snapshot of the data_sizes_ as the histogram data. + int GetBucketRange(size_t i) const; + void Snapshot(StatsHistogram::StatsSamples* samples) const; + private: int GetStatsBucket(int32 size); @@ -64,11 +71,12 @@ class Stats { uint32 storage_addr_; int data_sizes_[kDataSizesLength]; int64 counters_[MAX_COUNTER]; + scoped_ptr<StatsHistogram> size_histogram_; - DISALLOW_EVIL_CONSTRUCTORS(Stats); + DISALLOW_COPY_AND_ASSIGN(Stats); }; } // namespace disk_cache -#endif // NET_DISK_CACHE_STATS_H__ +#endif // NET_DISK_CACHE_STATS_H_ diff --git a/net/disk_cache/stats_histogram.cc b/net/disk_cache/stats_histogram.cc new file mode 100644 index 0000000..d396f69 --- /dev/null +++ b/net/disk_cache/stats_histogram.cc @@ -0,0 +1,56 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/disk_cache/stats_histogram.h" + +#include "base/logging.h" +#include "net/disk_cache/stats.h" + +namespace disk_cache { + +// Static. +const Stats* StatsHistogram::stats_ = NULL; + +bool StatsHistogram::Init(const Stats* stats) { + DCHECK(stats); + if (stats_) + return false; + + SetFlags(kUmaTargetedHistogramFlag); + + // We support statistics report for only one cache. + init_ = true; + stats_ = stats; + return true; +} + +StatsHistogram::~StatsHistogram() { + // Only cleanup what we set. + if (init_) + stats_ = NULL; +} + +Histogram::Sample StatsHistogram::ranges(size_t i) const { + DCHECK(stats_); + return stats_->GetBucketRange(i); +} + +size_t StatsHistogram::bucket_count() const { + return disk_cache::Stats::kDataSizesLength; +} + +void StatsHistogram::SnapshotSample(SampleSet* sample) const { + DCHECK(stats_); + StatsSamples my_sample; + stats_->Snapshot(&my_sample); + + *sample = my_sample; + + // Only report UMA data once. + StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); + mutable_me->ClearFlags(kUmaTargetedHistogramFlag); +} + +} // namespace disk_cache + diff --git a/net/disk_cache/stats_histogram.h b/net/disk_cache/stats_histogram.h new file mode 100644 index 0000000..4dd76cc --- /dev/null +++ b/net/disk_cache/stats_histogram.h @@ -0,0 +1,46 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_DISK_CACHE_STATS_HISTOGRAM_H_ +#define NET_DISK_CACHE_STATS_HISTOGRAM_H_ + +#include "base/histogram.h" + +namespace disk_cache { + +class Stats; + +// This class provides support for sending the disk cache size stats as a UMA +// histogram. We'll provide our own storage and management for the data, and a +// SampleSet with a copy of our data. +class StatsHistogram : public Histogram { + public: + class StatsSamples : public SampleSet { + public: + Counts* GetCounts() { + return &counts_; + } + }; + + explicit StatsHistogram(const wchar_t* name) + : Histogram(name, 1, 1, 2), init_(false) {} + ~StatsHistogram(); + + // We'll be reporting data from the given set of cache stats. + bool Init(const Stats* stats); + + virtual Sample ranges(size_t i) const; + virtual size_t bucket_count() const; + virtual void SnapshotSample(SampleSet* sample) const; + + private: + bool init_; + static const Stats* stats_; + DISALLOW_COPY_AND_ASSIGN(StatsHistogram); +}; + +} // namespace disk_cache + +#endif // NET_DISK_CACHE_STATS_HISTOGRAM_H_ + |