summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/SConscript1
-rw-r--r--net/build/net.vcproj8
-rw-r--r--net/disk_cache/backend_impl.cc9
-rw-r--r--net/disk_cache/stats.cc33
-rw-r--r--net/disk_cache/stats.h16
-rw-r--r--net/disk_cache/stats_histogram.cc56
-rw-r--r--net/disk_cache/stats_histogram.h46
-rw-r--r--net/net.xcodeproj/project.pbxproj6
8 files changed, 171 insertions, 4 deletions
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;
};