summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-22 03:42:12 +0000
committerkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-22 03:42:12 +0000
commit2f7d9cdf62cb6729838a9c67e1a6efea7c739302 (patch)
tree01b27817539910ecffacfceb0f3b27b6d7deb092 /net/disk_cache
parent00b8ae882e96f41c41c27d3070897f02dd75d30b (diff)
downloadchromium_src-2f7d9cdf62cb6729838a9c67e1a6efea7c739302.zip
chromium_src-2f7d9cdf62cb6729838a9c67e1a6efea7c739302.tar.gz
chromium_src-2f7d9cdf62cb6729838a9c67e1a6efea7c739302.tar.bz2
SampleSet -> HistogramSamples which can be reused by SparseHistogram
BUG=139612 Review URL: https://chromiumcodereview.appspot.com/10829466 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/stats.cc10
-rw-r--r--net/disk_cache/stats.h6
-rw-r--r--net/disk_cache/stats_histogram.cc79
-rw-r--r--net/disk_cache/stats_histogram.h38
4 files changed, 69 insertions, 64 deletions
diff --git a/net/disk_cache/stats.cc b/net/disk_cache/stats.cc
index af3b941..62d228c 100644
--- a/net/disk_cache/stats.cc
+++ b/net/disk_cache/stats.cc
@@ -6,6 +6,7 @@
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/metrics/histogram_samples.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "net/disk_cache/backend_impl.h"
@@ -150,9 +151,7 @@ bool Stats::Init(BackendImpl* backend, uint32* storage_addr) {
backend->ShouldReportAgain()) {
// Stats may be reused when the cache is re-created, but we want only one
// histogram at any given time.
- size_histogram_ =
- StatsHistogram::FactoryGet("DiskCache.SizeStats");
- size_histogram_->Init(this);
+ size_histogram_ = StatsHistogram::FactoryGet("DiskCache.SizeStats", this);
}
}
@@ -264,13 +263,12 @@ int Stats::GetBucketRange(size_t i) const {
return n;
}
-void Stats::Snapshot(StatsHistogram::StatsSamples* samples) const {
- samples->GetCounts()->resize(kDataSizesLength);
+void Stats::Snapshot(base::HistogramSamples* samples) const {
for (int i = 0; i < kDataSizesLength; i++) {
int count = data_sizes_[i];
if (count < 0)
count = 0;
- samples->GetCounts()->at(i) = count;
+ samples->Accumulate(GetBucketRange(i), count);
}
}
diff --git a/net/disk_cache/stats.h b/net/disk_cache/stats.h
index 643c832..94b9d68 100644
--- a/net/disk_cache/stats.h
+++ b/net/disk_cache/stats.h
@@ -11,6 +11,10 @@
#include "base/basictypes.h"
#include "net/disk_cache/stats_histogram.h"
+namespace base {
+class HistogramSamples;
+} // namespace base
+
namespace disk_cache {
class BackendImpl;
@@ -74,7 +78,7 @@ class Stats {
// 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;
+ void Snapshot(base::HistogramSamples* samples) const;
private:
int GetStatsBucket(int32 size);
diff --git a/net/disk_cache/stats_histogram.cc b/net/disk_cache/stats_histogram.cc
index d3bab34..6bd7a070 100644
--- a/net/disk_cache/stats_histogram.cc
+++ b/net/disk_cache/stats_histogram.cc
@@ -6,33 +6,59 @@
#include "base/debug/leak_annotations.h"
#include "base/logging.h"
+#include "base/metrics/bucket_ranges.h"
+#include "base/metrics/histogram_base.h"
+#include "base/metrics/sample_vector.h"
#include "base/metrics/statistics_recorder.h"
#include "net/disk_cache/stats.h"
namespace disk_cache {
+using base::BucketRanges;
using base::Histogram;
+using base::HistogramSamples;
+using base::SampleVector;
using base::StatisticsRecorder;
-// Static.
-const Stats* StatsHistogram::stats_ = NULL;
-
-StatsHistogram::~StatsHistogram() {
- // Only cleanup what we set.
- if (init_)
- stats_ = NULL;
+StatsHistogram::StatsHistogram(const std::string& name,
+ Sample minimum,
+ Sample maximum,
+ size_t bucket_count,
+ const BucketRanges* ranges,
+ const Stats* stats)
+ : Histogram(name, minimum, maximum, bucket_count, ranges),
+ stats_(stats) {}
+
+StatsHistogram::~StatsHistogram() {}
+
+// static
+void StatsHistogram::InitializeBucketRanges(const Stats* stats,
+ BucketRanges* ranges) {
+ for (size_t i = 0; i < ranges->size(); i++) {
+ ranges->set_range(i, stats->GetBucketRange(i));
+ }
+ ranges->ResetChecksum();
}
-StatsHistogram* StatsHistogram::FactoryGet(const std::string& name) {
+StatsHistogram* StatsHistogram::FactoryGet(const std::string& name,
+ const Stats* stats) {
Sample minimum = 1;
Sample maximum = disk_cache::Stats::kDataSizesLength - 1;
size_t bucket_count = disk_cache::Stats::kDataSizesLength;
-
Histogram* histogram = StatisticsRecorder::FindHistogram(name);
if (!histogram) {
+ DCHECK(stats);
+
+ // To avoid racy destruction at shutdown, the following will be leaked.
+ BucketRanges* ranges = new BucketRanges(bucket_count + 1);
+ InitializeBucketRanges(stats, ranges);
+ const BucketRanges* registered_ranges =
+ StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
+
// To avoid racy destruction at shutdown, the following will be leaked.
StatsHistogram* stats_histogram =
- new StatsHistogram(name, minimum, maximum, bucket_count);
+ new StatsHistogram(name, minimum, maximum, bucket_count,
+ registered_ranges, stats);
stats_histogram->SetFlags(kUmaTargetedHistogramFlag);
histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(stats_histogram);
}
@@ -46,40 +72,19 @@ StatsHistogram* StatsHistogram::FactoryGet(const std::string& name) {
return return_histogram;
}
-bool StatsHistogram::Init(const Stats* stats) {
- DCHECK(stats);
- if (stats_)
- return false;
-
- // We support statistics report for only one cache.
- init_ = true;
- stats_ = stats;
- return true;
-}
-
-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;
+scoped_ptr<SampleVector> StatsHistogram::SnapshotSamples() const {
+ scoped_ptr<SampleVector> samples(new SampleVector(bucket_ranges()));
+ stats_->Snapshot(samples.get());
// Only report UMA data once.
StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this);
mutable_me->ClearFlags(kUmaTargetedHistogramFlag);
+
+ return samples.Pass();
}
Histogram::Inconsistencies StatsHistogram::FindCorruption(
- const SampleSet& snapshot) const {
+ const HistogramSamples& samples) const {
return NO_INCONSISTENCIES; // This class won't monitor inconsistencies.
}
diff --git a/net/disk_cache/stats_histogram.h b/net/disk_cache/stats_histogram.h
index f3af304..0f7685f 100644
--- a/net/disk_cache/stats_histogram.h
+++ b/net/disk_cache/stats_histogram.h
@@ -7,49 +7,47 @@
#include <string>
+#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
+namespace base {
+class BucketRanges;
+class HistogramSamples;
+class SampleVector;
+} // namespace base
+
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.
+// SampleVector with a copy of our data.
//
// Class derivation of Histogram "deprecated," and should not be copied, and
// may eventually go away.
//
class StatsHistogram : public base::Histogram {
public:
- class StatsSamples : public SampleSet {
- public:
- Counts* GetCounts() {
- return &counts_;
- }
- };
-
StatsHistogram(const std::string& name,
Sample minimum,
Sample maximum,
- size_t bucket_count)
- : Histogram(name, minimum, maximum, bucket_count, NULL), init_(false) {}
+ size_t bucket_count,
+ const base::BucketRanges* ranges,
+ const Stats* stats);
virtual ~StatsHistogram();
- static StatsHistogram* FactoryGet(const std::string& name);
-
- // We'll be reporting data from the given set of cache stats.
- bool Init(const Stats* stats);
+ static void InitializeBucketRanges(const Stats* stats,
+ base::BucketRanges* ranges);
+ static StatsHistogram* FactoryGet(const std::string& name,
+ const Stats* stats);
- virtual Sample ranges(size_t i) const OVERRIDE;
- virtual size_t bucket_count() const OVERRIDE;
- virtual void SnapshotSample(SampleSet* sample) const OVERRIDE;
+ virtual scoped_ptr<base::SampleVector> SnapshotSamples() const OVERRIDE;
virtual Inconsistencies FindCorruption(
- const SampleSet& snapshot) const OVERRIDE;
+ const base::HistogramSamples& samples) const OVERRIDE;
private:
- bool init_;
- static const Stats* stats_;
+ const Stats* stats_;
DISALLOW_COPY_AND_ASSIGN(StatsHistogram);
};