Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // SampleVector implements HistogramSamples interface. It is used by all | 5 // SampleVector implements HistogramSamples interface. It is used by all |
|
Ilya Sherman
2012/10/01 21:24:50
nit: SampleMap
kaiwang
2012/10/01 22:38:52
Done.
| |
| 6 // Histogram based classes to store samples. | 6 // SparseHistogram to store samples. |
|
Ilya Sherman
2012/10/01 21:24:50
Optional nit: For the second sentence, perhaps som
kaiwang
2012/10/01 22:38:52
Done.
| |
| 7 | 7 |
| 8 #ifndef BASE_METRICS_SAMPLE_VECTOR_H_ | 8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ |
| 9 #define BASE_METRICS_SAMPLE_VECTOR_H_ | 9 #define BASE_METRICS_SAMPLE_MAP_H_ |
| 10 | 10 |
| 11 #include <vector> | 11 #include <map> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/gtest_prod_util.h" | |
| 15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/metrics/histogram_base.h" | 15 #include "base/metrics/histogram_base.h" |
| 17 #include "base/metrics/histogram_samples.h" | 16 #include "base/metrics/histogram_samples.h" |
| 17 #include "base/synchronization/lock.h" | |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 | 20 |
| 21 class BucketRanges; | 21 class BASE_EXPORT_PRIVATE SampleMap : public HistogramSamples { |
| 22 | |
| 23 class BASE_EXPORT_PRIVATE SampleVector : public HistogramSamples { | |
| 24 public: | 22 public: |
| 25 explicit SampleVector(const BucketRanges* bucket_ranges); | 23 SampleMap(); |
| 26 virtual ~SampleVector(); | 24 virtual ~SampleMap(); |
| 27 | 25 |
| 28 // HistogramSamples implementation: | 26 // HistogramSamples implementation: |
| 29 virtual void Accumulate(HistogramBase::Sample value, | 27 virtual void Accumulate(HistogramBase::Sample value, |
| 30 HistogramBase::Count count) OVERRIDE; | 28 HistogramBase::Count count) OVERRIDE; |
| 31 virtual HistogramBase::Count GetCount( | 29 virtual HistogramBase::Count GetCount( |
| 32 HistogramBase::Sample value) const OVERRIDE; | 30 HistogramBase::Sample value) const OVERRIDE; |
| 33 virtual HistogramBase::Count TotalCount() const OVERRIDE; | 31 virtual HistogramBase::Count TotalCount() const OVERRIDE; |
| 34 virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE; | 32 virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE; |
| 35 | 33 |
| 36 // Get count of a specific bucket. | |
| 37 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const; | |
| 38 | |
| 39 protected: | 34 protected: |
| 40 virtual bool AddSubtractImpl( | 35 virtual bool AddSubtractImpl( |
| 41 SampleCountIterator* iter, | 36 SampleCountIterator* iter, |
| 42 HistogramSamples::Instruction instruction) OVERRIDE; | 37 HistogramSamples::Instruction instruction) OVERRIDE; |
| 43 | 38 |
| 44 virtual size_t GetBucketIndex(HistogramBase::Sample value) const; | 39 private: |
| 40 std::map<HistogramBase::Sample, HistogramBase::Count> sample_count_; | |
|
Ilya Sherman
2012/10/01 21:24:50
nit: I think either |sample_counts_| or just |coun
kaiwang
2012/10/01 22:38:52
Done.
| |
| 45 | 41 |
| 46 private: | 42 // Protects access to above map. |
| 47 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); | 43 mutable base::Lock lock_; |
|
Ilya Sherman
2012/10/01 21:24:50
This is tangential to the current CL, but I wonder
kaiwang
2012/10/01 22:38:52
At least for existing histograms, it's common to b
| |
| 48 | 44 |
| 49 std::vector<HistogramBase::Count> counts_; | 45 DISALLOW_COPY_AND_ASSIGN(SampleMap); |
| 50 | |
| 51 // Shares the same BucketRanges with Histogram object. | |
| 52 const BucketRanges* const bucket_ranges_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(SampleVector); | |
| 55 }; | 46 }; |
| 56 | 47 |
| 57 class BASE_EXPORT_PRIVATE SampleVectorIterator : public SampleCountIterator { | 48 class BASE_EXPORT_PRIVATE SampleMapIterator : public SampleCountIterator { |
| 58 public: | 49 public: |
| 59 SampleVectorIterator(const std::vector<HistogramBase::Count>* counts, | 50 SampleMapIterator( |
| 60 const BucketRanges* bucket_ranges); | 51 const std::map<HistogramBase::Sample, HistogramBase::Count>& |
| 52 sample_count); | |
|
Ilya Sherman
2012/10/01 21:24:50
nit: Same naming comment as above.
kaiwang
2012/10/01 22:38:52
Done.
| |
| 53 | |
| 54 virtual ~SampleMapIterator(); | |
| 61 | 55 |
| 62 // SampleCountIterator implementation: | 56 // SampleCountIterator implementation: |
| 63 virtual bool Done() const OVERRIDE; | 57 virtual bool Done() const OVERRIDE; |
| 64 virtual void Next() OVERRIDE; | 58 virtual void Next() OVERRIDE; |
| 65 virtual void Get(HistogramBase::Sample* min, | 59 virtual void Get(HistogramBase::Sample* min, |
| 66 HistogramBase::Sample* max, | 60 HistogramBase::Sample* max, |
| 67 HistogramBase::Count* count) const OVERRIDE; | 61 HistogramBase::Count* count) const OVERRIDE; |
| 68 virtual bool GetBucketIndex(size_t* index) const OVERRIDE; | |
| 69 | |
| 70 private: | 62 private: |
| 71 void SkipEmptyBuckets(); | 63 std::map<HistogramBase::Sample, HistogramBase::Count>::const_iterator iter_; |
| 72 | 64 const std::map<HistogramBase::Sample, HistogramBase::Count>::const_iterator |
| 73 const std::vector<HistogramBase::Count>* counts_; | 65 end_; |
| 74 const BucketRanges* bucket_ranges_; | |
| 75 | |
| 76 size_t index_; | |
| 77 }; | 66 }; |
| 78 | 67 |
| 79 } // namespace base | 68 } // namespace base |
| 80 | 69 |
| 81 #endif // BASE_METRICS_SAMPLE_VECTOR_H_ | 70 #endif // BASE_METRICS_SAMPLE_MAP_H_ |
| OLD | NEW |