| Index: net/disk_cache/stats_histogram.cc
|
| ===================================================================
|
| --- net/disk_cache/stats_histogram.cc (revision 155400)
|
| +++ net/disk_cache/stats_histogram.cc (working copy)
|
| @@ -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(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() {
|
| - // Only cleanup what we set.
|
| - if (init_)
|
| - stats_ = NULL;
|
| +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 @@
|
| return return_histogram;
|
| }
|
|
|
| -bool StatsHistogram::Init(const Stats* stats) {
|
| - DCHECK(stats);
|
| - if (stats_)
|
| - return false;
|
| +scoped_ptr<SampleVector> StatsHistogram::SnapshotSamples() const {
|
| + scoped_ptr<SampleVector> samples(new SampleVector(bucket_ranges()));
|
| + stats_->Snapshot(samples.get());
|
|
|
| - // 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;
|
| -
|
| // 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.
|
| }
|
|
|
|
|