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