mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
Bug 1366294 - Part 2 - Cleanup Chromium Histogram code. r=chutten
- A histogram name identifies a set of histogram instances, for which storage and lookup will be handled in TelemetryHistogram.cpp. So we remove the names from histogram code. - Various unused macros in the header are removed. - Remaining traces of StatisticsRecorder are removed from the Histogram class code. - Some unused methods are dropped that were about printing histograms to ASCII etc. MozReview-Commit-ID: BF2rLSpKOJ8
This commit is contained in:
parent
2932617587
commit
3d975a580b
@ -81,8 +81,7 @@ 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) {
|
||||
@ -94,29 +93,20 @@ Histogram* Histogram::FactoryGet(const std::string& name,
|
||||
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);
|
||||
}
|
||||
|
||||
@ -160,80 +150,6 @@ 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.
|
||||
//------------------------------------------------------------------------------
|
||||
@ -270,12 +186,10 @@ Histogram::FindCorruption(const SampleSet& snapshot) const
|
||||
// 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;
|
||||
}
|
||||
@ -337,10 +251,8 @@ Histogram::SampleSet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
||||
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),
|
||||
@ -351,10 +263,8 @@ Histogram::Histogram(const std::string& name, Sample minimum,
|
||||
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),
|
||||
@ -366,12 +276,6 @@ Histogram::Histogram(const std::string& name, TimeDelta minimum,
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
@ -560,57 +464,6 @@ double Histogram::GetPeakBucketSize(const SampleSet& snapshot) const {
|
||||
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
|
||||
//------------------------------------------------------------------------------
|
||||
@ -665,8 +518,7 @@ void Histogram::SampleSet::Add(const SampleSet& other) {
|
||||
LinearHistogram::~LinearHistogram() {
|
||||
}
|
||||
|
||||
Histogram* LinearHistogram::FactoryGet(const std::string& name,
|
||||
Sample minimum,
|
||||
Histogram* LinearHistogram::FactoryGet(Sample minimum,
|
||||
Sample maximum,
|
||||
size_t bucket_count,
|
||||
Flags flags) {
|
||||
@ -677,26 +529,22 @@ Histogram* LinearHistogram::FactoryGet(const std::string& name,
|
||||
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);
|
||||
}
|
||||
|
||||
@ -715,18 +563,16 @@ void LinearHistogram::SetRangeDescriptions(
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
@ -769,16 +615,13 @@ bool LinearHistogram::PrintEmptyBucket(size_t index) const {
|
||||
// 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;
|
||||
@ -792,8 +635,8 @@ 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
|
||||
@ -809,24 +652,22 @@ BooleanHistogram::Accumulate(Sample value, Count count, size_t index)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
@ -889,22 +730,20 @@ FlagHistogram::Clear() {
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
@ -942,8 +781,7 @@ CountHistogram::AddSampleSet(const SampleSet& sample) {
|
||||
// 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);
|
||||
|
||||
@ -960,13 +798,10 @@ Histogram* CustomHistogram::FactoryGet(const std::string& name,
|
||||
|
||||
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(),
|
||||
@ -978,9 +813,8 @@ 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);
|
||||
|
@ -55,206 +55,6 @@
|
||||
|
||||
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;
|
||||
@ -373,13 +173,11 @@ class Histogram {
|
||||
//----------------------------------------------------------------------------
|
||||
// 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);
|
||||
@ -408,11 +206,6 @@ class Histogram {
|
||||
// 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.
|
||||
@ -431,7 +224,6 @@ class Histogram {
|
||||
// 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;
|
||||
@ -453,10 +245,8 @@ class Histogram {
|
||||
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();
|
||||
|
||||
@ -516,34 +306,12 @@ class Histogram {
|
||||
// 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_[].
|
||||
@ -578,13 +346,11 @@ class LinearHistogram : public Histogram {
|
||||
|
||||
/* 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);
|
||||
@ -599,11 +365,9 @@ class LinearHistogram : public Histogram {
|
||||
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();
|
||||
@ -632,7 +396,7 @@ class LinearHistogram : public Histogram {
|
||||
// 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;
|
||||
|
||||
@ -641,7 +405,7 @@ class BooleanHistogram : public LinearHistogram {
|
||||
virtual void Accumulate(Sample value, Count count, size_t index);
|
||||
|
||||
protected:
|
||||
explicit BooleanHistogram(const std::string& name);
|
||||
explicit BooleanHistogram();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
|
||||
};
|
||||
@ -652,7 +416,7 @@ class BooleanHistogram : public LinearHistogram {
|
||||
class FlagHistogram : public BooleanHistogram
|
||||
{
|
||||
public:
|
||||
static Histogram *FactoryGet(const std::string &name, Flags flags);
|
||||
static Histogram *FactoryGet(Flags flags);
|
||||
|
||||
virtual ClassType histogram_type() const;
|
||||
|
||||
@ -663,7 +427,7 @@ public:
|
||||
virtual void Clear();
|
||||
|
||||
private:
|
||||
explicit FlagHistogram(const std::string &name);
|
||||
explicit FlagHistogram();
|
||||
bool mSwitched;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FlagHistogram);
|
||||
@ -673,7 +437,7 @@ private:
|
||||
class CountHistogram : public LinearHistogram
|
||||
{
|
||||
public:
|
||||
static Histogram *FactoryGet(const std::string &name, Flags flags);
|
||||
static Histogram *FactoryGet(Flags flags);
|
||||
|
||||
virtual ClassType histogram_type() const;
|
||||
|
||||
@ -682,7 +446,7 @@ public:
|
||||
virtual void AddSampleSet(const SampleSet& sample);
|
||||
|
||||
private:
|
||||
explicit CountHistogram(const std::string &name);
|
||||
explicit CountHistogram();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CountHistogram);
|
||||
};
|
||||
@ -693,16 +457,14 @@ private:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user