OLD | NEW |
---|---|
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 5 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/shared_memory.h" | |
11 #include "base/metrics/histogram_base.h" | 12 #include "base/metrics/histogram_base.h" |
12 #include "base/metrics/persistent_memory_allocator.h" | 13 #include "base/metrics/persistent_memory_allocator.h" |
14 #include "base/strings/string_piece.h" | |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 | 17 |
18 class SharedPersistentMemoryAllocator; | |
19 | |
16 // Feature definition for enabling histogram persistence. | 20 // Feature definition for enabling histogram persistence. |
17 BASE_EXPORT extern const Feature kPersistentHistogramsFeature; | 21 BASE_EXPORT extern const Feature kPersistentHistogramsFeature; |
18 | 22 |
19 // Histogram containing creation results. Visible for testing. | 23 // Histogram containing creation results. Visible for testing. |
20 BASE_EXPORT HistogramBase* GetCreateHistogramResultHistogram(); | 24 BASE_EXPORT HistogramBase* GetCreateHistogramResultHistogram(); |
21 | 25 |
22 // Access a PersistentMemoryAllocator for storing histograms in space that | 26 // Access a PersistentMemoryAllocator for storing histograms in space that |
23 // can be persisted or shared between processes. There is only ever one | 27 // 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 | 28 // 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 | 29 // 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 | 30 // 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 | 31 // 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 | 32 // 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 | 33 // possible during startup to capture as many histograms as possible and |
30 // while operating single-threaded so there are no race-conditions. | 34 // while operating single-threaded so there are no race-conditions. |
31 BASE_EXPORT void SetPersistentHistogramMemoryAllocator( | 35 BASE_EXPORT void SetPersistentHistogramMemoryAllocator( |
32 PersistentMemoryAllocator* allocator); | 36 PersistentMemoryAllocator* allocator); |
33 BASE_EXPORT PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator(); | 37 BASE_EXPORT PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator(); |
34 | 38 |
35 // This access to the persistent allocator is only for testing; it extracts | 39 // This access to the persistent allocator is only for testing; it extracts |
36 // the current allocator completely. This allows easy creation of histograms | 40 // the current allocator completely. This allows easy creation of histograms |
37 // within persistent memory segments which can then be extracted and used | 41 // within persistent memory segments which can then be extracted and used |
38 // in other ways. | 42 // in other ways. |
39 BASE_EXPORT PersistentMemoryAllocator* | 43 BASE_EXPORT PersistentMemoryAllocator* |
40 ReleasePersistentHistogramMemoryAllocatorForTesting(); | 44 ReleasePersistentHistogramMemoryAllocatorForTesting(); |
41 | 45 |
46 // Create a sharable memory segment with an attached persistent memory | |
47 // allocator suitable for storing histograms. This segment can be shared | |
48 // with other processes via an IPC message and used to create the same | |
49 // on the other side. | |
Alexei Svitkine (slow)
2016/03/24 17:29:53
Please document the params better. What's id? What
| |
50 BASE_EXPORT SharedPersistentMemoryAllocator* | |
51 CreateSharedPersistentHistogramMemoryAllocator( | |
52 size_t size, | |
53 StringPiece name, | |
54 uint64_t id); | |
55 BASE_EXPORT SharedPersistentMemoryAllocator* | |
56 CreateSharedPersistentHistogramMemoryAllocator( | |
Alexei Svitkine (slow)
2016/03/24 17:29:52
Overloads are generally discouraged. Please use di
| |
57 size_t size, | |
58 const SharedMemoryHandle& handle, | |
59 bool readonly); | |
60 | |
42 // Recreate a Histogram from data held in persistent memory. Though this | 61 // 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 | 62 // 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| | 63 // 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. | 64 // 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. | 65 // 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 | 66 // 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 | 67 // 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 | 68 // from persistent memory segments other than the default place that this |
50 // process is creating its own histograms. The caller must take ownership of | 69 // process is creating its own histograms. The caller must take ownership of |
51 // the returned object and destroy it when no longer needed. | 70 // the returned object and destroy it when no longer needed. |
(...skipping 30 matching lines...) Expand all Loading... | |
82 // possible for other processes to create histograms in the attached memory | 101 // possible for other processes to create histograms in the attached memory |
83 // segment; this adds those to the internal list of known histograms to | 102 // segment; this adds those to the internal list of known histograms to |
84 // avoid creating duplicates that would have to merged during reporting. | 103 // 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 | 104 // Every call to this method resumes from the last entry it saw so it costs |
86 // nothing if nothing new has been added. | 105 // nothing if nothing new has been added. |
87 void ImportPersistentHistograms(); | 106 void ImportPersistentHistograms(); |
88 | 107 |
89 } // namespace base | 108 } // namespace base |
90 | 109 |
91 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 110 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
OLD | NEW |