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

Side by Side Diff: base/metrics/sample_vector.cc

Issue 11022002: Add SampleMap and use it in SparseHistogram (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address more comments Created 8 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/metrics/sample_vector.h ('k') | base/metrics/sample_vector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/sample_vector.h" 5 #include "base/metrics/sample_vector.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/bucket_ranges.h" 8 #include "base/metrics/bucket_ranges.h"
9 9
10 using std::vector; 10 using std::vector;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 DCHECK(bucket_index >= 0 && bucket_index < counts_.size()); 46 DCHECK(bucket_index >= 0 && bucket_index < counts_.size());
47 return counts_[bucket_index]; 47 return counts_[bucket_index];
48 } 48 }
49 49
50 scoped_ptr<SampleCountIterator> SampleVector::Iterator() const { 50 scoped_ptr<SampleCountIterator> SampleVector::Iterator() const {
51 return scoped_ptr<SampleCountIterator>( 51 return scoped_ptr<SampleCountIterator>(
52 new SampleVectorIterator(&counts_, bucket_ranges_)); 52 new SampleVectorIterator(&counts_, bucket_ranges_));
53 } 53 }
54 54
55 bool SampleVector::AddSubtractImpl(SampleCountIterator* iter, 55 bool SampleVector::AddSubtractImpl(SampleCountIterator* iter,
56 HistogramSamples::Instruction instruction) { 56 HistogramSamples::Operator op) {
57 HistogramBase::Sample min; 57 HistogramBase::Sample min;
58 HistogramBase::Sample max; 58 HistogramBase::Sample max;
59 HistogramBase::Count count; 59 HistogramBase::Count count;
60 60
61 // Go through the iterator and add the counts into correct bucket. 61 // Go through the iterator and add the counts into correct bucket.
62 size_t index = 0; 62 size_t index = 0;
63 while (index < counts_.size() && !iter->Done()) { 63 while (index < counts_.size() && !iter->Done()) {
64 iter->Get(&min, &max, &count); 64 iter->Get(&min, &max, &count);
65 if (min == bucket_ranges_->range(index) && 65 if (min == bucket_ranges_->range(index) &&
66 max == bucket_ranges_->range(index + 1)) { 66 max == bucket_ranges_->range(index + 1)) {
67 // Sample matches this bucket! 67 // Sample matches this bucket!
68 counts_[index] += 68 counts_[index] += (op == HistogramSamples::ADD) ? count : -count;
69 (instruction == HistogramSamples::ADD) ? count : -count;
70 iter->Next(); 69 iter->Next();
71 } else if (min > bucket_ranges_->range(index)) { 70 } else if (min > bucket_ranges_->range(index)) {
72 // Sample is larger than current bucket range. Try next. 71 // Sample is larger than current bucket range. Try next.
73 index++; 72 index++;
74 } else { 73 } else {
75 // Sample is smaller than current bucket range. We scan buckets from 74 // Sample is smaller than current bucket range. We scan buckets from
76 // smallest to largest, so the sample value must be invalid. 75 // smallest to largest, so the sample value must be invalid.
77 return false; 76 return false;
78 } 77 }
79 } 78 }
(...skipping 30 matching lines...) Expand all
110 109
111 SampleVectorIterator::SampleVectorIterator(const vector<Count>* counts, 110 SampleVectorIterator::SampleVectorIterator(const vector<Count>* counts,
112 const BucketRanges* bucket_ranges) 111 const BucketRanges* bucket_ranges)
113 : counts_(counts), 112 : counts_(counts),
114 bucket_ranges_(bucket_ranges), 113 bucket_ranges_(bucket_ranges),
115 index_(0) { 114 index_(0) {
116 CHECK_GT(bucket_ranges_->size(), counts_->size()); 115 CHECK_GT(bucket_ranges_->size(), counts_->size());
117 SkipEmptyBuckets(); 116 SkipEmptyBuckets();
118 } 117 }
119 118
119 SampleVectorIterator::~SampleVectorIterator() {}
120
120 bool SampleVectorIterator::Done() const { 121 bool SampleVectorIterator::Done() const {
121 return index_ >= counts_->size(); 122 return index_ >= counts_->size();
122 } 123 }
123 124
124 void SampleVectorIterator::Next() { 125 void SampleVectorIterator::Next() {
125 DCHECK(!Done()); 126 DCHECK(!Done());
126 index_++; 127 index_++;
127 SkipEmptyBuckets(); 128 SkipEmptyBuckets();
128 } 129 }
129 130
(...skipping 21 matching lines...) Expand all
151 return; 152 return;
152 153
153 while (index_ < counts_->size()) { 154 while (index_ < counts_->size()) {
154 if ((*counts_)[index_] != 0) 155 if ((*counts_)[index_] != 0)
155 return; 156 return;
156 index_++; 157 index_++;
157 } 158 }
158 } 159 }
159 160
160 } // namespace base 161 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sample_vector.h ('k') | base/metrics/sample_vector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698