OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 5 #ifndef BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #if defined(OS_POSIX) && !defined(OS_NACL) | 23 #if defined(OS_POSIX) && !defined(OS_NACL) |
24 #define COUNT_RESIDENT_BYTES_SUPPORTED | 24 #define COUNT_RESIDENT_BYTES_SUPPORTED |
25 #endif | 25 #endif |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 namespace trace_event { | 28 namespace trace_event { |
29 | 29 |
30 class ConvertableToTraceFormat; | 30 class ConvertableToTraceFormat; |
31 class MemoryDumpManager; | 31 class MemoryDumpManager; |
32 class MemoryDumpSessionState; | 32 class MemoryDumpSessionState; |
| 33 class TracedValue; |
33 | 34 |
34 // ProcessMemoryDump is as a strongly typed container which holds the dumps | 35 // ProcessMemoryDump is as a strongly typed container which holds the dumps |
35 // produced by the MemoryDumpProvider(s) for a specific process. | 36 // produced by the MemoryDumpProvider(s) for a specific process. |
36 class BASE_EXPORT ProcessMemoryDump { | 37 class BASE_EXPORT ProcessMemoryDump { |
37 public: | 38 public: |
38 struct MemoryAllocatorDumpEdge { | 39 struct MemoryAllocatorDumpEdge { |
39 MemoryAllocatorDumpGuid source; | 40 MemoryAllocatorDumpGuid source; |
40 MemoryAllocatorDumpGuid target; | 41 MemoryAllocatorDumpGuid target; |
41 int importance; | 42 int importance; |
42 const char* type; | 43 const char* type; |
43 }; | 44 }; |
44 | 45 |
45 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to | 46 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to |
46 // MemoryAllocatorDump instances. | 47 // MemoryAllocatorDump instances. |
47 using AllocatorDumpsMap = | 48 using AllocatorDumpsMap = |
48 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; | 49 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; |
49 | 50 |
| 51 using HeapDumpsMap = |
| 52 SmallMap<hash_map<std::string, scoped_refptr<TracedValue>>>; |
| 53 |
50 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 54 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
51 // Returns the total bytes resident for a virtual address range, with given | 55 // Returns the total bytes resident for a virtual address range, with given |
52 // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The | 56 // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The |
53 // value returned is valid only if the given range is currently mmapped by the | 57 // value returned is valid only if the given range is currently mmapped by the |
54 // process. The |start_address| must be page-aligned. | 58 // process. The |start_address| must be page-aligned. |
55 static size_t CountResidentBytes(void* start_address, size_t mapped_size); | 59 static size_t CountResidentBytes(void* start_address, size_t mapped_size); |
56 #endif | 60 #endif |
57 | 61 |
58 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); | 62 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); |
59 ~ProcessMemoryDump(); | 63 ~ProcessMemoryDump(); |
(...skipping 28 matching lines...) Expand all Loading... |
88 MemoryAllocatorDump* CreateSharedGlobalAllocatorDump( | 92 MemoryAllocatorDump* CreateSharedGlobalAllocatorDump( |
89 const MemoryAllocatorDumpGuid& guid); | 93 const MemoryAllocatorDumpGuid& guid); |
90 | 94 |
91 // Looks up a shared MemoryAllocatorDump given its guid. | 95 // Looks up a shared MemoryAllocatorDump given its guid. |
92 MemoryAllocatorDump* GetSharedGlobalAllocatorDump( | 96 MemoryAllocatorDump* GetSharedGlobalAllocatorDump( |
93 const MemoryAllocatorDumpGuid& guid) const; | 97 const MemoryAllocatorDumpGuid& guid) const; |
94 | 98 |
95 // Returns the map of the MemoryAllocatorDumps added to this dump. | 99 // Returns the map of the MemoryAllocatorDumps added to this dump. |
96 const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; } | 100 const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; } |
97 | 101 |
| 102 // Adds a heap dump for the allocator with |absolute_name|. The |TracedValue| |
| 103 // must have the correct format. |trace_event::HeapDumper| will generate such |
| 104 // a value from a |trace_event::AllocationRegister|. |
| 105 void AddHeapDump(const std::string& absolute_name, |
| 106 scoped_refptr<TracedValue> heap_dump); |
| 107 |
98 // Adds an ownership relationship between two MemoryAllocatorDump(s) with the | 108 // Adds an ownership relationship between two MemoryAllocatorDump(s) with the |
99 // semantics: |source| owns |target|, and has the effect of attributing | 109 // semantics: |source| owns |target|, and has the effect of attributing |
100 // the memory usage of |target| to |source|. |importance| is optional and | 110 // the memory usage of |target| to |source|. |importance| is optional and |
101 // relevant only for the cases of co-ownership, where it acts as a z-index: | 111 // relevant only for the cases of co-ownership, where it acts as a z-index: |
102 // the owner with the highest importance will be attributed |target|'s memory. | 112 // the owner with the highest importance will be attributed |target|'s memory. |
103 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 113 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
104 const MemoryAllocatorDumpGuid& target, | 114 const MemoryAllocatorDumpGuid& target, |
105 int importance); | 115 int importance); |
106 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 116 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
107 const MemoryAllocatorDumpGuid& target); | 117 const MemoryAllocatorDumpGuid& target); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 private: | 158 private: |
149 void AddAllocatorDumpInternal(MemoryAllocatorDump* mad); | 159 void AddAllocatorDumpInternal(MemoryAllocatorDump* mad); |
150 | 160 |
151 ProcessMemoryTotals process_totals_; | 161 ProcessMemoryTotals process_totals_; |
152 bool has_process_totals_; | 162 bool has_process_totals_; |
153 | 163 |
154 ProcessMemoryMaps process_mmaps_; | 164 ProcessMemoryMaps process_mmaps_; |
155 bool has_process_mmaps_; | 165 bool has_process_mmaps_; |
156 | 166 |
157 AllocatorDumpsMap allocator_dumps_; | 167 AllocatorDumpsMap allocator_dumps_; |
| 168 HeapDumpsMap heap_dumps_; |
158 | 169 |
159 // ProcessMemoryDump handles the memory ownership of all its belongings. | 170 // ProcessMemoryDump handles the memory ownership of all its belongings. |
160 ScopedVector<MemoryAllocatorDump> allocator_dumps_storage_; | 171 ScopedVector<MemoryAllocatorDump> allocator_dumps_storage_; |
161 | 172 |
162 // State shared among all PMDs instances created in a given trace session. | 173 // State shared among all PMDs instances created in a given trace session. |
163 scoped_refptr<MemoryDumpSessionState> session_state_; | 174 scoped_refptr<MemoryDumpSessionState> session_state_; |
164 | 175 |
165 // Keeps track of relationships between MemoryAllocatorDump(s). | 176 // Keeps track of relationships between MemoryAllocatorDump(s). |
166 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; | 177 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; |
167 | 178 |
168 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); | 179 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); |
169 }; | 180 }; |
170 | 181 |
171 } // namespace trace_event | 182 } // namespace trace_event |
172 } // namespace base | 183 } // namespace base |
173 | 184 |
174 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 185 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
OLD | NEW |