Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(788)

Unified Diff: base/metrics/sample_vector.cc

Issue 1471073007: Reorganize histograms for persistence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: extra parameter no longer necessary in some files Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/sample_vector.cc
diff --git a/base/metrics/sample_vector.cc b/base/metrics/sample_vector.cc
index 1202527545c52ac2846d58743c46f538326f4aaa..a77cd71d422f574992a1731a37446d1d6bef1372 100644
--- a/base/metrics/sample_vector.cc
+++ b/base/metrics/sample_vector.cc
@@ -13,11 +13,36 @@ typedef HistogramBase::Count Count;
typedef HistogramBase::Sample Sample;
SampleVector::SampleVector(const BucketRanges* bucket_ranges)
- : counts_(bucket_ranges->bucket_count()),
+ : HistogramSamples(0),
+ 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 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 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);
+}
+
SampleVector::~SampleVector() {}
void SampleVector::Accumulate(Sample value, Count count) {
@@ -35,20 +60,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 +84,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 +134,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 +178,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 +192,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_++;
}

Powered by Google App Engine
This is Rietveld 408576698