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