Index: base/metrics/histogram.cc |
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc |
index b7ef10749f86c7387f553137882474497801e311..ef4a4b96df1fc4b099b211e9f38ed1e6af4dc312 100644 |
--- a/base/metrics/histogram.cc |
+++ b/base/metrics/histogram.cc |
@@ -164,6 +164,8 @@ HistogramBase* Histogram::Factory::Build() { |
minimum_ = registered_ranges->range(1); |
maximum_ = registered_ranges->range(bucket_count_ - 1); |
} |
+ DCHECK_EQ(minimum_, registered_ranges->range(1)); |
+ DCHECK_EQ(maximum_, registered_ranges->range(bucket_count_ - 1)); |
// Try to create the histogram using a "persistent" allocator. As of |
// 2016-02-25, the availability of such is controlled by a base::Feature |
@@ -358,6 +360,18 @@ uint32_t Histogram::FindCorruption(const HistogramSamples& samples) const { |
return inconsistencies; |
} |
+Sample Histogram::declared_min() const { |
+ if (bucket_ranges_->bucket_count() < 2) |
+ return -1; |
+ return bucket_ranges_->range(1); |
+} |
+ |
+Sample Histogram::declared_max() const { |
+ if (bucket_ranges_->bucket_count() < 2) |
+ return -1; |
+ return bucket_ranges_->range(bucket_ranges_->bucket_count() - 1); |
+} |
+ |
Sample Histogram::ranges(uint32_t i) const { |
return bucket_ranges_->range(i); |
} |
@@ -431,9 +445,9 @@ HistogramType Histogram::GetHistogramType() const { |
bool Histogram::HasConstructionArguments(Sample expected_minimum, |
Sample expected_maximum, |
uint32_t expected_bucket_count) const { |
- return ((expected_minimum == declared_min_) && |
- (expected_maximum == declared_max_) && |
- (expected_bucket_count == bucket_count())); |
+ return (expected_bucket_count == bucket_count() && |
+ expected_minimum == declared_min() && |
+ expected_maximum == declared_max()); |
} |
void Histogram::Add(int value) { |
@@ -462,7 +476,10 @@ std::unique_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
} |
std::unique_ptr<HistogramSamples> Histogram::SnapshotDelta() { |
+#if DCHECK_IS_ON() |
DCHECK(!final_delta_created_); |
+#endif |
+ |
// The code below has subtle thread-safety guarantees! All changes to |
// the underlying SampleVectors use atomic integer operations, which guarantee |
// eventual consistency, but do not guarantee full synchronization between |
@@ -483,8 +500,10 @@ std::unique_ptr<HistogramSamples> Histogram::SnapshotDelta() { |
} |
std::unique_ptr<HistogramSamples> Histogram::SnapshotFinalDelta() const { |
+#if DCHECK_IS_ON() |
DCHECK(!final_delta_created_); |
final_delta_created_ = true; |
+#endif |
return SnapshotUnloggedSamples(); |
} |
@@ -523,10 +542,7 @@ Histogram::Histogram(const std::string& name, |
Sample minimum, |
Sample maximum, |
Alexei Svitkine (slow)
2017/07/05 20:15:45
Can we remove these params as well?
I see it's on
bcwhite
2017/07/05 21:12:20
Possible. It would remove them as parameters from
bcwhite
2017/07/06 13:08:31
Going with the TODO for now.
|
const BucketRanges* ranges) |
- : HistogramBase(name), |
- bucket_ranges_(ranges), |
- declared_min_(minimum), |
- declared_max_(maximum) { |
+ : HistogramBase(name), bucket_ranges_(ranges) { |
// TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. |
CHECK(ranges) << name << ": " << minimum << "-" << maximum; |
unlogged_samples_.reset(new SampleVector(HashMetricName(name), ranges)); |
@@ -541,10 +557,7 @@ Histogram::Histogram(const std::string& name, |
const DelayedPersistentAllocation& logged_counts, |
HistogramSamples::Metadata* meta, |
HistogramSamples::Metadata* logged_meta) |
- : HistogramBase(name), |
- bucket_ranges_(ranges), |
- declared_min_(minimum), |
- declared_max_(maximum) { |
+ : HistogramBase(name), bucket_ranges_(ranges) { |
// TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. |
CHECK(ranges) << name << ": " << minimum << "-" << maximum; |
unlogged_samples_.reset( |