Index: base/metrics/sample_vector.cc |
diff --git a/base/metrics/sample_vector.cc b/base/metrics/sample_vector.cc |
index 1202527545c52ac2846d58743c46f538326f4aaa..46faef068fd8ab4586ab3e937112d34d868e01ea 100644 |
--- a/base/metrics/sample_vector.cc |
+++ b/base/metrics/sample_vector.cc |
@@ -13,8 +13,27 @@ typedef HistogramBase::Count Count; |
typedef HistogramBase::Sample Sample; |
SampleVector::SampleVector(const BucketRanges* bucket_ranges) |
- : counts_(bucket_ranges->bucket_count()), |
+ : SampleVector(0, bucket_ranges) {} |
+ |
+SampleVector::SampleVector(uint64_t id, const BucketRanges* bucket_ranges) |
+ : HistogramSamples(id), |
+ local_counts_(bucket_ranges->bucket_count()), |
+ counts_(&local_counts_[0]), |
+ counts_size_(local_counts_.size()), |
+ bucket_ranges_(bucket_ranges) { |
+ CHECK_GE(bucket_ranges_->bucket_count(), 1u); |
+} |
+ |
+SampleVector::SampleVector(uint64_t id, |
+ HistogramBase::AtomicCount* counts, |
+ size_t counts_size, |
+ Metadata* meta, |
+ const BucketRanges* bucket_ranges) |
+ : HistogramSamples(id, meta), |
+ counts_(counts), |
+ counts_size_(bucket_ranges->bucket_count()), |
bucket_ranges_(bucket_ranges) { |
+ CHECK_LE(bucket_ranges_->bucket_count(), counts_size_); |
CHECK_GE(bucket_ranges_->bucket_count(), 1u); |
} |
@@ -35,20 +54,20 @@ Count SampleVector::GetCount(Sample value) const { |
Count SampleVector::TotalCount() const { |
Count count = 0; |
- for (size_t i = 0; i < counts_.size(); i++) { |
+ for (size_t i = 0; i < counts_size_; i++) { |
count += subtle::NoBarrier_Load(&counts_[i]); |
} |
return count; |
} |
Count SampleVector::GetCountAtIndex(size_t bucket_index) const { |
- DCHECK(bucket_index < counts_.size()); |
+ DCHECK(bucket_index < counts_size_); |
return subtle::NoBarrier_Load(&counts_[bucket_index]); |
} |
scoped_ptr<SampleCountIterator> SampleVector::Iterator() const { |
return scoped_ptr<SampleCountIterator>( |
- new SampleVectorIterator(&counts_, bucket_ranges_)); |
+ new SampleVectorIterator(counts_, counts_size_, bucket_ranges_)); |
} |
bool SampleVector::AddSubtractImpl(SampleCountIterator* iter, |
@@ -59,7 +78,7 @@ bool SampleVector::AddSubtractImpl(SampleCountIterator* iter, |
// Go through the iterator and add the counts into correct bucket. |
size_t index = 0; |
- while (index < counts_.size() && !iter->Done()) { |
+ while (index < counts_size_ && !iter->Done()) { |
iter->Get(&min, &max, &count); |
if (min == bucket_ranges_->range(index) && |
max == bucket_ranges_->range(index + 1)) { |
@@ -109,19 +128,33 @@ size_t SampleVector::GetBucketIndex(Sample value) const { |
return mid; |
} |
-SampleVectorIterator::SampleVectorIterator(const std::vector<Count>* counts, |
- const BucketRanges* bucket_ranges) |
+SampleVectorIterator::SampleVectorIterator( |
+ const std::vector<HistogramBase::AtomicCount>* counts, |
+ const BucketRanges* bucket_ranges) |
+ : counts_(&(*counts)[0]), |
+ counts_size_(counts->size()), |
+ bucket_ranges_(bucket_ranges), |
+ index_(0) { |
+ CHECK_GE(bucket_ranges_->bucket_count(), counts_size_); |
+ SkipEmptyBuckets(); |
+} |
+ |
+SampleVectorIterator::SampleVectorIterator( |
+ const HistogramBase::AtomicCount* counts, |
+ size_t counts_size, |
+ const BucketRanges* bucket_ranges) |
: counts_(counts), |
+ counts_size_(counts_size), |
bucket_ranges_(bucket_ranges), |
index_(0) { |
- CHECK_GE(bucket_ranges_->bucket_count(), counts_->size()); |
+ CHECK_GE(bucket_ranges_->bucket_count(), counts_size_); |
SkipEmptyBuckets(); |
} |
SampleVectorIterator::~SampleVectorIterator() {} |
bool SampleVectorIterator::Done() const { |
- return index_ >= counts_->size(); |
+ return index_ >= counts_size_; |
} |
void SampleVectorIterator::Next() { |
@@ -139,7 +172,7 @@ void SampleVectorIterator::Get(HistogramBase::Sample* min, |
if (max != NULL) |
*max = bucket_ranges_->range(index_ + 1); |
if (count != NULL) |
- *count = subtle::NoBarrier_Load(&(*counts_)[index_]); |
+ *count = subtle::NoBarrier_Load(&counts_[index_]); |
} |
bool SampleVectorIterator::GetBucketIndex(size_t* index) const { |
@@ -153,8 +186,8 @@ void SampleVectorIterator::SkipEmptyBuckets() { |
if (Done()) |
return; |
- while (index_ < counts_->size()) { |
- if (subtle::NoBarrier_Load(&(*counts_)[index_]) != 0) |
+ while (index_ < counts_size_) { |
+ if (subtle::NoBarrier_Load(&counts_[index_]) != 0) |
return; |
index_++; |
} |