Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: base/trace_event/process_memory_dump.h

Issue 2911263003: [memory-infra] Add method to override importance of ownership edges (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
32 namespace trace_event { 33 namespace trace_event {
33 34
34 class MemoryDumpSessionState; 35 class MemoryDumpSessionState;
35 class TracedValue; 36 class TracedValue;
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 target; 43 MemoryAllocatorDumpGuid target;
44 int importance; 44 int importance;
45 const char* type; 45 const char* type;
46 bool overridable;
46 }; 47 };
47 48
48 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to 49 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to
49 // MemoryAllocatorDump instances. 50 // MemoryAllocatorDump instances.
50 using AllocatorDumpsMap = 51 using AllocatorDumpsMap =
51 std::unordered_map<std::string, std::unique_ptr<MemoryAllocatorDump>>; 52 std::unordered_map<std::string, std::unique_ptr<MemoryAllocatorDump>>;
52 53
53 using HeapDumpsMap = 54 using HeapDumpsMap =
54 std::unordered_map<std::string, std::unique_ptr<TracedValue>>; 55 std::unordered_map<std::string, std::unique_ptr<TracedValue>>;
55 56
57 // Stores allocator dump edges as a map from source allocator dump guids to
58 // the target.
Primiano Tucci (use gerrit) 2017/06/05 15:23:39 "to the target" part in the comment is false :)
ssid 2017/06/05 17:03:29 Yeah, I was looking for this phrase!
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
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 const AllocatorDumpEdgesMap& allocator_dumps_edges_for_testing() const {
139 return allocator_dumps_edges_; 145 return allocator_dumps_edges_;
140 } 146 }
141 147
142 // Utility method to add a suballocation relationship with the following 148 // Utility method to add a suballocation relationship with the following
143 // semantics: |source| is suballocated from |target_node_name|. 149 // semantics: |source| is suballocated from |target_node_name|.
144 // This creates a child node of |target_node_name| and adds an ownership edge 150 // 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 151 // between |source| and the new child node. As a result, the UI will not
146 // account the memory of |source| in the target node. 152 // account the memory of |source| in the target node.
147 void AddSuballocation(const MemoryAllocatorDumpGuid& source, 153 void AddSuballocation(const MemoryAllocatorDumpGuid& source,
148 const std::string& target_node_name); 154 const std::string& target_node_name);
(...skipping 25 matching lines...) Expand all
174 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } 180 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; }
175 bool has_process_mmaps() const { return has_process_mmaps_; } 181 bool has_process_mmaps() const { return has_process_mmaps_; }
176 void set_has_process_mmaps() { has_process_mmaps_ = true; } 182 void set_has_process_mmaps() { has_process_mmaps_ = true; }
177 183
178 const HeapDumpsMap& heap_dumps() const { return heap_dumps_; } 184 const HeapDumpsMap& heap_dumps() const { return heap_dumps_; }
179 185
180 const MemoryDumpArgs& dump_args() const { return dump_args_; } 186 const MemoryDumpArgs& dump_args() const { return dump_args_; }
181 187
182 private: 188 private:
183 FRIEND_TEST_ALL_PREFIXES(ProcessMemoryDumpTest, BackgroundModeTest); 189 FRIEND_TEST_ALL_PREFIXES(ProcessMemoryDumpTest, BackgroundModeTest);
190 FRIEND_TEST_ALL_PREFIXES(ProcessMemoryDumpTest, OverrideOwnershipEdge);
184 191
185 MemoryAllocatorDump* AddAllocatorDumpInternal( 192 MemoryAllocatorDump* AddAllocatorDumpInternal(
186 std::unique_ptr<MemoryAllocatorDump> mad); 193 std::unique_ptr<MemoryAllocatorDump> mad);
187 194
188 MemoryAllocatorDump* GetBlackHoleMad(); 195 MemoryAllocatorDump* GetBlackHoleMad();
189 196
197 // Adds edges that can be overriden by a later or earlier call to
198 // AddOwnershipEdge() with the same source and target with a different
199 // |importance| value.
200 void AddOverridableOwnershipEdge(const MemoryAllocatorDumpGuid& source,
201 const MemoryAllocatorDumpGuid& target,
202 int importance);
203
190 ProcessMemoryTotals process_totals_; 204 ProcessMemoryTotals process_totals_;
191 bool has_process_totals_; 205 bool has_process_totals_;
192 206
193 ProcessMemoryMaps process_mmaps_; 207 ProcessMemoryMaps process_mmaps_;
194 bool has_process_mmaps_; 208 bool has_process_mmaps_;
195 209
196 AllocatorDumpsMap allocator_dumps_; 210 AllocatorDumpsMap allocator_dumps_;
197 HeapDumpsMap heap_dumps_; 211 HeapDumpsMap heap_dumps_;
198 212
199 // State shared among all PMDs instances created in a given trace session. 213 // State shared among all PMDs instances created in a given trace session.
200 scoped_refptr<MemoryDumpSessionState> session_state_; 214 scoped_refptr<MemoryDumpSessionState> session_state_;
201 215
202 // Keeps track of relationships between MemoryAllocatorDump(s). 216 // Keeps track of relationships between MemoryAllocatorDump(s).
203 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; 217 AllocatorDumpEdgesMap allocator_dumps_edges_;
204 218
205 // Level of detail of the current dump. 219 // Level of detail of the current dump.
206 const MemoryDumpArgs dump_args_; 220 const MemoryDumpArgs dump_args_;
207 221
208 // This allocator dump is returned when an invalid dump is created in 222 // 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 223 // background mode. The attributes of the dump are ignored and not added to
210 // the trace. 224 // the trace.
211 std::unique_ptr<MemoryAllocatorDump> black_hole_mad_; 225 std::unique_ptr<MemoryAllocatorDump> black_hole_mad_;
212 226
213 // When set to true, the DCHECK(s) for invalid dump creations on the 227 // When set to true, the DCHECK(s) for invalid dump creations on the
214 // background mode are disabled for testing. 228 // background mode are disabled for testing.
215 static bool is_black_hole_non_fatal_for_testing_; 229 static bool is_black_hole_non_fatal_for_testing_;
216 230
217 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); 231 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump);
218 }; 232 };
219 233
220 } // namespace trace_event 234 } // namespace trace_event
221 } // namespace base 235 } // namespace base
222 236
223 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ 237 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698