1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // SampleMap implements HistogramSamples interface. It is used by the 6 // SparseHistogram class to store samples. 7 8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ 9 #define BASE_METRICS_SAMPLE_MAP_H_ 10 11 #include <stdint.h> 12 13 #include <map> 14 #include <memory> 15 16 #include "base/base_export.h" 17 #include "base/compiler_specific.h" 18 #include "base/metrics/histogram_base.h" 19 #include "base/metrics/histogram_samples.h" 20 21 namespace base { 22 23 // The logic here is similar to that of PersistentSampleMap but with different 24 // data structures. Changes here likely need to be duplicated there. 25 class BASE_EXPORT SampleMap : public HistogramSamples { 26 public: 27 SampleMap(); 28 explicit SampleMap(uint64_t id); 29 30 SampleMap(const SampleMap&) = delete; 31 SampleMap& operator=(const SampleMap&) = delete; 32 33 ~SampleMap() override; 34 35 // HistogramSamples: 36 void Accumulate(HistogramBase::Sample value, 37 HistogramBase::Count count) override; 38 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; 39 HistogramBase::Count TotalCount() const override; 40 std::unique_ptr<SampleCountIterator> Iterator() const override; 41 std::unique_ptr<SampleCountIterator> ExtractingIterator() override; 42 bool IsDefinitelyEmpty() const override; 43 44 protected: 45 // Performs arithemetic. |op| is ADD or SUBTRACT. 46 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override; 47 48 private: 49 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; 50 }; 51 52 } // namespace base 53 54 #endif // BASE_METRICS_SAMPLE_MAP_H_ 55