Index: base/metrics/sample_map.h |
diff --git a/base/metrics/sample_map.h b/base/metrics/sample_map.h |
index da536e31e676d1e71516caf5c03c535719168451..22139929a5c1f6e455873a719508be454d2a6ce2 100644 |
--- a/base/metrics/sample_map.h |
+++ b/base/metrics/sample_map.h |
@@ -17,6 +17,7 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/metrics/histogram_base.h" |
#include "base/metrics/histogram_samples.h" |
+#include "base/metrics/persistent_memory_allocator.h" |
namespace base { |
@@ -66,6 +67,71 @@ class BASE_EXPORT SampleMapIterator : public SampleCountIterator { |
const SampleToCountMap::const_iterator end_; |
}; |
+ |
+// A sample-map similar to the above but holds its samples in persistent memory |
+// in order to be live across process restarts or be shared between processes. |
+class BASE_EXPORT PersistentSampleMap : public HistogramSamples { |
+ public: |
+ PersistentSampleMap(uint64_t id, |
+ PersistentMemoryAllocator* allocator, |
+ Metadata* meta); |
+ ~PersistentSampleMap() override; |
+ |
+ // HistogramSamples implementation: |
+ void Accumulate(HistogramBase::Sample value, |
+ HistogramBase::Count count) override; |
+ HistogramBase::Count GetCount(HistogramBase::Sample value) const override; |
+ HistogramBase::Count TotalCount() const override; |
+ scoped_ptr<SampleCountIterator> Iterator() const override; |
+ |
+ protected: |
+ // Performs arithemetic. |op| is ADD or SUBTRACT. |
+ bool AddSubtractImpl(SampleCountIterator* iter, |
+ 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.
|
+ |
+ // Gets a pointer to a "count" corresponding to a given |value|. It can |
+ // optionally create the bucket if it doesn't already exist. |
+ 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.
|
+ bool create_if_necessary); |
+ |
+ private: |
+ // 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.
|
+ // 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.
|
+ // 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.
|
+ HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value); |
+ |
+ // All created/loaded sample values and their associated counts. |
+ std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_; |
+ |
+ // The persistent memory allocator holding samples and an iterator through it. |
+ PersistentMemoryAllocator* allocator_; |
+ PersistentMemoryAllocator::Iterator sample_iter_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap); |
+}; |
+ |
+class BASE_EXPORT PersistentSampleMapIterator : public SampleCountIterator { |
+ public: |
+ typedef std::map<HistogramBase::Sample, HistogramBase::Count*> |
+ SampleToCountMap; |
+ |
+ explicit PersistentSampleMapIterator(const SampleToCountMap& sample_counts); |
+ ~PersistentSampleMapIterator() override; |
+ |
+ // SampleCountIterator implementation: |
+ bool Done() const override; |
+ void Next() override; |
+ void Get(HistogramBase::Sample* min, |
+ HistogramBase::Sample* max, |
+ HistogramBase::Count* count) const override; |
+ |
+ private: |
+ void SkipEmptyBuckets(); |
+ |
+ SampleToCountMap::const_iterator iter_; |
+ const SampleToCountMap::const_iterator end_; |
+}; |
+ |
} // namespace base |
#endif // BASE_METRICS_SAMPLE_MAP_H_ |