Index: base/metrics/persistent_histogram_allocator.h |
diff --git a/base/metrics/persistent_histogram_allocator.h b/base/metrics/persistent_histogram_allocator.h |
index 61fadafd63ecdbe9b34d6c4b632a587c2de6e02d..c73f7f4b744514fdbd4455b067da077d7ec5bd76 100644 |
--- a/base/metrics/persistent_histogram_allocator.h |
+++ b/base/metrics/persistent_histogram_allocator.h |
@@ -222,6 +222,7 @@ class BASE_EXPORT PersistentHistogramAllocator { |
const char* Name() const { return memory_allocator_->Name(); } |
const void* data() const { return memory_allocator_->data(); } |
size_t length() const { return memory_allocator_->length(); } |
+ size_t size() const { return memory_allocator_->size(); } |
size_t used() const { return memory_allocator_->used(); } |
// Recreate a Histogram from data held in persistent memory. Though this |
@@ -393,18 +394,42 @@ class BASE_EXPORT GlobalHistogramAllocator |
// while operating single-threaded so there are no race-conditions. |
static void Set(std::unique_ptr<GlobalHistogramAllocator> allocator); |
- // Gets a pointer to the global histogram allocator. |
+ // Enables the global persistent allocator. Existing histograms will not be |
+ // affected; only newly created ones will go into the allocator. |
+ static void Enable(); |
+ |
+ // Disables the global persistent allocator. Existing histograms will not be |
+ // affected; newly created histograms will be allocated from the heap. |
+ static void Disable(); |
+ |
+ // Gets a pointer to an enabled global histogram allocator. If a global |
+ // allocator exists but is disabled, this will return null. |
static GlobalHistogramAllocator* Get(); |
+ // Gets a pointer to a global histogram allocator if one exists, even if |
+ // that allocator is disabled. |
+ static GlobalHistogramAllocator* GetEvenIfDisabled(); |
+ |
// 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. |
+ // the current allocator completely regardless whether it is enabled or not. |
+ // This allows easy creation of histograms within persistent memory segments |
+ // which can then be extracted and used in other ways. |
static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); |
+ // Stores a pathname to which the contents of this allocator should be saved |
+ // in order to persist the data for a later use. |
+ void SetPersistentLocation(const FilePath& location); |
+ |
+ // Writes the internal data to a previously set location. This is generally |
+ // called when a process is exiting from a section of code that may not know |
+ // the filesystem. The data is written in an atomic manner. The return value |
+ // indicates success. |
+ bool WriteToPersistentLocation(); |
+ |
private: |
friend class StatisticsRecorder; |
+ // Creates a new global histogram allocator. It will be enabled by default. |
explicit GlobalHistogramAllocator( |
std::unique_ptr<PersistentMemoryAllocator> memory); |
@@ -420,6 +445,9 @@ class BASE_EXPORT GlobalHistogramAllocator |
// iterator to continue the work. |
Iterator import_iterator_; |
+ // The location to which the data should be persisted. |
+ FilePath persistent_location_; |
+ |
DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); |
}; |