--- a/ipc/chromium/src/base/histogram.cc
+++ b/ipc/chromium/src/base/histogram.cc
@@ -76,52 +76,42 @@ 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0
0x2d02ef8dL,
};
typedef Histogram::Count Count;
// static
const size_t Histogram::kBucketCount_MAX = 16384u;
-Histogram* Histogram::FactoryGet(const std::string& name,
- Sample minimum,
+Histogram* Histogram::FactoryGet(Sample minimum,
Sample maximum,
size_t bucket_count,
Flags flags) {
Histogram* histogram(NULL);
// Defensive code.
if (minimum < 1)
minimum = 1;
if (maximum > kSampleType_MAX - 1)
maximum = kSampleType_MAX - 1;
- if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
- // Extra variable is not needed... but this keeps this section basically
- // identical to other derived classes in this file (and compiler will
- // optimize away the extra variable.
- Histogram* tentative_histogram =
- new Histogram(name, minimum, maximum, bucket_count);
- tentative_histogram->InitializeBucketRange();
- tentative_histogram->SetFlags(flags);
- histogram =
- StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
- }
+ histogram = new Histogram(minimum, maximum, bucket_count);
+ histogram->InitializeBucketRange();
+ histogram->SetFlags(flags);
DCHECK_EQ(HISTOGRAM, histogram->histogram_type());
DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
return histogram;
}
-Histogram* Histogram::FactoryTimeGet(const std::string& name,
- TimeDelta minimum,
+Histogram* Histogram::FactoryTimeGet(TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
Flags flags) {
- return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
+ return FactoryGet(minimum.InMilliseconds(), maximum.InMilliseconds(),
bucket_count, flags);
}
void Histogram::Add(int value) {
if (value > kSampleType_MAX - 1)
value = kSampleType_MAX - 1;
if (value < 0)
value = 0;
@@ -155,90 +145,16 @@ void Histogram::Clear() {
ss.Resize(*this);
sample_ = ss;
}
void Histogram::SetRangeDescriptions(const DescriptionPair descriptions[]) {
DCHECK(false);
}
-// The following methods provide a graphical histogram display.
-void Histogram::WriteHTMLGraph(std::string* output) const {
- // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc.
- output->append("<PRE>");
- WriteAscii(true, "<br>", output);
- output->append("</PRE>");
-}
-
-void Histogram::WriteAscii(bool graph_it, const std::string& newline,
- std::string* output) const {
- // Get local (stack) copies of all effectively volatile class data so that we
- // are consistent across our output activities.
- SampleSet snapshot;
- SnapshotSample(&snapshot);
-
- Count sample_count = snapshot.TotalCount();
-
- WriteAsciiHeader(snapshot, sample_count, output);
- output->append(newline);
-
- // Prepare to normalize graphical rendering of bucket contents.
- double max_size = 0;
- if (graph_it)
- max_size = GetPeakBucketSize(snapshot);
-
- // 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 == snapshot.counts(largest_non_empty_bucket)) {
- if (0 == largest_non_empty_bucket)
- break; // All buckets are empty.
- --largest_non_empty_bucket;
- }
-
- // 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) {
- if (snapshot.counts(i)) {
- size_t width = GetAsciiBucketRange(i).size() + 1;
- if (width > print_width)
- print_width = width;
- }
- }
-
- int64_t remaining = sample_count;
- int64_t past = 0;
- // Output the actual histogram graph.
- for (size_t i = 0; i < bucket_count(); ++i) {
- Count current = snapshot.counts(i);
- if (!current && !PrintEmptyBucket(i))
- continue;
- remaining -= current;
- std::string range = GetAsciiBucketRange(i);
- output->append(range);
- for (size_t j = 0; range.size() + j < print_width + 1; ++j)
- output->push_back(' ');
- 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);
- continue; // No reason to plot emptiness.
- }
- double current_size = GetBucketSize(current, i);
- if (graph_it)
- WriteAsciiBucketGraph(current_size, max_size, output);
- WriteAsciiBucketContext(past, current, remaining, i, output);
- output->append(newline);
- past += current;
- }
- DCHECK_EQ(sample_count, past);
-}
-
//------------------------------------------------------------------------------
// Methods for the validating a sample and a related histogram.
//------------------------------------------------------------------------------
Histogram::Inconsistencies
Histogram::FindCorruption(const SampleSet& snapshot) const
{
int inconsistencies = NO_INCONSISTENCIES;
@@ -265,22 +181,20 @@ Histogram::FindCorruption(const SampleSe
// we'll catch a redundant count that doesn't match the sample count. We
// allow for a certain amount of slop before flagging this as an
// inconsistency. Even with an inconsistency, we'll snapshot it again (for
// UMA in about a half hour, so we'll eventually get the data, if it was
// not the result of a corruption. If histograms show that 1 is "too tight"
// then we may try to use 2 or 3 for this slop value.
const int kCommonRaceBasedCountMismatch = 1;
if (delta > 0) {
- UMA_HISTOGRAM_COUNTS("Histogram.InconsistentCountHigh", delta);
if (delta > kCommonRaceBasedCountMismatch)
inconsistencies |= COUNT_HIGH_ERROR;
} else {
DCHECK_GT(0, delta);
- UMA_HISTOGRAM_COUNTS("Histogram.InconsistentCountLow", -delta);
if (-delta > kCommonRaceBasedCountMismatch)
inconsistencies |= COUNT_LOW_ERROR;
}
}
return static_cast<Inconsistencies>(inconsistencies);
}
Histogram::ClassType Histogram::histogram_type() const {
@@ -332,51 +246,41 @@ size_t Histogram::SizeOfIncludingThis(mo
size_t
Histogram::SampleSet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
{
// We're not allowed to do deep dives into STL data structures. This
// is as close as we can get to measuring this array.
return aMallocSizeOf(&counts_[0]);
}
-Histogram::Histogram(const std::string& name, Sample minimum,
- Sample maximum, size_t bucket_count)
+Histogram::Histogram(Sample minimum, Sample maximum, size_t bucket_count)
: sample_(),
- histogram_name_(name),
declared_min_(minimum),
declared_max_(maximum),
bucket_count_(bucket_count),
flags_(kNoFlags),
ranges_(bucket_count + 1, 0),
range_checksum_(0),
recording_enabled_(true) {
Initialize();
}
-Histogram::Histogram(const std::string& name, TimeDelta minimum,
- TimeDelta maximum, size_t bucket_count)
+Histogram::Histogram(TimeDelta minimum, TimeDelta maximum, size_t bucket_count)
: sample_(),
- histogram_name_(name),
declared_min_(static_cast<int> (minimum.InMilliseconds())),
declared_max_(static_cast<int> (maximum.InMilliseconds())),
bucket_count_(bucket_count),
flags_(kNoFlags),
ranges_(bucket_count + 1, 0),
range_checksum_(0),
recording_enabled_(true) {
Initialize();
}
Histogram::~Histogram() {
- if (StatisticsRecorder::dump_on_exit()) {
- std::string output;
- WriteAscii(true, "\n", &output);
- CHROMIUM_LOG(INFO) << output;
- }
-
// Just to make sure most derived class did this properly...
DCHECK(ValidateBucketRanges());
}
// Calculate what range of values are held in each bucket.
// We have to be careful that we don't pick a ratio between starting points in
// consecutive buckets that is sooo small, that the integer bounds are the same
// (effectively making one bucket get no values). We need to avoid:
@@ -555,67 +459,16 @@ double Histogram::GetPeakBucketSize(cons
double current_size
= GetBucketSize(snapshot.counts(i), i);
if (current_size > max)
max = current_size;
}
return max;
}
-void Histogram::WriteAsciiHeader(const SampleSet& snapshot,
- Count sample_count,
- std::string* output) const {
- StringAppendF(output,
- "Histogram: %s recorded %d samples",
- histogram_name().c_str(),
- sample_count);
- int64_t snapshot_sum = snapshot.sum();
- if (0 == sample_count) {
- DCHECK_EQ(snapshot_sum, 0);
- } else {
- double average = static_cast<float>(snapshot_sum) / sample_count;
-
- StringAppendF(output, ", average = %.1f", average);
- }
- if (flags_ & ~kHexRangePrintingFlag)
- StringAppendF(output, " (flags = 0x%x)", flags_ & ~kHexRangePrintingFlag);
-}
-
-void Histogram::WriteAsciiBucketContext(const int64_t past,
- const Count current,
- const int64_t remaining,
- const size_t i,
- std::string* output) const {
- double scaled_sum = (past + current + remaining) / 100.0;
- WriteAsciiBucketValue(current, scaled_sum, output);
- if (0 < i) {
- double percentage = past / scaled_sum;
- StringAppendF(output, " {%3.1f%%}", percentage);
- }
-}
-
-void Histogram::WriteAsciiBucketValue(Count current, double scaled_sum,
- std::string* output) const {
- StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
-}
-
-void Histogram::WriteAsciiBucketGraph(double current_size, double max_size,
- std::string* output) const {
- const int k_line_length = 72; // Maximal horizontal width of graph.
- int x_count = static_cast<int>(k_line_length * (current_size / max_size)
- + 0.5);
- int x_remainder = k_line_length - x_count;
-
- while (0 < x_count--)
- output->append("-");
- output->append("O");
- while (0 < x_remainder--)
- output->append(" ");
-}
-
//------------------------------------------------------------------------------
// Methods for the Histogram::SampleSet class
//------------------------------------------------------------------------------
Histogram::SampleSet::SampleSet()
: counts_(),
sum_(0),
redundant_count_(0) {
@@ -660,48 +513,43 @@ void Histogram::SampleSet::Add(const Sam
//------------------------------------------------------------------------------
// LinearHistogram: This histogram uses a traditional set of evenly spaced
// buckets.
//------------------------------------------------------------------------------
LinearHistogram::~LinearHistogram() {
}
-Histogram* LinearHistogram::FactoryGet(const std::string& name,
- Sample minimum,
+Histogram* LinearHistogram::FactoryGet(Sample minimum,
Sample maximum,
size_t bucket_count,
Flags flags) {
Histogram* histogram(NULL);
if (minimum < 1)
minimum = 1;
if (maximum > kSampleType_MAX - 1)
maximum = kSampleType_MAX - 1;
- if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
- LinearHistogram* tentative_histogram =
- new LinearHistogram(name, minimum, maximum, bucket_count);
- tentative_histogram->InitializeBucketRange();
- tentative_histogram->SetFlags(flags);
- histogram =
- StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
- }
+ LinearHistogram* linear_histogram =
+ new LinearHistogram(minimum, maximum, bucket_count);
+ linear_histogram->InitializeBucketRange();
+ linear_histogram->SetFlags(flags);
+ histogram = linear_histogram;
DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type());
DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
return histogram;
}
-Histogram* LinearHistogram::FactoryTimeGet(const std::string& name,
- TimeDelta minimum,
+Histogram* LinearHistogram::FactoryTimeGet(TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
Flags flags) {
- return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
+ return FactoryGet(minimum.InMilliseconds(), maximum.InMilliseconds(),
bucket_count, flags);
}
Histogram::ClassType LinearHistogram::histogram_type() const {
return LINEAR_HISTOGRAM;
}
void LinearHistogram::Accumulate(Sample value, Count count, size_t index) {
@@ -710,28 +558,26 @@ void LinearHistogram::Accumulate(Sample
void LinearHistogram::SetRangeDescriptions(
const DescriptionPair descriptions[]) {
for (int i =0; descriptions[i].description; ++i) {
bucket_description_[descriptions[i].sample] = descriptions[i].description;
}
}
-LinearHistogram::LinearHistogram(const std::string& name,
- Sample minimum,
+LinearHistogram::LinearHistogram(Sample minimum,
Sample maximum,
size_t bucket_count)
- : Histogram(name, minimum >= 1 ? minimum : 1, maximum, bucket_count) {
+ : Histogram(minimum >= 1 ? minimum : 1, maximum, bucket_count) {
}
-LinearHistogram::LinearHistogram(const std::string& name,
- TimeDelta minimum,
+LinearHistogram::LinearHistogram(TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count)
- : Histogram(name, minimum >= TimeDelta::FromMilliseconds(1) ?
+ : Histogram(minimum >= TimeDelta::FromMilliseconds(1) ?
minimum : TimeDelta::FromMilliseconds(1),
maximum, bucket_count) {
}
void LinearHistogram::InitializeBucketRange() {
DCHECK_GT(declared_min(), 0); // 0 is the underflow bucket here.
double min = declared_min();
double max = declared_max();
@@ -764,74 +610,69 @@ bool LinearHistogram::PrintEmptyBucket(s
return bucket_description_.find(ranges(index)) == bucket_description_.end();
}
//------------------------------------------------------------------------------
// This section provides implementation for BooleanHistogram.
//------------------------------------------------------------------------------
-Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) {
+Histogram* BooleanHistogram::FactoryGet(Flags flags) {
Histogram* histogram(NULL);
- if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
- BooleanHistogram* tentative_histogram = new BooleanHistogram(name);
- tentative_histogram->InitializeBucketRange();
- tentative_histogram->SetFlags(flags);
- histogram =
- StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
- }
+ BooleanHistogram* tentative_histogram = new BooleanHistogram();
+ tentative_histogram->InitializeBucketRange();
+ tentative_histogram->SetFlags(flags);
+ histogram = tentative_histogram;
DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type());
return histogram;
}
Histogram::ClassType BooleanHistogram::histogram_type() const {
return BOOLEAN_HISTOGRAM;
}
void BooleanHistogram::AddBoolean(bool value) {
Add(value ? 1 : 0);
}
-BooleanHistogram::BooleanHistogram(const std::string& name)
- : LinearHistogram(name, 1, 2, 3) {
+BooleanHistogram::BooleanHistogram()
+ : LinearHistogram(1, 2, 3) {
}
void
BooleanHistogram::Accumulate(Sample value, Count count, size_t index)
{
// Callers will have computed index based on the non-booleanified value.
// So we need to adjust the index manually.
LinearHistogram::Accumulate(!!value, count, value ? 1 : 0);
}
//------------------------------------------------------------------------------
// FlagHistogram:
//------------------------------------------------------------------------------
Histogram *
-FlagHistogram::FactoryGet(const std::string &name, Flags flags)
+FlagHistogram::FactoryGet(Flags flags)
{
Histogram *h(nullptr);
- if (!StatisticsRecorder::FindHistogram(name, &h)) {
- FlagHistogram *fh = new FlagHistogram(name);
- fh->InitializeBucketRange();
- fh->SetFlags(flags);
- size_t zero_index = fh->BucketIndex(0);
- fh->LinearHistogram::Accumulate(0, 1, zero_index);
- h = StatisticsRecorder::RegisterOrDeleteDuplicate(fh);
- }
+ FlagHistogram *fh = new FlagHistogram();
+ fh->InitializeBucketRange();
+ fh->SetFlags(flags);
+ size_t zero_index = fh->BucketIndex(0);
+ fh->LinearHistogram::Accumulate(0, 1, zero_index);
+ h = fh;
return h;
}
-FlagHistogram::FlagHistogram(const std::string &name)
- : BooleanHistogram(name), mSwitched(false) {
+FlagHistogram::FlagHistogram()
+ : BooleanHistogram(), mSwitched(false) {
}
Histogram::ClassType
FlagHistogram::histogram_type() const
{
return FLAG_HISTOGRAM;
}
@@ -884,32 +725,30 @@ FlagHistogram::Clear() {
LinearHistogram::Accumulate(0, 1, zero_index);
}
//------------------------------------------------------------------------------
// CountHistogram:
//------------------------------------------------------------------------------
Histogram *
-CountHistogram::FactoryGet(const std::string &name, Flags flags)
+CountHistogram::FactoryGet(Flags flags)
{
Histogram *h(nullptr);
- if (!StatisticsRecorder::FindHistogram(name, &h)) {
- CountHistogram *fh = new CountHistogram(name);
- fh->InitializeBucketRange();
- fh->SetFlags(flags);
- h = StatisticsRecorder::RegisterOrDeleteDuplicate(fh);
- }
+ CountHistogram *fh = new CountHistogram();
+ fh->InitializeBucketRange();
+ fh->SetFlags(flags);
+ h = fh;
return h;
}
-CountHistogram::CountHistogram(const std::string &name)
- : LinearHistogram(name, 1, 2, 3) {
+CountHistogram::CountHistogram()
+ : LinearHistogram(1, 2, 3) {
}
Histogram::ClassType
CountHistogram::histogram_type() const
{
return COUNT_HISTOGRAM;
}
@@ -937,55 +776,50 @@ CountHistogram::AddSampleSet(const Sampl
}
}
//------------------------------------------------------------------------------
// CustomHistogram:
//------------------------------------------------------------------------------
-Histogram* CustomHistogram::FactoryGet(const std::string& name,
- const std::vector<Sample>& custom_ranges,
+Histogram* CustomHistogram::FactoryGet(const std::vector<Sample>& custom_ranges,
Flags flags) {
Histogram* histogram(NULL);
// Remove the duplicates in the custom ranges array.
std::vector<int> ranges = custom_ranges;
ranges.push_back(0); // Ensure we have a zero value.
std::sort(ranges.begin(), ranges.end());
ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end());
if (ranges.size() <= 1) {
DCHECK(false);
// Note that we pushed a 0 in above, so for defensive code....
ranges.push_back(1); // Put in some data so we can index to [1].
}
DCHECK_LT(ranges.back(), kSampleType_MAX);
- if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
- CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges);
- tentative_histogram->InitializedCustomBucketRange(ranges);
- tentative_histogram->SetFlags(flags);
- histogram =
- StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
- }
+ CustomHistogram* custom_histogram = new CustomHistogram(ranges);
+ custom_histogram->InitializedCustomBucketRange(ranges);
+ custom_histogram->SetFlags(flags);
+ histogram = custom_histogram;
DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM);
DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(),
ranges.size()));
return histogram;
}
Histogram::ClassType CustomHistogram::histogram_type() const {
return CUSTOM_HISTOGRAM;
}
-CustomHistogram::CustomHistogram(const std::string& name,
- const std::vector<Sample>& custom_ranges)
- : Histogram(name, custom_ranges[1], custom_ranges.back(),
+CustomHistogram::CustomHistogram(const std::vector<Sample>& custom_ranges)
+ : Histogram(custom_ranges[1], custom_ranges.back(),
custom_ranges.size()) {
DCHECK_GT(custom_ranges.size(), 1u);
DCHECK_EQ(custom_ranges[0], 0);
}
void CustomHistogram::InitializedCustomBucketRange(
const std::vector<Sample>& custom_ranges) {
DCHECK_GT(custom_ranges.size(), 1u);
--- a/ipc/chromium/src/base/histogram.h
+++ b/ipc/chromium/src/base/histogram.h
@@ -51,216 +51,16 @@
#include <vector>
#include "base/time.h"
#include "base/lock.h"
namespace base {
//------------------------------------------------------------------------------
-// Provide easy general purpose histogram in a macro, just like stats counters.
-// The first four macros use 50 buckets.
-
-#define HISTOGRAM_TIMES(name, sample) HISTOGRAM_CUSTOM_TIMES( \
- name, sample, base::TimeDelta::FromMilliseconds(1), \
- base::TimeDelta::FromSeconds(10), 50)
-
-#define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 1000000, 50)
-
-#define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 100, 50)
-
-#define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 10000, 50)
-
-#define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::Histogram::FactoryGet(name, min, max, bucket_count, \
- base::Histogram::kNoFlags); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->Add(sample); \
- } while (0)
-
-#define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
- HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
-
-// For folks that need real specific times, use this to select a precise range
-// of times you want plotted, and the number of buckets you want used.
-#define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \
- base::Histogram::kNoFlags); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->AddTime(sample); \
- } while (0)
-
-// DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES.
-#define HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \
- base::Histogram::kNoFlags); \
- DCHECK_EQ(name, counter->histogram_name()); \
- if ((sample) < (max)) counter->AddTime(sample); \
- } while (0)
-
-// Support histograming of an enumerated value. The samples should always be
-// less than boundary_value.
-
-#define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::LinearHistogram::FactoryGet(name, 1, boundary_value, \
- boundary_value + 1, base::Histogram::kNoFlags); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->Add(sample); \
- } while (0)
-
-#define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::CustomHistogram::FactoryGet(name, custom_ranges, \
- base::Histogram::kNoFlags); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->Add(sample); \
- } while (0)
-
-
-//------------------------------------------------------------------------------
-// Define Debug vs non-debug flavors of macros.
-#ifndef NDEBUG
-
-#define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample)
-#define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample)
-#define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\
- name, under_one_hundred)
-#define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
- HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count)
-#define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \
- HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count)
-#define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
- HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count)
-#define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \
- HISTOGRAM_ENUMERATION(name, sample, boundary_value)
-#define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
- HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges)
-
-#else // NDEBUG
-
-#define DHISTOGRAM_TIMES(name, sample) do {} while (0)
-#define DHISTOGRAM_COUNTS(name, sample) do {} while (0)
-#define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) do {} while (0)
-#define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
- do {} while (0)
-#define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \
- do {} while (0)
-#define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
- do {} while (0)
-#define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) do {} while (0)
-#define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
- do {} while (0)
-
-#endif // NDEBUG
-
-//------------------------------------------------------------------------------
-// The following macros provide typical usage scenarios for callers that wish
-// to record histogram data, and have the data submitted/uploaded via UMA.
-// Not all systems support such UMA, but if they do, the following macros
-// should work with the service.
-
-#define UMA_HISTOGRAM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
- name, sample, base::TimeDelta::FromMilliseconds(1), \
- base::TimeDelta::FromSeconds(10), 50)
-
-#define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
- name, sample, base::TimeDelta::FromMilliseconds(10), \
- base::TimeDelta::FromMinutes(3), 50)
-
-// Use this macro when times can routinely be much longer than 10 seconds.
-#define UMA_HISTOGRAM_LONG_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
- name, sample, base::TimeDelta::FromMilliseconds(1), \
- base::TimeDelta::FromHours(1), 50)
-
-#define UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \
- base::Histogram::kUmaTargetedHistogramFlag); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->AddTime(sample); \
- } while (0)
-
-// DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES.
-#define UMA_HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \
- base::Histogram::kUmaTargetedHistogramFlag); \
- DCHECK_EQ(name, counter->histogram_name()); \
- if ((sample) < (max)) counter->AddTime(sample); \
- } while (0)
-
-#define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 1000000, 50)
-
-#define UMA_HISTOGRAM_COUNTS_100(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 100, 50)
-
-#define UMA_HISTOGRAM_COUNTS_10000(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 10000, 50)
-
-#define UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::Histogram::FactoryGet(name, min, max, bucket_count, \
- base::Histogram::kUmaTargetedHistogramFlag); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->Add(sample); \
- } while (0)
-
-#define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1000, 500000, 50)
-
-#define UMA_HISTOGRAM_MEMORY_MB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
- name, sample, 1, 1000, 50)
-
-#define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
- UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
-
-#define UMA_HISTOGRAM_BOOLEAN(name, sample) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::BooleanHistogram::FactoryGet(name, \
- base::Histogram::kUmaTargetedHistogramFlag); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->AddBoolean(sample); \
- } while (0)
-
-#define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::LinearHistogram::FactoryGet(name, 1, boundary_value, \
- boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->Add(sample); \
- } while (0)
-
-#define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \
- static base::Histogram* counter(NULL); \
- if (!counter) \
- counter = base::CustomHistogram::FactoryGet(name, custom_ranges, \
- base::Histogram::kUmaTargetedHistogramFlag); \
- DCHECK_EQ(name, counter->histogram_name()); \
- counter->Add(sample); \
- } while (0)
-
-//------------------------------------------------------------------------------
class BooleanHistogram;
class CustomHistogram;
class Histogram;
class LinearHistogram;
class Histogram {
public:
@@ -368,23 +168,21 @@ class Histogram {
// and also the snapshotting code may asynchronously get a mismatch (though
// generally either race based mismatch cause is VERY rare).
int64_t redundant_count_;
};
//----------------------------------------------------------------------------
// minimum should start from 1. 0 is invalid as a minimum. 0 is an implicit
// default underflow bucket.
- static Histogram* FactoryGet(const std::string& name,
- Sample minimum,
+ static Histogram* FactoryGet(Sample minimum,
Sample maximum,
size_t bucket_count,
Flags flags);
- static Histogram* FactoryTimeGet(const std::string& name,
- base::TimeDelta minimum,
+ static Histogram* FactoryTimeGet(base::TimeDelta minimum,
base::TimeDelta maximum,
size_t bucket_count,
Flags flags);
void Add(int value);
void Subtract(int value);
// TODO: Currently recording_enabled_ is not used by any Histogram class, but
@@ -403,21 +201,16 @@ class Histogram {
virtual void AddSampleSet(const SampleSet& sample);
virtual void Clear();
// This method is an interface, used only by LinearHistogram.
virtual void SetRangeDescriptions(const DescriptionPair descriptions[]);
- // The following methods provide graphical histogram displays.
- void WriteHTMLGraph(std::string* output) const;
- void WriteAscii(bool graph_it, const std::string& newline,
- std::string* output) const;
-
// Support generic flagging of Histograms.
// 0x1 Currently used to mark this histogram to be recorded by UMA..
// 0x8000 means print ranges in hex.
void SetFlags(Flags flags) { flags_ = static_cast<Flags> (flags_ | flags); }
void ClearFlags(Flags flags) { flags_ = static_cast<Flags>(flags_ & ~flags); }
int flags() const { return flags_; }
// Check to see if bucket ranges, counts and tallies in the snapshot are
@@ -426,17 +219,16 @@ class Histogram {
// a SnapShot process, but should otherwise be false at all times (unless we
// have memory over-writes, or DRAM failures).
virtual Inconsistencies FindCorruption(const SampleSet& snapshot) const;
//----------------------------------------------------------------------------
// Accessors for factory constuction, serialization and testing.
//----------------------------------------------------------------------------
virtual ClassType histogram_type() const;
- const std::string& histogram_name() const { return histogram_name_; }
Sample declared_min() const { return declared_min_; }
Sample declared_max() const { return declared_max_; }
virtual Sample ranges(size_t i) const;
uint32_t range_checksum() const { return range_checksum_; }
virtual size_t bucket_count() const;
// Do a safe atomic snapshot of sample data. The caller is assumed to
// have exclusive access to the destination, |*sample|, and no locking
@@ -448,20 +240,18 @@ class Histogram {
virtual bool HasConstructorTimeDeltaArguments(TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count);
// Return true iff the range_checksum_ matches current ranges_ vector.
bool HasValidRangeChecksum() const;
protected:
- Histogram(const std::string& name, Sample minimum,
- Sample maximum, size_t bucket_count);
- Histogram(const std::string& name, TimeDelta minimum,
- TimeDelta maximum, size_t bucket_count);
+ Histogram(Sample minimum, Sample maximum, size_t bucket_count);
+ Histogram(TimeDelta minimum, TimeDelta maximum, size_t bucket_count);
virtual ~Histogram();
// Initialize ranges_ mapping.
void InitializeBucketRange();
// Method to override to skip the display of the i'th bucket if it's empty.
virtual bool PrintEmptyBucket(size_t index) const;
@@ -511,44 +301,22 @@ class Histogram {
static uint32_t Crc32(uint32_t sum, Sample range);
//----------------------------------------------------------------------------
// Helpers for emitting Ascii graphic. Each method appends data to output.
// Find out how large the (graphically) the largest bucket will appear to be.
double GetPeakBucketSize(const SampleSet& snapshot) const;
- // Write a common header message describing this histogram.
- void WriteAsciiHeader(const SampleSet& snapshot,
- Count sample_count, std::string* output) const;
-
- // Write information about previous, current, and next buckets.
- // Information such as cumulative percentage, etc.
- void WriteAsciiBucketContext(const int64_t past, const Count current,
- const int64_t remaining, const size_t i,
- std::string* output) const;
-
- // Write textual description of the bucket contents (relative to histogram).
- // Output is the count in the buckets, as well as the percentage.
- void WriteAsciiBucketValue(Count current, double scaled_sum,
- std::string* output) const;
-
- // Produce actual graph (set of blank vs non blank char's) for a bucket.
- void WriteAsciiBucketGraph(double current_size, double max_size,
- std::string* output) const;
-
//----------------------------------------------------------------------------
// Table for generating Crc32 values.
static const uint32_t kCrcTable[256];
//----------------------------------------------------------------------------
// Invariant values set at/near construction time
- // ASCII version of original name given to the constructor. All identically
- // named instances will be coalesced cross-project.
- const std::string histogram_name_;
Sample declared_min_; // Less than this goes into counts_[0]
Sample declared_max_; // Over this goes into counts_[bucket_count_ - 1].
size_t bucket_count_; // Dimension of counts_[].
// Flag the histogram for recording by UMA via metric_services.h.
Flags flags_;
// For each index, show the least value that can be stored in the
@@ -573,42 +341,38 @@ class Histogram {
// LinearHistogram is a more traditional histogram, with evenly spaced
// buckets.
class LinearHistogram : public Histogram {
public:
virtual ~LinearHistogram();
/* minimum should start from 1. 0 is as minimum is invalid. 0 is an implicit
default underflow bucket. */
- static Histogram* FactoryGet(const std::string& name,
- Sample minimum,
+ static Histogram* FactoryGet(Sample minimum,
Sample maximum,
size_t bucket_count,
Flags flags);
- static Histogram* FactoryTimeGet(const std::string& name,
- TimeDelta minimum,
+ static Histogram* FactoryTimeGet(TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
Flags flags);
// Overridden from Histogram:
virtual ClassType histogram_type() const;
virtual void Accumulate(Sample value, Count count, size_t index);
// Store a list of number/text values for use in rendering the histogram.
// The last element in the array has a null in its "description" slot.
virtual void SetRangeDescriptions(const DescriptionPair descriptions[]);
protected:
- LinearHistogram(const std::string& name, Sample minimum,
- Sample maximum, size_t bucket_count);
+ LinearHistogram(Sample minimum, Sample maximum, size_t bucket_count);
- LinearHistogram(const std::string& name, TimeDelta minimum,
- TimeDelta maximum, size_t bucket_count);
+ LinearHistogram(TimeDelta minimum, TimeDelta maximum, size_t bucket_count);
// Initialize ranges_ mapping.
void InitializeBucketRange();
virtual double GetBucketSize(Count current, size_t i) const;
// If we have a description for a bucket, then return that. Otherwise
// let parent class provide a (numeric) description.
virtual const std::string GetAsciiBucketRange(size_t i) const;
@@ -627,87 +391,85 @@ class LinearHistogram : public Histogram
DISALLOW_COPY_AND_ASSIGN(LinearHistogram);
};
//------------------------------------------------------------------------------
// BooleanHistogram is a histogram for booleans.
class BooleanHistogram : public LinearHistogram {
public:
- static Histogram* FactoryGet(const std::string& name, Flags flags);
+ static Histogram* FactoryGet(Flags flags);
virtual ClassType histogram_type() const;
virtual void AddBoolean(bool value);
virtual void Accumulate(Sample value, Count count, size_t index);
protected:
- explicit BooleanHistogram(const std::string& name);
+ explicit BooleanHistogram();
DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
};
//------------------------------------------------------------------------------
// FlagHistogram is like boolean histogram, but only allows a single off/on value.
class FlagHistogram : public BooleanHistogram
{
public:
- static Histogram *FactoryGet(const std::string &name, Flags flags);
+ static Histogram *FactoryGet(Flags flags);
virtual ClassType histogram_type() const;
virtual void Accumulate(Sample value, Count count, size_t index);
virtual void AddSampleSet(const SampleSet& sample);
virtual void Clear();
private:
- explicit FlagHistogram(const std::string &name);
+ explicit FlagHistogram();
bool mSwitched;
DISALLOW_COPY_AND_ASSIGN(FlagHistogram);
};
// CountHistogram only allows a single monotic counter value.
class CountHistogram : public LinearHistogram
{
public:
- static Histogram *FactoryGet(const std::string &name, Flags flags);
+ static Histogram *FactoryGet(Flags flags);
virtual ClassType histogram_type() const;
virtual void Accumulate(Sample value, Count count, size_t index);
virtual void AddSampleSet(const SampleSet& sample);
private:
- explicit CountHistogram(const std::string &name);
+ explicit CountHistogram();
DISALLOW_COPY_AND_ASSIGN(CountHistogram);
};
//------------------------------------------------------------------------------
// CustomHistogram is a histogram for a set of custom integers.
class CustomHistogram : public Histogram {
public:
- static Histogram* FactoryGet(const std::string& name,
- const std::vector<Sample>& custom_ranges,
+ static Histogram* FactoryGet(const std::vector<Sample>& custom_ranges,
Flags flags);
// Overridden from Histogram:
virtual ClassType histogram_type() const;
protected:
- CustomHistogram(const std::string& name,
- const std::vector<Sample>& custom_ranges);
+ CustomHistogram(const std::vector<Sample>& custom_ranges);
// Initialize ranges_ mapping.
void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges);
virtual double GetBucketSize(Count current, size_t i) const;
DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
};