sample_map.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.
  4. // SampleMap implements HistogramSamples interface. It is used by the
  5. // SparseHistogram class to store samples.
  6. #ifndef BASE_METRICS_SAMPLE_MAP_H_
  7. #define BASE_METRICS_SAMPLE_MAP_H_
  8. #include <stdint.h>
  9. #include <map>
  10. #include <memory>
  11. #include "base/base_export.h"
  12. #include "base/compiler_specific.h"
  13. #include "base/metrics/histogram_base.h"
  14. #include "base/metrics/histogram_samples.h"
  15. namespace base {
  16. // The logic here is similar to that of PersistentSampleMap but with different
  17. // data structures. Changes here likely need to be duplicated there.
  18. class BASE_EXPORT SampleMap : public HistogramSamples {
  19. public:
  20. SampleMap();
  21. explicit SampleMap(uint64_t id);
  22. SampleMap(const SampleMap&) = delete;
  23. SampleMap& operator=(const SampleMap&) = delete;
  24. ~SampleMap() override;
  25. // HistogramSamples:
  26. void Accumulate(HistogramBase::Sample value,
  27. HistogramBase::Count count) override;
  28. HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
  29. HistogramBase::Count TotalCount() const override;
  30. std::unique_ptr<SampleCountIterator> Iterator() const override;
  31. protected:
  32. // Performs arithemetic. |op| is ADD or SUBTRACT.
  33. bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override;
  34. private:
  35. std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_;
  36. };
  37. } // namespace base
  38. #endif // BASE_METRICS_SAMPLE_MAP_H_