Chromium Code Reviews| Index: base/metrics/sample_map.h |
| diff --git a/base/metrics/sample_map.h b/base/metrics/sample_map.h |
| index da536e31e676d1e71516caf5c03c535719168451..6dff4fe13c2a2df2504b935f3fe3add877853c52 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 { |
| @@ -34,9 +35,8 @@ class BASE_EXPORT SampleMap : public HistogramSamples { |
| scoped_ptr<SampleCountIterator> Iterator() const override; |
| protected: |
| - bool AddSubtractImpl( |
| - SampleCountIterator* iter, |
| - HistogramSamples::Operator op) override; // |op| is ADD or SUBTRACT. |
| + // Performs arithemetic. |op| is ADD or SUBTRACT. |
| + bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override; |
| private: |
| std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; |
| @@ -66,6 +66,73 @@ 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 { |
|
Alexei Svitkine (slow)
2016/03/03 17:43:38
I would make a separate file for this.
bcwhite
2016/03/07 15:30:39
Done.
|
| + public: |
| + PersistentSampleMap(uint64_t id, |
| + PersistentMemoryAllocator* allocator, |
| + Metadata* meta); |
| + ~PersistentSampleMap() override; |
| + |
| + // HistogramSamples implementation: |
|
Alexei Svitkine (slow)
2016/03/03 17:43:38
Nit: // HistogramSamples:
bcwhite
2016/03/07 15:30:39
Done. Above, too.
|
| + 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, Operator op) override; |
| + |
| + // 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* GetSampleCountStorage(HistogramBase::Sample value, |
| + bool create_if_necessary); |
| + |
| + private: |
| + enum : HistogramBase::Sample { kAllSamples = -1 }; |
| + |
| + // Imports samples from persistent memory, stopping after importing |
| + // |until_value| or when there is nothing left to import. Pass kAllSamples |
| + // to import everything. Returns a pointer to the count for |until_value| |
| + // if it is found, NULL otherwise. |
| + 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 { |
|
Alexei Svitkine (slow)
2016/03/03 17:43:38
How is this class different than SampleMapIterator
bcwhite
2016/03/07 15:30:39
It operates on a PersistentSampleMap instead of a
|
| + 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_ |