OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
| 6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/feature_list.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram_base.h" |
| 12 #include "base/metrics/persistent_memory_allocator.h" |
| 13 |
| 14 namespace base { |
| 15 |
| 16 BASE_EXPORT extern const Feature kPersistentHistogramsFeature; |
| 17 |
| 18 // Access a PersistentMemoryAllocator for storing histograms in space that |
| 19 // can be persisted or shared between processes. There is only ever one |
| 20 // allocator for all such histograms created by a single process though one |
| 21 // process may access the histograms created by other processes if it has a |
| 22 // handle on its memory segment. This takes ownership of the object and |
| 23 // should not be changed without great care as it is likely that there will |
| 24 // be pointers to data held in that space. |
| 25 BASE_EXPORT void SetPersistentHistogramMemoryAllocator( |
| 26 PersistentMemoryAllocator* allocator); |
| 27 BASE_EXPORT PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator(); |
| 28 |
| 29 // This access to the persistent allocator is only for testing; it extracts |
| 30 // the current allocator completely. This allows easy creation of histograms |
| 31 // within persistent memory segments which can then be extracted and used |
| 32 // in other ways. |
| 33 BASE_EXPORT PersistentMemoryAllocator* |
| 34 ReleasePersistentHistogramMemoryAllocator(); |
| 35 |
| 36 // Recreate a Histogram from data held in persistent memory. Though this |
| 37 // object will be local to the current process, the sample data will be |
| 38 // shared with all other threads referencing it. This method takes a |ref| |
| 39 // to the top- level histogram data and the |allocator| on which it is found. |
| 40 // This method will return nullptr if any problem is detected with the data. |
| 41 // The |allocator| may or may not be the same as the PersistentMemoryAllocator |
| 42 // set for general use so that this method can be used to extract Histograms |
| 43 // from persistent memory segments other than the default place that this |
| 44 // process is creating its own histograms. The caller must take ownership of |
| 45 // the returned object and destroy it when no longer needed. |
| 46 BASE_EXPORT HistogramBase* GetPersistentHistogram( |
| 47 PersistentMemoryAllocator* allocator, |
| 48 int32_t ref); |
| 49 |
| 50 // Get the next histogram in persistent data based on iterator. The caller |
| 51 // must take ownership of the returned object and destroy it when no longer |
| 52 // needed. |
| 53 BASE_EXPORT HistogramBase* GetNextPersistentHistogram( |
| 54 PersistentMemoryAllocator* allocator, |
| 55 PersistentMemoryAllocator::Iterator* iter); |
| 56 |
| 57 // Finalize the creation of the histogram, making it available to other |
| 58 // processes if it is the registered instance. |
| 59 void FinalizePersistentHistogram(PersistentMemoryAllocator::Reference ref, |
| 60 bool register); |
| 61 |
| 62 // Allocate a new persistent histogram. This does *not* make the object |
| 63 // iterable in the allocator; call MakeIterable(ref) directly if that is |
| 64 // desired. |
| 65 BASE_EXPORT HistogramBase* AllocatePersistentHistogram( |
| 66 PersistentMemoryAllocator* allocator, |
| 67 HistogramType histogram_type, |
| 68 const std::string& name, |
| 69 int minimum, |
| 70 int maximum, |
| 71 const BucketRanges* bucket_ranges, |
| 72 int32_t flags, |
| 73 PersistentMemoryAllocator::Reference* ref_ptr); |
| 74 |
| 75 // Import new histograms from attached PersistentMemoryAllocator. It's |
| 76 // possible for other processes to create histograms in the attached memory |
| 77 // segment; this adds those to the internal list of known histograms to |
| 78 // avoid creating duplicates that would have to merged during reporting. |
| 79 // Every call to this method resumes from the last entry it saw so it costs |
| 80 // nothing if nothing new has been added. |
| 81 void ImportPersistentHistograms(); |
| 82 |
| 83 } // namespace base |
| 84 |
| 85 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
OLD | NEW |