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 | |
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
-rw-r--r-- | base/histogram.cc | 20 | ||||
-rw-r--r-- | base/histogram.h | 7 | ||||
-rw-r--r-- | net/SConscript | 1 | ||||
-rw-r--r-- | net/build/net.vcproj | 8 | ||||
-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 | ||||
-rw-r--r-- | net/net.xcodeproj/project.pbxproj | 6 |
10 files changed, 185 insertions, 17 deletions
diff --git a/base/histogram.cc b/base/histogram.cc index b4dede7..19dcf83 100644 --- a/base/histogram.cc +++ b/base/histogram.cc @@ -99,8 +99,8 @@ void Histogram::WriteAscii(bool graph_it, const std::string& newline, // Calculate space needed to print bucket range numbers. Leave room to print // nearly the largest bucket range without sliding over the histogram. - size_t largest_non_empty_bucket = bucket_count_ - 1; - while (0 == sample_.counts(largest_non_empty_bucket)) { + size_t largest_non_empty_bucket = bucket_count() - 1; + while (0 == snapshot.counts(largest_non_empty_bucket)) { if (0 == largest_non_empty_bucket) break; // All buckets are empty. largest_non_empty_bucket--; @@ -108,7 +108,7 @@ void Histogram::WriteAscii(bool graph_it, const std::string& newline, // Calculate largest print width needed for any of our bucket range displays. size_t print_width = 1; - for (size_t i = 0; i < bucket_count_; ++i) { + for (size_t i = 0; i < bucket_count(); ++i) { if (snapshot.counts(i)) { size_t width = GetAsciiBucketRange(i).size() + 1; if (width > print_width) @@ -119,14 +119,14 @@ void Histogram::WriteAscii(bool graph_it, const std::string& newline, int64 remaining = sample_count; int64 past = 0; // Output the actual histogram graph. - for (size_t i = 0; i < bucket_count_; i++) { + for (size_t i = 0; i < bucket_count(); i++) { Count current = snapshot.counts(i); if (!current && !PrintEmptyBucket(i)) continue; remaining -= current; StringAppendF(output, "%#*s ", print_width, GetAsciiBucketRange(i).c_str()); - if (0 == current && i < bucket_count_ - 1 && 0 == snapshot.counts(i + 1)) { - while (i < bucket_count_ - 1 && 0 == snapshot.counts(i + 1)) + if (0 == current && i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) { + while (i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) i++; output->append("... "); output->append(newline); @@ -159,7 +159,7 @@ void Histogram::Initialize() { if (declared_max_ >= kSampleType_MAX) declared_max_ = kSampleType_MAX - 1; DCHECK(declared_min_ > 0); // We provide underflow bucket. - DCHECK(declared_min_ < declared_max_); + DCHECK(declared_min_ <= declared_max_); DCHECK(1 < bucket_count_); size_t maximal_bucket_count = declared_max_ - declared_min_ + 2; DCHECK(bucket_count_ <= maximal_bucket_count); @@ -275,7 +275,7 @@ void Histogram::SetBucketRange(size_t i, Sample value) { double Histogram::GetPeakBucketSize(const SampleSet& snapshot) const { double max = 0; - for (size_t i = 0; i < bucket_count_ ; i++) { + for (size_t i = 0; i < bucket_count() ; i++) { double current_size = GetBucketSize(snapshot.counts(i), i); if (current_size > max) max = current_size; @@ -322,9 +322,9 @@ void Histogram::WriteAsciiBucketContext(const int64 past, const std::string Histogram::GetAsciiBucketRange(size_t i) const { std::string result; if (kHexRangePrintingFlag & flags_) - StringAppendF(&result, "%#x", ranges_[i]); + StringAppendF(&result, "%#x", ranges(i)); else - StringAppendF(&result, "%d", ranges_[i]); + StringAppendF(&result, "%d", ranges(i)); return result; } diff --git a/base/histogram.h b/base/histogram.h index 678cbf6..a2672e0 100644 --- a/base/histogram.h +++ b/base/histogram.h @@ -177,7 +177,7 @@ class Histogram : public StatsRate { void Add(const SampleSet& other); void Subtract(const SampleSet& other); - private: + protected: // Actual histogram data is stored in buckets, showing the count of values // that fit into each bucket. Counts counts_; @@ -208,6 +208,7 @@ class Histogram : public StatsRate { // 0x1 Currently used to mark this histogram to be recorded by UMA.. // 0x8000 means print ranges in hex. void SetFlags(int flags) { flags_ |= flags; } + void ClearFlags(int flags) { flags_ &= ~flags; } int flags() const { return flags_; } //---------------------------------------------------------------------------- @@ -216,8 +217,8 @@ class Histogram : public StatsRate { const std::string histogram_name() const { return histogram_name_; } Sample declared_min() const { return declared_min_; } Sample declared_max() const { return declared_max_; } - Sample ranges(size_t i) const { return ranges_[i];} - size_t bucket_count() const { return bucket_count_; } + virtual Sample ranges(size_t i) const { return ranges_[i];} + virtual size_t bucket_count() const { return bucket_count_; } // Snapshot the current complete set of sample data. // Override with atomic/locked snapshot if needed. virtual void SnapshotSample(SampleSet* sample) const; diff --git a/net/SConscript b/net/SConscript index 3d4e1c0..25cac7d 100644 --- a/net/SConscript +++ b/net/SConscript @@ -60,6 +60,7 @@ input_files = [ 'disk_cache/mem_rankings.cc', 'disk_cache/rankings.cc', 'disk_cache/stats.cc', + 'disk_cache/stats_histogram.cc', 'disk_cache/trace.cc', 'http/cert_status_cache.cc', 'http/http_cache.cc', diff --git a/net/build/net.vcproj b/net/build/net.vcproj index 19ba8fc..68703cd 100644 --- a/net/build/net.vcproj +++ b/net/build/net.vcproj @@ -897,6 +897,14 @@ > </File> <File + RelativePath="..\disk_cache\stats_histogram.cc" + > + </File> + <File + RelativePath="..\disk_cache\stats_histogram.h" + > + </File> + <File RelativePath="..\disk_cache\storage_block-inl.h" > </File> 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_ + diff --git a/net/net.xcodeproj/project.pbxproj b/net/net.xcodeproj/project.pbxproj index c7c9e29e..3309aa3 100644 --- a/net/net.xcodeproj/project.pbxproj +++ b/net/net.xcodeproj/project.pbxproj @@ -132,6 +132,7 @@ 82ECB3090E5B651D00A913E3 /* mime_sniffer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32AD0E5A181C00A747DB /* mime_sniffer.cc */; }; B5F622260E805FC40076681A /* url_request_job_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33A30E5A198600A747DB /* url_request_job_manager.cc */; }; BAA46E3B0E5CE99A00E77460 /* net_util_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED329F0E5A181C00A747DB /* net_util_unittest.cc */; }; + DFEE18270E882E3600666107 /* stats_histogram.cc in Sources */ = {isa = PBXBuildFile; fileRef = DFEE18250E882E3600666107 /* stats_histogram.cc */; }; E47E933F0E8924DC00CA613E /* tcp_client_socket_libevent.cc in Sources */ = {isa = PBXBuildFile; fileRef = E47E933E0E8924DC00CA613E /* tcp_client_socket_libevent.cc */; }; E47E93430E8924EE00CA613E /* tcp_client_socket_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED328E0E5A181C00A747DB /* tcp_client_socket_unittest.cc */; }; E49DD2EA0E892F8C003C7A87 /* sdch_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = E49DD2E80E892F8C003C7A87 /* sdch_manager.cc */; }; @@ -604,6 +605,8 @@ E49DD3360E8933A2003C7A87 /* proxy_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = proxy_service.cc; path = proxy/proxy_service.cc; sourceTree = "<group>"; }; E49DD33A0E8933C0003C7A87 /* proxy_resolver_fixed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = proxy_resolver_fixed.h; path = proxy/proxy_resolver_fixed.h; sourceTree = "<group>"; }; E49DD33B0E8933C0003C7A87 /* proxy_resolver_fixed.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = proxy_resolver_fixed.cc; path = proxy/proxy_resolver_fixed.cc; sourceTree = "<group>"; }; + DFEE18250E882E3600666107 /* stats_histogram.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stats_histogram.cc; sourceTree = "<group>"; }; + DFEE18260E882E3600666107 /* stats_histogram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stats_histogram.h; sourceTree = "<group>"; }; E4AFA6230E523E2900201347 /* net_unittests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = net_unittests; sourceTree = BUILT_PRODUCTS_DIR; }; E4AFA62E0E5240A300201347 /* gtest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = gtest.xcodeproj; path = testing/gtest.xcodeproj; sourceTree = "<group>"; }; E4AFA6420E5241B400201347 /* run_all_unittests.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = run_all_unittests.cc; sourceTree = "<group>"; }; @@ -942,6 +945,8 @@ 7BED32DB0E5A190600A747DB /* rankings.h */, 7BED32DA0E5A190600A747DB /* stats.cc */, 7BED33020E5A190600A747DB /* stats.h */, + DFEE18250E882E3600666107 /* stats_histogram.cc */, + DFEE18260E882E3600666107 /* stats_histogram.h */, 7BED33010E5A190600A747DB /* storage_block-inl.h */, 7BED33000E5A190600A747DB /* storage_block.h */, 7BED32D90E5A190600A747DB /* storage_block_unittest.cc */, @@ -1368,6 +1373,7 @@ 821F20A50E5CD414003C7E38 /* url_request_view_cache_job.cc in Sources */, 82113BBD0E892E5800E3848F /* x509_certificate.cc in Sources */, 827E139D0E81611D00183614 /* x509_certificate_mac.cc in Sources */, + DFEE18270E882E3600666107 /* stats_histogram.cc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |