Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / base / metrics / sample_vector.h
blob55f9b965cc679651444e2ab8abaf678b7c28a214
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
3 // found in the LICENSE file.
5 // SampleVector implements HistogramSamples interface. It is used by all
6 // Histogram based classes to store samples.
8 #ifndef BASE_METRICS_SAMPLE_VECTOR_H_
9 #define BASE_METRICS_SAMPLE_VECTOR_H_
11 #include <vector>
13 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/histogram_base.h"
17 #include "base/metrics/histogram_samples.h"
19 namespace base {
21 class BucketRanges;
23 class BASE_EXPORT_PRIVATE SampleVector : public HistogramSamples {
24 public:
25 explicit SampleVector(const BucketRanges* bucket_ranges);
26 ~SampleVector() override;
28 // HistogramSamples implementation:
29 void Accumulate(HistogramBase::Sample value,
30 HistogramBase::Count count) override;
31 HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
32 HistogramBase::Count TotalCount() const override;
33 scoped_ptr<SampleCountIterator> Iterator() const override;
35 // Get count of a specific bucket.
36 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const;
38 protected:
39 bool AddSubtractImpl(
40 SampleCountIterator* iter,
41 HistogramSamples::Operator op) override; // |op| is ADD or SUBTRACT.
43 virtual size_t GetBucketIndex(HistogramBase::Sample value) const;
45 private:
46 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
48 std::vector<HistogramBase::AtomicCount> counts_;
50 // Shares the same BucketRanges with Histogram object.
51 const BucketRanges* const bucket_ranges_;
53 DISALLOW_COPY_AND_ASSIGN(SampleVector);
56 class BASE_EXPORT_PRIVATE SampleVectorIterator : public SampleCountIterator {
57 public:
58 SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts,
59 const BucketRanges* bucket_ranges);
60 ~SampleVectorIterator() override;
62 // SampleCountIterator implementation:
63 bool Done() const override;
64 void Next() override;
65 void Get(HistogramBase::Sample* min,
66 HistogramBase::Sample* max,
67 HistogramBase::Count* count) const override;
69 // SampleVector uses predefined buckets, so iterator can return bucket index.
70 bool GetBucketIndex(size_t* index) const override;
72 private:
73 void SkipEmptyBuckets();
75 const std::vector<HistogramBase::AtomicCount>* counts_;
76 const BucketRanges* bucket_ranges_;
78 size_t index_;
81 } // namespace base
83 #endif // BASE_METRICS_SAMPLE_VECTOR_H_