Commit a3cfbfaa authored by rvargas@chromium.org's avatar rvargas@chromium.org

Disk cache: Remove stats_histogram.

StatsHistograms is the only "external" subclass of base::Histogram and as such
it often requires extra considerations when modifying the base class. On the
other hand, almost the same data can be gathered by using a regular log
histogram with a specific range.

This CL does that, generating a 75 bucket histogram to map the 27 buckets
from the original data. Most of the buckets will be empty, and a couple of
buckets will be merged on the new histogram, but the compromise looks
good enough.

BUG=377936

Review URL: https://codereview.chromium.org/295913014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273074 0039d316-1c4b-4281-b951-d872f2087c98
parent ae2477e9
......@@ -11,6 +11,8 @@
#ifndef NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_H_
#define NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_H_
#include "base/metrics/histogram.h"
// -----------------------------------------------------------------------------
// These histograms follow the definition of UMA_HISTOGRAMN_XXX except that
......
......@@ -6,7 +6,11 @@
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/metrics/bucket_ranges.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/sample_vector.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
......@@ -88,13 +92,10 @@ bool VerifyStats(OnDiskStats* stats) {
return true;
}
Stats::Stats() : size_histogram_(NULL) {
Stats::Stats() {
}
Stats::~Stats() {
if (size_histogram_) {
size_histogram_->Disable();
}
}
bool Stats::Init(void* data, int num_bytes, Addr address) {
......@@ -123,17 +124,32 @@ bool Stats::Init(void* data, int num_bytes, Addr address) {
}
void Stats::InitSizeHistogram() {
// It seems impossible to support this histogram for more than one
// simultaneous objects with the current infrastructure.
// Only generate this histogram for the main cache.
static bool first_time = true;
if (first_time) {
first_time = false;
if (!size_histogram_) {
// 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", this);
}
if (!first_time)
return;
first_time = false;
int min = 1;
int max = 64 * 1024;
int num_buckets = 75;
base::BucketRanges ranges(num_buckets + 1);
base::Histogram::InitializeBucketRanges(min, max, &ranges);
base::HistogramBase* stats_histogram = base::Histogram::FactoryGet(
"DiskCache.SizeStats2", min, max, num_buckets,
base::HistogramBase::kUmaTargetedHistogramFlag);
base::SampleVector samples(&ranges);
for (int i = 0; i < kDataSizesLength; i++) {
// This is a good time to fix any inconsistent data. The count should be
// always positive, but if it's not, reset the value now.
if (data_sizes_[i] < 0)
data_sizes_[i] = 0;
samples.Accumulate(GetBucketRange(i) / 1024, data_sizes_[i]);
}
stats_histogram->AddSamples(samples);
}
int Stats::StorageSize() {
......@@ -248,15 +264,6 @@ int Stats::GetBucketRange(size_t i) const {
return n;
}
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->Accumulate(GetBucketRange(i), count);
}
}
// The array will be filled this way:
// index size
// 0 [0, 1024)
......
......@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "net/disk_cache/blockfile/addr.h"
#include "net/disk_cache/blockfile/stats_histogram.h"
namespace base {
class HistogramSamples;
......@@ -83,19 +82,15 @@ class Stats {
// Returns the number of bytes copied.
int SerializeStats(void* data, int num_bytes, Addr* address);
// 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(base::HistogramSamples* samples) const;
private:
// Supports generation of SizeStats histogram data.
int GetBucketRange(size_t i) const;
int GetStatsBucket(int32 size);
int GetRatio(Counters hit, Counters miss) const;
Addr storage_addr_;
int data_sizes_[kDataSizesLength];
int64 counters_[MAX_COUNTER];
StatsHistogram* size_histogram_;
DISALLOW_COPY_AND_ASSIGN(Stats);
};
......
// Copyright (c) 2012 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/blockfile/stats_histogram.h"
#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/blockfile/stats.h"
namespace disk_cache {
using base::BucketRanges;
using base::Histogram;
using base::HistogramSamples;
using base::SampleVector;
using base::StatisticsRecorder;
StatsHistogram::StatsHistogram(const std::string& name,
Sample minimum,
Sample maximum,
const BucketRanges* ranges,
const Stats* stats)
: Histogram(name, minimum, maximum, 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,
const Stats* stats) {
Sample minimum = 1;
Sample maximum = disk_cache::Stats::kDataSizesLength - 1;
size_t bucket_count = disk_cache::Stats::kDataSizesLength;
HistogramBase* 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, registered_ranges, stats);
stats_histogram->SetFlags(kUmaTargetedHistogramFlag);
histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(stats_histogram);
}
DCHECK(base::HISTOGRAM == histogram->GetHistogramType());
DCHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count));
// We're preparing for an otherwise unsafe upcast by ensuring we have the
// proper class type.
StatsHistogram* return_histogram = static_cast<StatsHistogram*>(histogram);
return return_histogram;
}
void StatsHistogram::Disable() {
stats_ = NULL;
}
scoped_ptr<HistogramSamples> StatsHistogram::SnapshotSamples() const {
scoped_ptr<SampleVector> samples(new SampleVector(bucket_ranges()));
if (stats_)
stats_->Snapshot(samples.get());
// Only report UMA data once.
StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this);
mutable_me->ClearFlags(kUmaTargetedHistogramFlag);
return samples.PassAs<HistogramSamples>();
}
int StatsHistogram::FindCorruption(const HistogramSamples& samples) const {
// This class won't monitor inconsistencies.
return HistogramBase::NO_INCONSISTENCIES;
}
} // namespace disk_cache
// Copyright (c) 2012 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_BLOCKFILE_STATS_HISTOGRAM_H_
#define NET_DISK_CACHE_BLOCKFILE_STATS_HISTOGRAM_H_
#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
// 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:
StatsHistogram(const std::string& name,
Sample minimum,
Sample maximum,
const base::BucketRanges* ranges,
const Stats* stats);
virtual ~StatsHistogram();
static void InitializeBucketRanges(const Stats* stats,
base::BucketRanges* ranges);
static StatsHistogram* FactoryGet(const std::string& name,
const Stats* stats);
// Disables this histogram when the underlying Stats go away.
void Disable();
virtual scoped_ptr<base::HistogramSamples> SnapshotSamples() const OVERRIDE;
virtual int FindCorruption(
const base::HistogramSamples& samples) const OVERRIDE;
private:
const Stats* stats_;
DISALLOW_COPY_AND_ASSIGN(StatsHistogram);
};
} // namespace disk_cache
#endif // NET_DISK_CACHE_BLOCKFILE_STATS_HISTOGRAM_H_
......@@ -420,8 +420,6 @@
'disk_cache/blockfile/sparse_control.h',
'disk_cache/blockfile/stats.cc',
'disk_cache/blockfile/stats.h',
'disk_cache/blockfile/stats_histogram.cc',
'disk_cache/blockfile/stats_histogram.h',
'disk_cache/blockfile/storage_block-inl.h',
'disk_cache/blockfile/storage_block.h',
'disk_cache/blockfile/stress_support.h',
......
......@@ -3371,6 +3371,11 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<summary>The age of the cache's files (wall time). ShaderCache.</summary>
</histogram>
<histogram name="DiskCache.SizeStats2" units="kilobytes">
<owner>rvargas@chromium.org</owner>
<summary>The size distribution of data stored in the HTTP cache.</summary>
</histogram>
<histogram name="DiskCache.TotalIOTime" units="milliseconds">
<obsolete>
Deprecated.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment