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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <map> |
10 #include <unordered_map> | 11 #include <unordered_map> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/base_export.h" | 14 #include "base/base_export.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
17 #include "base/trace_event/memory_allocator_dump.h" | 18 #include "base/trace_event/memory_allocator_dump.h" |
18 #include "base/trace_event/memory_allocator_dump_guid.h" | 19 #include "base/trace_event/memory_allocator_dump_guid.h" |
19 #include "base/trace_event/memory_dump_request_args.h" | 20 #include "base/trace_event/memory_dump_request_args.h" |
(...skipping 16 matching lines...) Expand all Loading... |
36 | 37 |
37 // ProcessMemoryDump is as a strongly typed container which holds the dumps | 38 // ProcessMemoryDump is as a strongly typed container which holds the dumps |
38 // produced by the MemoryDumpProvider(s) for a specific process. | 39 // produced by the MemoryDumpProvider(s) for a specific process. |
39 class BASE_EXPORT ProcessMemoryDump { | 40 class BASE_EXPORT ProcessMemoryDump { |
40 public: | 41 public: |
41 struct MemoryAllocatorDumpEdge { | 42 struct MemoryAllocatorDumpEdge { |
42 MemoryAllocatorDumpGuid source; | 43 MemoryAllocatorDumpGuid source; |
43 MemoryAllocatorDumpGuid target; | 44 MemoryAllocatorDumpGuid target; |
44 int importance; | 45 int importance; |
45 const char* type; | 46 const char* type; |
| 47 bool overridable; |
46 }; | 48 }; |
47 | 49 |
48 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to | 50 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to |
49 // MemoryAllocatorDump instances. | 51 // MemoryAllocatorDump instances. |
50 using AllocatorDumpsMap = | 52 using AllocatorDumpsMap = |
51 std::unordered_map<std::string, std::unique_ptr<MemoryAllocatorDump>>; | 53 std::unordered_map<std::string, std::unique_ptr<MemoryAllocatorDump>>; |
52 | 54 |
53 using HeapDumpsMap = | 55 using HeapDumpsMap = |
54 std::unordered_map<std::string, std::unique_ptr<TracedValue>>; | 56 std::unordered_map<std::string, std::unique_ptr<TracedValue>>; |
55 | 57 |
| 58 // Stores allocator dump edges indexed by source allocator dump GUID. |
| 59 using AllocatorDumpEdgesMap = |
| 60 std::map<MemoryAllocatorDumpGuid, MemoryAllocatorDumpEdge>; |
| 61 |
56 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 62 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
57 // Returns the number of bytes in a kernel memory page. Some platforms may | 63 // Returns the number of bytes in a kernel memory page. Some platforms may |
58 // have a different value for kernel page sizes from user page sizes. It is | 64 // have a different value for kernel page sizes from user page sizes. It is |
59 // important to use kernel memory page sizes for resident bytes calculation. | 65 // important to use kernel memory page sizes for resident bytes calculation. |
60 // In most cases, the two are the same. | 66 // In most cases, the two are the same. |
61 static size_t GetSystemPageSize(); | 67 static size_t GetSystemPageSize(); |
62 | 68 |
63 // Returns the total bytes resident for a virtual address range, with given | 69 // Returns the total bytes resident for a virtual address range, with given |
64 // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The | 70 // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The |
65 // value returned is valid only if the given range is currently mmapped by the | 71 // value returned is valid only if the given range is currently mmapped by the |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // semantics: |source| owns |target|, and has the effect of attributing | 134 // semantics: |source| owns |target|, and has the effect of attributing |
129 // the memory usage of |target| to |source|. |importance| is optional and | 135 // the memory usage of |target| to |source|. |importance| is optional and |
130 // relevant only for the cases of co-ownership, where it acts as a z-index: | 136 // relevant only for the cases of co-ownership, where it acts as a z-index: |
131 // the owner with the highest importance will be attributed |target|'s memory. | 137 // the owner with the highest importance will be attributed |target|'s memory. |
132 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 138 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
133 const MemoryAllocatorDumpGuid& target, | 139 const MemoryAllocatorDumpGuid& target, |
134 int importance); | 140 int importance); |
135 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 141 void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
136 const MemoryAllocatorDumpGuid& target); | 142 const MemoryAllocatorDumpGuid& target); |
137 | 143 |
138 const std::vector<MemoryAllocatorDumpEdge>& allocator_dumps_edges() const { | 144 // Adds edges that can be overriden by a later or earlier call to |
| 145 // AddOwnershipEdge() with the same source and target with a different |
| 146 // |importance| value. |
| 147 void AddOverridableOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
| 148 const MemoryAllocatorDumpGuid& target, |
| 149 int importance); |
| 150 |
| 151 const AllocatorDumpEdgesMap& allocator_dumps_edges_for_testing() const { |
139 return allocator_dumps_edges_; | 152 return allocator_dumps_edges_; |
140 } | 153 } |
141 | 154 |
142 // Utility method to add a suballocation relationship with the following | 155 // Utility method to add a suballocation relationship with the following |
143 // semantics: |source| is suballocated from |target_node_name|. | 156 // semantics: |source| is suballocated from |target_node_name|. |
144 // This creates a child node of |target_node_name| and adds an ownership edge | 157 // This creates a child node of |target_node_name| and adds an ownership edge |
145 // between |source| and the new child node. As a result, the UI will not | 158 // between |source| and the new child node. As a result, the UI will not |
146 // account the memory of |source| in the target node. | 159 // account the memory of |source| in the target node. |
147 void AddSuballocation(const MemoryAllocatorDumpGuid& source, | 160 void AddSuballocation(const MemoryAllocatorDumpGuid& source, |
148 const std::string& target_node_name); | 161 const std::string& target_node_name); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 ProcessMemoryMaps process_mmaps_; | 206 ProcessMemoryMaps process_mmaps_; |
194 bool has_process_mmaps_; | 207 bool has_process_mmaps_; |
195 | 208 |
196 AllocatorDumpsMap allocator_dumps_; | 209 AllocatorDumpsMap allocator_dumps_; |
197 HeapDumpsMap heap_dumps_; | 210 HeapDumpsMap heap_dumps_; |
198 | 211 |
199 // State shared among all PMDs instances created in a given trace session. | 212 // State shared among all PMDs instances created in a given trace session. |
200 scoped_refptr<MemoryDumpSessionState> session_state_; | 213 scoped_refptr<MemoryDumpSessionState> session_state_; |
201 | 214 |
202 // Keeps track of relationships between MemoryAllocatorDump(s). | 215 // Keeps track of relationships between MemoryAllocatorDump(s). |
203 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; | 216 AllocatorDumpEdgesMap allocator_dumps_edges_; |
204 | 217 |
205 // Level of detail of the current dump. | 218 // Level of detail of the current dump. |
206 const MemoryDumpArgs dump_args_; | 219 const MemoryDumpArgs dump_args_; |
207 | 220 |
208 // This allocator dump is returned when an invalid dump is created in | 221 // This allocator dump is returned when an invalid dump is created in |
209 // background mode. The attributes of the dump are ignored and not added to | 222 // background mode. The attributes of the dump are ignored and not added to |
210 // the trace. | 223 // the trace. |
211 std::unique_ptr<MemoryAllocatorDump> black_hole_mad_; | 224 std::unique_ptr<MemoryAllocatorDump> black_hole_mad_; |
212 | 225 |
213 // When set to true, the DCHECK(s) for invalid dump creations on the | 226 // When set to true, the DCHECK(s) for invalid dump creations on the |
214 // background mode are disabled for testing. | 227 // background mode are disabled for testing. |
215 static bool is_black_hole_non_fatal_for_testing_; | 228 static bool is_black_hole_non_fatal_for_testing_; |
216 | 229 |
217 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); | 230 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); |
218 }; | 231 }; |
219 | 232 |
220 } // namespace trace_event | 233 } // namespace trace_event |
221 } // namespace base | 234 } // namespace base |
222 | 235 |
223 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 236 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
OLD | NEW |