Chromium Code Reviews| Index: base/metrics/histogram.h |
| diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h |
| index 28bb29b6e3dbae6c2e32a37d516c52ad78c3c8df..a2d3d01cde78ec9d0e3a3141757e12647742ae97 100644 |
| --- a/base/metrics/histogram.h |
| +++ b/base/metrics/histogram.h |
| @@ -92,6 +92,7 @@ class BooleanHistogram; |
| class CustomHistogram; |
| class Histogram; |
| class LinearHistogram; |
| +class PersistentMemoryAllocator; |
| class Pickle; |
| class PickleIterator; |
| class SampleVector; |
| @@ -138,6 +139,14 @@ class BASE_EXPORT Histogram : public HistogramBase { |
| size_t bucket_count, |
| int32_t flags); |
| + static HistogramBase* PersistentGet(const char* name, |
|
Alexei Svitkine (slow)
2016/01/12 21:54:44
Add a comment, please.
bcwhite
2016/01/13 13:38:29
Done.
|
| + Sample minimum, |
| + Sample maximum, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + size_t counts_size, |
| + HistogramSamples::Metadata* meta); |
| + |
| static void InitializeBucketRanges(Sample minimum, |
| Sample maximum, |
| BucketRanges* ranges); |
| @@ -193,6 +202,13 @@ class BASE_EXPORT Histogram : public HistogramBase { |
| void WriteAscii(std::string* output) const override; |
| protected: |
| + // This class, defined entirely within the .cc file, contains all the |
| + // common logic for building a Histogram and can be overridden by more |
| + // specific types to alter details of how the creation is done. It is |
| + // defined as an embedded class (rather than an anonymous one) so it |
| + // can access the protected constructors. |
| + class Factory; |
| + |
| // |ranges| should contain the underflow and overflow buckets. See top |
| // comments for example. |
| Histogram(const std::string& name, |
| @@ -200,6 +216,20 @@ class BASE_EXPORT Histogram : public HistogramBase { |
| Sample maximum, |
| const BucketRanges* ranges); |
| + // Traditionally, histograms allocate their own memory for the bucket |
| + // vector but "shared" histograms use memory regions allocated from a |
| + // special memory segment that is passed in here. It is assumed that |
| + // the life of this memory is managed externally and exceeds the lifetime |
| + // of this object. Practically, this memory is never released until the |
| + // process exits and the OS cleans it up. |
| + Histogram(const std::string& name, |
| + Sample minimum, |
| + Sample maximum, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + size_t counts_size, |
| + HistogramSamples::Metadata* meta); |
| + |
| ~Histogram() override; |
| // HistogramBase implementation: |
| @@ -313,6 +343,14 @@ class BASE_EXPORT LinearHistogram : public Histogram { |
| size_t bucket_count, |
| int32_t flags); |
| + static HistogramBase* PersistentGet(const char* name, |
| + Sample minimum, |
| + Sample maximum, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + size_t counts_size, |
| + HistogramSamples::Metadata* meta); |
| + |
| struct DescriptionPair { |
| Sample sample; |
| const char* description; // Null means end of a list of pairs. |
| @@ -339,11 +377,21 @@ class BASE_EXPORT LinearHistogram : public Histogram { |
| HistogramType GetHistogramType() const override; |
| protected: |
| + class Factory; |
| + |
| LinearHistogram(const std::string& name, |
| Sample minimum, |
| Sample maximum, |
| const BucketRanges* ranges); |
| + LinearHistogram(const std::string& name, |
|
Alexei Svitkine (slow)
2016/01/12 21:54:44
Please add a comment to these extra constructors.
bcwhite
2016/01/13 13:38:29
There's one big descriptive comment for the one in
|
| + Sample minimum, |
| + Sample maximum, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + size_t counts_size, |
| + HistogramSamples::Metadata* meta); |
| + |
| double GetBucketSize(Count current, size_t i) const override; |
| // If we have a description for a bucket, then return that. Otherwise |
| @@ -380,10 +428,22 @@ class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
| // call sites. |
| static HistogramBase* FactoryGet(const char* name, int32_t flags); |
| + static HistogramBase* PersistentGet(const char* name, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + HistogramSamples::Metadata* meta); |
| + |
| HistogramType GetHistogramType() const override; |
| + protected: |
| + class Factory; |
| + |
| private: |
| BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
| + BooleanHistogram(const std::string& name, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + HistogramSamples::Metadata* meta); |
| friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( |
| base::PickleIterator* iter); |
| @@ -412,6 +472,12 @@ class BASE_EXPORT CustomHistogram : public Histogram { |
| const std::vector<Sample>& custom_ranges, |
| int32_t flags); |
| + static HistogramBase* PersistentGet(const char* name, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + size_t counts_size, |
| + HistogramSamples::Metadata* meta); |
| + |
| // Overridden from Histogram: |
| HistogramType GetHistogramType() const override; |
| @@ -424,9 +490,17 @@ class BASE_EXPORT CustomHistogram : public Histogram { |
| static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
| size_t num_values); |
| protected: |
| + class Factory; |
| + |
| CustomHistogram(const std::string& name, |
| const BucketRanges* ranges); |
| + CustomHistogram(const std::string& name, |
| + const BucketRanges* ranges, |
| + HistogramBase::AtomicCount* counts, |
| + size_t counts_size, |
| + HistogramSamples::Metadata* meta); |
| + |
| // HistogramBase implementation: |
| bool SerializeInfoImpl(base::Pickle* pickle) const override; |
| @@ -438,8 +512,6 @@ class BASE_EXPORT CustomHistogram : public Histogram { |
| static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
| static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
| - static BucketRanges* CreateBucketRangesFromCustomRanges( |
| - const std::vector<Sample>& custom_ranges); |
| DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| }; |