Home | History | Annotate | Download | only in metrics
      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 
      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/compiler_specific.h"
     17 #include "base/macros.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   ~SampleMap() override;
     30 
     31   // HistogramSamples:
     32   void Accumulate(HistogramBase::Sample value,
     33                   HistogramBase::Count count) override;
     34   HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
     35   HistogramBase::Count TotalCount() const override;
     36   std::unique_ptr<SampleCountIterator> Iterator() const override;
     37 
     38  protected:
     39   // Performs arithemetic. |op| is ADD or SUBTRACT.
     40   bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override;
     41 
     42  private:
     43   std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_;
     44 
     45   DISALLOW_COPY_AND_ASSIGN(SampleMap);
     46 };
     47 
     48 }  // namespace base
     49 
     50 #endif  // BASE_METRICS_SAMPLE_MAP_H_
     51