Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // SampleMap implements HistogramSamples interface. It is used by the | 5 // SampleMap implements HistogramSamples interface. It is used by the |
| 6 // SparseHistogram class to store samples. | 6 // SparseHistogram class to store samples. |
| 7 | 7 |
| 8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ | 8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ |
| 9 #define BASE_METRICS_SAMPLE_MAP_H_ | 9 #define BASE_METRICS_SAMPLE_MAP_H_ |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/metrics/histogram_base.h" | 18 #include "base/metrics/histogram_base.h" |
| 19 #include "base/metrics/histogram_samples.h" | 19 #include "base/metrics/histogram_samples.h" |
| 20 #include "base/metrics/persistent_memory_allocator.h" | |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 | 23 |
| 23 class BASE_EXPORT SampleMap : public HistogramSamples { | 24 class BASE_EXPORT SampleMap : public HistogramSamples { |
| 24 public: | 25 public: |
| 25 SampleMap(); | 26 SampleMap(); |
| 26 explicit SampleMap(uint64_t id); | 27 explicit SampleMap(uint64_t id); |
| 27 ~SampleMap() override; | 28 ~SampleMap() override; |
| 28 | 29 |
| 29 // HistogramSamples implementation: | 30 // HistogramSamples implementation: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 59 HistogramBase::Sample* max, | 60 HistogramBase::Sample* max, |
| 60 HistogramBase::Count* count) const override; | 61 HistogramBase::Count* count) const override; |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 void SkipEmptyBuckets(); | 64 void SkipEmptyBuckets(); |
| 64 | 65 |
| 65 SampleToCountMap::const_iterator iter_; | 66 SampleToCountMap::const_iterator iter_; |
| 66 const SampleToCountMap::const_iterator end_; | 67 const SampleToCountMap::const_iterator end_; |
| 67 }; | 68 }; |
| 68 | 69 |
| 70 | |
| 71 // A sample-map similar to the above but holds its samples in persistent memory | |
| 72 // in order to be live across process restarts or be shared between processes. | |
| 73 class BASE_EXPORT PersistentSampleMap : public HistogramSamples { | |
| 74 public: | |
| 75 PersistentSampleMap(uint64_t id, | |
| 76 PersistentMemoryAllocator* allocator, | |
| 77 Metadata* meta); | |
| 78 ~PersistentSampleMap() override; | |
| 79 | |
| 80 // HistogramSamples implementation: | |
| 81 void Accumulate(HistogramBase::Sample value, | |
| 82 HistogramBase::Count count) override; | |
| 83 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; | |
| 84 HistogramBase::Count TotalCount() const override; | |
| 85 scoped_ptr<SampleCountIterator> Iterator() const override; | |
| 86 | |
| 87 protected: | |
| 88 // Performs arithemetic. |op| is ADD or SUBTRACT. | |
| 89 bool AddSubtractImpl(SampleCountIterator* iter, | |
| 90 HistogramSamples::Operator op) override; | |
|
grt (UTC plus 2)
2016/03/02 20:00:42
nit: HistogramSamples:: not needed
bcwhite
2016/03/02 22:32:44
Done. Above, too.
| |
| 91 | |
| 92 // Gets a pointer to a "count" corresponding to a given |value|. It can | |
| 93 // optionally create the bucket if it doesn't already exist. | |
| 94 HistogramBase::Count* GetSampleCountPointer(HistogramBase::Sample value, | |
|
grt (UTC plus 2)
2016/03/02 20:00:42
nit: what do you think of GetSampleCountStorage?
bcwhite
2016/03/02 22:32:44
Done.
| |
| 95 bool create_if_necessary); | |
| 96 | |
| 97 private: | |
| 98 // Imports samples from persistent memory, stopping if a particular value | |
|
grt (UTC plus 2)
2016/03/02 20:00:42
is it correct to say "stopping after importing |un
bcwhite
2016/03/02 22:32:44
Done.
| |
| 99 // is found. Pass -1 to import everything. Returns a pointer to the | |
|
grt (UTC plus 2)
2016/03/02 20:00:42
nit: add a private kAllSamples constant like this:
bcwhite
2016/03/02 22:32:43
Done.
| |
| 100 // count for |until_value| if it is found, NULL otherwise. | |
|
grt (UTC plus 2)
2016/03/02 20:00:42
in our post-nullptr world (where we shouldn't use
bcwhite
2016/03/02 22:32:44
Acknowledged.
| |
| 101 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value); | |
| 102 | |
| 103 // All created/loaded sample values and their associated counts. | |
| 104 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_; | |
| 105 | |
| 106 // The persistent memory allocator holding samples and an iterator through it. | |
| 107 PersistentMemoryAllocator* allocator_; | |
| 108 PersistentMemoryAllocator::Iterator sample_iter_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap); | |
| 111 }; | |
| 112 | |
| 113 class BASE_EXPORT PersistentSampleMapIterator : public SampleCountIterator { | |
| 114 public: | |
| 115 typedef std::map<HistogramBase::Sample, HistogramBase::Count*> | |
| 116 SampleToCountMap; | |
| 117 | |
| 118 explicit PersistentSampleMapIterator(const SampleToCountMap& sample_counts); | |
| 119 ~PersistentSampleMapIterator() override; | |
| 120 | |
| 121 // SampleCountIterator implementation: | |
| 122 bool Done() const override; | |
| 123 void Next() override; | |
| 124 void Get(HistogramBase::Sample* min, | |
| 125 HistogramBase::Sample* max, | |
| 126 HistogramBase::Count* count) const override; | |
| 127 | |
| 128 private: | |
| 129 void SkipEmptyBuckets(); | |
| 130 | |
| 131 SampleToCountMap::const_iterator iter_; | |
| 132 const SampleToCountMap::const_iterator end_; | |
| 133 }; | |
| 134 | |
| 69 } // namespace base | 135 } // namespace base |
| 70 | 136 |
| 71 #endif // BASE_METRICS_SAMPLE_MAP_H_ | 137 #endif // BASE_METRICS_SAMPLE_MAP_H_ |
| OLD | NEW |