Chromium Code Reviews| Index: base/metrics/histogram_base.h |
| diff --git a/base/metrics/histogram_base.h b/base/metrics/histogram_base.h |
| index f45cc9c106e323e83791265a57cbefaa3352011b..309e31af68c8d320fc0f72dbd154694e7b0a65e5 100644 |
| --- a/base/metrics/histogram_base.h |
| +++ b/base/metrics/histogram_base.h |
| @@ -13,12 +13,14 @@ |
| #include "base/atomicops.h" |
| #include "base/base_export.h" |
| #include "base/basictypes.h" |
| +#include "base/memory/persistent_memory_allocator.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/string_piece.h" |
| #include "base/time/time.h" |
| namespace base { |
| +class BucketRanges; |
| class DictionaryValue; |
| class HistogramBase; |
| class HistogramSamples; |
| @@ -79,6 +81,13 @@ class BASE_EXPORT HistogramBase { |
| // to shortcut looking up the callback if it doesn't exist. |
| kCallbackExists = 0x20, |
| + // Indicates that the histogram is held in "persistent" memory and may |
| + // be accessible between processes. This is only possible if such a |
| + // memory segment has been created/attached, used to create a Persistent- |
| + // MemoryAllocator, and that loaded into the Histogram module before this |
| + // histogram is created. |
| + kIsPersistent = 0x40, |
| + |
| // Only for Histogram and its sub classes: fancy bucket-naming support. |
| kHexRangePrintingFlag = 0x8000, |
| }; |
| @@ -158,7 +167,53 @@ class BASE_EXPORT HistogramBase { |
| // customize the output. |
| void WriteJSON(std::string* output) const; |
| + // Access a PersistentMemoryAllocator for storing histograms in space that |
| + // can be persisted or shared between processes. There is only ever one |
| + // allocator for all such histograms created by a single process though one |
| + // process may access the histograms created by other processes if it has a |
| + // handle on its memory segment. This takes ownership of the object and |
| + // should not be changed without great care as it is likely that there will |
| + // be pointers to data held in that space. |
| + static void SetDefaultPersistentMemoryAllocator(PersistentMemoryAllocator* a); |
| + static PersistentMemoryAllocator* GetDefaultPersistentMemoryAllocator() { |
| + return allocator_.get(); |
| + } |
| + |
| + // This access to the persistent allocator is only for testing; it extracts |
| + // the current allocator completely. This allows easy creation of histograms |
| + // within persistent memory segments which can then be extracted and used |
| + // in other ways. |
| + static PersistentMemoryAllocator* ReleaseDefaultPersistentMemoryAllocator() { |
| + return allocator_.release(); |
| + }; |
| + |
| + // Recreate a Histogram from data held in persistent memory. Though this |
| + // object will be local to the current process, the sample data will be |
| + // shared with all other threads referencing it. This method takes a |ref| |
| + // to the top- level histogram data and the |allocator| on which it is found. |
| + // This method will return nullptr if any problem is detected with the data. |
| + // The |allocator| may or may not be the same as the PersistentMemoryAllocator |
| + // set for general use so that this method can be used to extract Histograms |
| + // from persistent memory segments other than the default place that this |
| + // process is creating its own histograms. The caller must take ownership of |
| + // the returned object and destroy it when no longer needed. |
| + static HistogramBase* GetPersistentHistogram( |
| + PersistentMemoryAllocator* allocator, |
| + int32_t ref); |
| + |
| + // Get the next histogram in persistent data based on iterator. The caller |
| + // must take ownership of the returned object and destroy it when no longer |
| + // needed. |
| + static HistogramBase* GetNextPersistentHistogram( |
| + PersistentMemoryAllocator* allocator, |
| + PersistentMemoryAllocator::Iterator* iter); |
|
Alexei Svitkine (slow)
2015/12/04 18:27:36
Can you put these in a separate file? HistogramBas
bcwhite
2015/12/07 23:27:19
Done.
|
| + |
| protected: |
| + struct PersistentHistogramData; |
| + |
| + // Global allocator used when histograms should be persistent. |
| + static scoped_ptr<PersistentMemoryAllocator> allocator_; |
| + |
| // Subclasses should implement this function to make SerializeInfo work. |
| virtual bool SerializeInfoImpl(base::Pickle* pickle) const = 0; |
| @@ -190,6 +245,32 @@ class BASE_EXPORT HistogramBase { |
| // passing |sample| as the parameter. |
| void FindAndRunCallback(Sample sample) const; |
| + // Create a histogram based on persistent data. |
| + static HistogramBase* CreatePersistentHistogram( |
| + PersistentMemoryAllocator* allocator, |
| + PersistentHistogramData* histogram_data); |
| + |
| + // Allocate a new persistent histogram. This does *not* make the object |
| + // iterable in the allocator; call MakeIterable(ref) directly if that is |
| + // desired. |
| + static HistogramBase* AllocatePersistentHistogram( |
| + PersistentMemoryAllocator* allocator, |
| + HistogramType histogram_type, |
| + const std::string& name, |
| + int minimum, |
| + int maximum, |
| + const BucketRanges* bucket_ranges, |
| + int32 flags, |
| + PersistentMemoryAllocator::Reference* ref_ptr); |
| + |
| + // Import new histograms from attached PersistentMemoryAllocator. It's |
| + // possible for other processes to create histograms in the attached memory |
| + // segment; this adds those to the internal list of known histograms to |
| + // avoid creating duplicates that would have to merged during reporting. |
| + // Every call to this method resumes from the last entry it saw so it costs |
| + // nothing if nothing new has been added. |
| + static void ImportPersistentHistograms(); |
| + |
| private: |
| const std::string histogram_name_; |
| AtomicCount flags_; |