Bug 747379 - Override Histogram::AddSampleSet for FlagHistograms. r=nfroyd

This commit is contained in:
Graeme McCutcheon 2012-04-27 11:14:03 +01:00
parent d4809c1dce
commit 444c09308a
3 changed files with 40 additions and 10 deletions

View File

@ -962,6 +962,31 @@ FlagHistogram::Accumulate(Sample value, Count count, size_t index)
Histogram::Accumulate(1, -1, zero_index);
}
void
FlagHistogram::AddSampleSet(const SampleSet& sample) {
DCHECK_EQ(bucket_count(), sample.size());
// We can't be sure the SampleSet provided came from another FlagHistogram,
// so we take the following steps:
// - If our flag has already been set do nothing.
// - Set our flag if the following hold:
// - The sum of the counts in the provided SampleSet is 1.
// - The bucket index for that single value is the same as the index where we
// would place our set flag.
// - Otherwise, take no action.
if (mSwitched) {
return;
}
if (sample.sum() != 1) {
return;
}
size_t one_index = BucketIndex(1);
if (sample.counts(one_index) == 1) {
Accumulate(1, 1, one_index);
}
}
//------------------------------------------------------------------------------
// CustomHistogram:
//------------------------------------------------------------------------------

View File

@ -336,6 +336,7 @@ class Histogram {
Count TotalCount() const;
int64 sum() const { return sum_; }
int64 redundant_count() const { return redundant_count_; }
size_t size() const { return counts_.size(); }
// Arithmetic manipulation of corresponding elements of the set.
void Add(const SampleSet& other);
@ -392,7 +393,7 @@ class Histogram {
Add(static_cast<int>(time.InMilliseconds()));
}
void AddSampleSet(const SampleSet& sample);
virtual void AddSampleSet(const SampleSet& sample);
// This method is an interface, used only by LinearHistogram.
virtual void SetRangeDescriptions(const DescriptionPair descriptions[]);
@ -661,6 +662,8 @@ public:
virtual void Accumulate(Sample value, Count count, size_t index);
virtual void AddSampleSet(const SampleSet& sample);
private:
explicit FlagHistogram(const std::string &name);
bool mSwitched;

View File

@ -132,15 +132,11 @@ function compareHistograms(h1, h2) {
do_check_eq(s1.histogram_type, s2.histogram_type);
do_check_eq(s1.min, s2.min);
do_check_eq(s1.max, s2.max);
do_check_eq(s1.sum, s2.sum);
// XXX Don't compare flag sums until bug 747379 is fixed
if (s1.histogram_type != Telemetry.HISTOGRAM_FLAG) {
do_check_eq(s1.sum, s2.sum);
do_check_eq(s1.counts.length, s2.counts.length);
for (let i = 0; i < s1.counts.length; i++)
do_check_eq(s1.counts[i], s2.counts[i]);
}
do_check_eq(s1.counts.length, s2.counts.length);
for (let i = 0; i < s1.counts.length; i++)
do_check_eq(s1.counts[i], s2.counts[i]);
do_check_eq(s1.ranges.length, s2.ranges.length);
for (let i = 0; i < s1.ranges.length; i++)
@ -148,7 +144,7 @@ function compareHistograms(h1, h2) {
}
function test_histogramFrom() {
// One histogram of each type
// Test one histogram of each type.
let names = ["CYCLE_COLLECTOR", "GC_REASON", "GC_RESET", "TELEMETRY_TEST_FLAG"];
for each (let name in names) {
@ -157,6 +153,12 @@ function test_histogramFrom() {
let clone = Telemetry.histogramFrom("clone" + name, name);
compareHistograms(original, clone);
}
// Additionally, set the flag on TELEMETRY_TEST_FLAG, and check it gets set on the clone.
let testFlag = Telemetry.getHistogramById("TELEMETRY_TEST_FLAG");
testFlag.add(1);
let clone = Telemetry.histogramFrom("FlagClone", "TELEMETRY_TEST_FLAG");
compareHistograms(testFlag, clone);
}
function test_getSlowSQL() {