OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 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 // 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 { | |
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, stopping after importing | |
Alexei Svitkine (slow)
2016/03/08 19:46:25
I don't understand what Import means in this conte
bcwhite
2016/03/09 01:16:52
Done.
| |
56 // |until_value| or when there is nothing left to import. Pass kAllSamples | |
Alexei Svitkine (slow)
2016/03/08 19:46:25
What does "stopping after importing |until_value|"
bcwhite
2016/03/09 01:16:52
It's the latter.
I had -1 originally documented i
Alexei Svitkine (slow)
2016/03/09 20:35:19
Okay. I guess it doesn't matter too much either wa
| |
57 // to import everything. Returns a pointer to the count for |until_value| | |
58 // if it is found, NULL otherwise. | |
Alexei Svitkine (slow)
2016/03/08 19:46:25
Nit: NULL -> null
bcwhite
2016/03/09 01:16:52
Done.
| |
59 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value); | |
60 | |
61 // All created/loaded sample values and their associated counts. | |
Alexei Svitkine (slow)
2016/03/08 19:46:25
Expand on ownership.
bcwhite
2016/03/09 01:16:52
Done.
| |
62 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_; | |
63 | |
64 // The persistent memory allocator holding samples and an iterator through it. | |
65 PersistentMemoryAllocator* allocator_; | |
66 PersistentMemoryAllocator::Iterator sample_iter_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap); | |
69 }; | |
70 | |
71 class BASE_EXPORT PersistentSampleMapIterator : public SampleCountIterator { | |
Alexei Svitkine (slow)
2016/03/08 19:46:25
This class shouldn't be used directly by clients,
bcwhite
2016/03/09 01:16:52
That works. Would you like me to do the same to S
Alexei Svitkine (slow)
2016/03/09 20:35:19
Yes, please. :)
bcwhite
2016/03/09 22:57:33
Done.
| |
72 public: | |
73 typedef std::map<HistogramBase::Sample, HistogramBase::Count*> | |
74 SampleToCountMap; | |
75 | |
76 explicit PersistentSampleMapIterator(const SampleToCountMap& sample_counts); | |
77 ~PersistentSampleMapIterator() override; | |
78 | |
79 // SampleCountIterator: | |
80 bool Done() const override; | |
81 void Next() override; | |
82 void Get(HistogramBase::Sample* min, | |
83 HistogramBase::Sample* max, | |
84 HistogramBase::Count* count) const override; | |
85 | |
86 private: | |
87 void SkipEmptyBuckets(); | |
88 | |
89 SampleToCountMap::const_iterator iter_; | |
90 const SampleToCountMap::const_iterator end_; | |
91 }; | |
92 | |
93 } // namespace base | |
94 | |
95 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ | |
OLD | NEW |