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