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 // Enumerate possible creation results for reporting. | |
17 enum CreateHistogramResultType { | |
Alexei Svitkine (slow)
2016/01/22 16:15:16
Move this to the .cc file in the anon namespace.
bcwhite
2016/01/22 17:17:48
I had it there but given that GetCreateHistogramRe
Alexei Svitkine (slow)
2016/01/22 17:23:40
Hmm, but it's only public for tests, right? In tha
| |
18 // Everything was fine. | |
19 CREATE_HISTOGRAM_SUCCESS = 0, | |
20 | |
21 // Pointer to metadata was not valid. | |
22 CREATE_HISTOGRAM_INVALID_METADATA_POINTER, | |
23 | |
24 // Histogram metadata was not valid. | |
25 CREATE_HISTOGRAM_INVALID_METADATA, | |
26 | |
27 // Ranges information was not valid. | |
28 CREATE_HISTOGRAM_INVALID_RANGES_ARRAY, | |
29 | |
30 // Counts information was not valid. | |
31 CREATE_HISTOGRAM_INVALID_COUNTS_ARRAY, | |
32 | |
33 // Could not allocate histogram memory due to corruption. | |
34 CREATE_HISTOGRAM_ALLOCATOR_CORRUPT, | |
35 | |
36 // Could not allocate histogram memory due to lack of space. | |
37 CREATE_HISTOGRAM_ALLOCATOR_FULL, | |
38 | |
39 // Could not allocate histogram memory due to unknown error. | |
40 CREATE_HISTOGRAM_ALLOCATOR_ERROR, | |
41 | |
42 // Always keep this at the end. | |
43 CREATE_HISTOGRAM_MAX | |
44 }; | |
45 | |
46 // Feature definition for enabling histogram persistence. | |
47 BASE_EXPORT extern const Feature kPersistentHistogramsFeature; | |
48 | |
49 // Histogram containing creation results. Visible for testing. | |
50 BASE_EXPORT HistogramBase* GetCreateHistogramResultHistogram(); | |
51 | |
52 // Access a PersistentMemoryAllocator for storing histograms in space that | |
53 // can be persisted or shared between processes. There is only ever one | |
54 // allocator for all such histograms created by a single process though one | |
55 // process may access the histograms created by other processes if it has a | |
56 // handle on its memory segment. This takes ownership of the object and | |
57 // should not be changed without great care as it is likely that there will | |
58 // be pointers to data held in that space. | |
59 BASE_EXPORT void SetPersistentHistogramMemoryAllocator( | |
60 PersistentMemoryAllocator* allocator); | |
61 BASE_EXPORT PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator(); | |
62 | |
63 // This access to the persistent allocator is only for testing; it extracts | |
64 // the current allocator completely. This allows easy creation of histograms | |
65 // within persistent memory segments which can then be extracted and used | |
66 // in other ways. | |
67 BASE_EXPORT PersistentMemoryAllocator* | |
68 ReleasePersistentHistogramMemoryAllocator(); | |
69 | |
70 // Recreate a Histogram from data held in persistent memory. Though this | |
71 // object will be local to the current process, the sample data will be | |
72 // shared with all other threads referencing it. This method takes a |ref| | |
73 // to the top- level histogram data and the |allocator| on which it is found. | |
74 // This method will return nullptr if any problem is detected with the data. | |
75 // The |allocator| may or may not be the same as the PersistentMemoryAllocator | |
76 // set for general use so that this method can be used to extract Histograms | |
77 // from persistent memory segments other than the default place that this | |
78 // process is creating its own histograms. The caller must take ownership of | |
79 // the returned object and destroy it when no longer needed. | |
80 BASE_EXPORT HistogramBase* GetPersistentHistogram( | |
81 PersistentMemoryAllocator* allocator, | |
82 int32_t ref); | |
83 | |
84 // Get the next histogram in persistent data based on iterator. The caller | |
85 // must take ownership of the returned object and destroy it when no longer | |
86 // needed. | |
87 BASE_EXPORT HistogramBase* GetNextPersistentHistogram( | |
88 PersistentMemoryAllocator* allocator, | |
89 PersistentMemoryAllocator::Iterator* iter); | |
90 | |
91 // Finalize the creation of the histogram, making it available to other | |
92 // processes if it is the registered instance. | |
93 void FinalizePersistentHistogram(PersistentMemoryAllocator::Reference ref, | |
94 bool register); | |
95 | |
96 // Allocate a new persistent histogram. This does *not* make the object | |
97 // iterable in the allocator; call MakeIterable(ref) directly if that is | |
98 // desired. | |
99 BASE_EXPORT HistogramBase* AllocatePersistentHistogram( | |
100 PersistentMemoryAllocator* allocator, | |
101 HistogramType histogram_type, | |
102 const std::string& name, | |
103 int minimum, | |
104 int maximum, | |
105 const BucketRanges* bucket_ranges, | |
106 int32_t flags, | |
107 PersistentMemoryAllocator::Reference* ref_ptr); | |
108 | |
109 // Import new histograms from attached PersistentMemoryAllocator. It's | |
110 // possible for other processes to create histograms in the attached memory | |
111 // segment; this adds those to the internal list of known histograms to | |
112 // avoid creating duplicates that would have to merged during reporting. | |
113 // Every call to this method resumes from the last entry it saw so it costs | |
114 // nothing if nothing new has been added. | |
115 void ImportPersistentHistograms(); | |
116 | |
117 } // namespace base | |
118 | |
119 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | |
OLD | NEW |