OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
Alexei Svitkine (slow)
2016/03/14 18:49:00
Nit: No (c)
bcwhite
2016/03/15 00:00:21
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // PersistentSampleMap implements HistogramSamples interface. It is used | |
6 // by the SparseHistogram class to store samples in persistent memory which | |
7 // allows it to be shared between processes or live across restarts. | |
8 | |
9 #ifndef BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ | |
10 #define BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ | |
11 | |
12 #include <stdint.h> | |
13 | |
14 #include <map> | |
15 | |
16 #include "base/compiler_specific.h" | |
17 #include "base/macros.h" | |
18 #include "base/memory/scoped_ptr.h" | |
19 #include "base/metrics/histogram_base.h" | |
20 #include "base/metrics/histogram_samples.h" | |
21 #include "base/metrics/persistent_memory_allocator.h" | |
22 | |
23 namespace base { | |
24 | |
25 class BASE_EXPORT PersistentSampleMap : public HistogramSamples { | |
Alexei Svitkine (slow)
2016/03/14 18:49:00
Add a comment. Mention it shares logic for SampleM
bcwhite
2016/03/15 00:00:21
Done.
| |
26 public: | |
27 PersistentSampleMap(uint64_t id, | |
28 PersistentMemoryAllocator* allocator, | |
29 Metadata* meta); | |
30 ~PersistentSampleMap() override; | |
31 | |
32 // HistogramSamples: | |
33 void Accumulate(HistogramBase::Sample value, | |
34 HistogramBase::Count count) override; | |
35 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; | |
36 HistogramBase::Count TotalCount() const override; | |
37 scoped_ptr<SampleCountIterator> Iterator() const override; | |
38 | |
39 protected: | |
40 // Performs arithemetic. |op| is ADD or SUBTRACT. | |
41 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override; | |
42 | |
43 // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL | |
44 // if sample does not exist. | |
45 HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value); | |
46 | |
47 // Gets a pointer to a "count" corresponding to a given |value|, creating | |
48 // the sample (initialized to zero) if it does not already exists. | |
49 HistogramBase::Count* GetOrCreateSampleCountStorage( | |
50 HistogramBase::Sample value); | |
51 | |
52 private: | |
53 enum : HistogramBase::Sample { kAllSamples = -1 }; | |
54 | |
55 // Imports samples from persistent memory by iterating over all sample | |
56 // records found therein, adding them to the sample_counts_ map. If a | |
57 // count for the sample |until_value| is found, stop the import and return | |
58 // a pointer to that counter. If that value is not found, null will be | |
59 // returned after all currently available samples have been loaded. Pass | |
60 // kAllSamples to force the importing of all available samples. | |
61 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value); | |
62 | |
63 // All created/loaded sample values and their associated counts. The storage | |
64 // for the actual Count numbers is owned by the |allocator_|. | |
65 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_; | |
66 | |
67 // The persistent memory allocator holding samples and an iterator through it. | |
68 PersistentMemoryAllocator* allocator_; | |
69 PersistentMemoryAllocator::Iterator sample_iter_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap); | |
72 }; | |
73 | |
74 } // namespace base | |
75 | |
76 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ | |
OLD | NEW |