sample_map.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/compiler_specific.h"
  12. #include "base/macros.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() override;
  23. // HistogramSamples:
  24. void Accumulate(HistogramBase::Sample value,
  25. HistogramBase::Count count) override;
  26. HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
  27. HistogramBase::Count TotalCount() const override;
  28. std::unique_ptr<SampleCountIterator> Iterator() const override;
  29. protected:
  30. // Performs arithemetic. |op| is ADD or SUBTRACT.
  31. bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override;
  32. private:
  33. std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_;
  34. DISALLOW_COPY_AND_ASSIGN(SampleMap);
  35. };
  36. } // namespace base
  37. #endif // BASE_METRICS_SAMPLE_MAP_H_