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 // Finalize the creation of the histogram, making it available to other | |
66 // processes if it is the registered instance. | |
67 void FinalizePersistentHistogram(PersistentMemoryAllocator::Reference ref, | |
68 bool register); | |
Alexei Svitkine (slow)
2016/01/08 18:52:48
Nit: codereview is highlighting "register" because
bcwhite
2016/01/12 16:34:57
Done.
| |
69 | |
70 // Allocate a new persistent histogram. This does *not* make the object | |
71 // iterable in the allocator; call MakeIterable(ref) directly if that is | |
72 // desired. | |
73 BASE_EXPORT HistogramBase* AllocatePersistentHistogram( | |
74 PersistentMemoryAllocator* allocator, | |
75 HistogramType histogram_type, | |
76 const std::string& name, | |
77 int minimum, | |
78 int maximum, | |
79 const BucketRanges* bucket_ranges, | |
80 int32 flags, | |
81 PersistentMemoryAllocator::Reference* ref_ptr); | |
82 | |
83 // Import new histograms from attached PersistentMemoryAllocator. It's | |
84 // possible for other processes to create histograms in the attached memory | |
85 // segment; this adds those to the internal list of known histograms to | |
86 // avoid creating duplicates that would have to merged during reporting. | |
87 // Every call to this method resumes from the last entry it saw so it costs | |
88 // nothing if nothing new has been added. | |
89 void ImportPersistentHistograms(); | |
90 | |
91 } // namespace base | |
92 | |
93 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | |
OLD | NEW |