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

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

Issue 1718173002: tracing: memory-infra cleanup post-C++11 + test coverage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@incwhatyouuse
Patch Set: Re petrcermak review Created 4 years, 10 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
« no previous file with comments | « no previous file | base/trace_event/process_memory_dump.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <unordered_map>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/base_export.h" 13 #include "base/base_export.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/containers/small_map.h"
15 #include "base/macros.h" 14 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
18 #include "base/trace_event/memory_allocator_dump.h" 17 #include "base/trace_event/memory_allocator_dump.h"
19 #include "base/trace_event/memory_allocator_dump_guid.h" 18 #include "base/trace_event/memory_allocator_dump_guid.h"
20 #include "base/trace_event/memory_dump_session_state.h" 19 #include "base/trace_event/memory_dump_session_state.h"
21 #include "base/trace_event/process_memory_maps.h" 20 #include "base/trace_event/process_memory_maps.h"
22 #include "base/trace_event/process_memory_totals.h" 21 #include "base/trace_event/process_memory_totals.h"
23 #include "build/build_config.h" 22 #include "build/build_config.h"
24 23
25 // Define COUNT_RESIDENT_BYTES_SUPPORTED if platform supports counting of the 24 // Define COUNT_RESIDENT_BYTES_SUPPORTED if platform supports counting of the
26 // resident memory. 25 // resident memory.
27 // TODO(crbug.com/542671): COUNT_RESIDENT_BYTES_SUPPORTED is disabled on iOS 26 // TODO(crbug.com/542671): COUNT_RESIDENT_BYTES_SUPPORTED is disabled on iOS
28 // as it cause memory corruption on iOS 9.0+ devices. 27 // as it cause memory corruption on iOS 9.0+ devices.
29 #if (defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_IOS)) || \ 28 #if (defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_IOS)) || \
30 defined(OS_WIN) 29 defined(OS_WIN)
31 #define COUNT_RESIDENT_BYTES_SUPPORTED 30 #define COUNT_RESIDENT_BYTES_SUPPORTED
32 #endif 31 #endif
33 32
34 namespace base { 33 namespace base {
35 namespace trace_event { 34 namespace trace_event {
36 35
37 class ConvertableToTraceFormat;
38 class MemoryDumpManager; 36 class MemoryDumpManager;
39 class MemoryDumpSessionState; 37 class MemoryDumpSessionState;
40 class TracedValue; 38 class TracedValue;
41 39
42 // ProcessMemoryDump is as a strongly typed container which holds the dumps 40 // ProcessMemoryDump is as a strongly typed container which holds the dumps
43 // produced by the MemoryDumpProvider(s) for a specific process. 41 // produced by the MemoryDumpProvider(s) for a specific process.
44 class BASE_EXPORT ProcessMemoryDump { 42 class BASE_EXPORT ProcessMemoryDump {
45 public: 43 public:
46 struct MemoryAllocatorDumpEdge { 44 struct MemoryAllocatorDumpEdge {
47 MemoryAllocatorDumpGuid source; 45 MemoryAllocatorDumpGuid source;
48 MemoryAllocatorDumpGuid target; 46 MemoryAllocatorDumpGuid target;
49 int importance; 47 int importance;
50 const char* type; 48 const char* type;
51 }; 49 };
52 50
53 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to 51 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to
54 // MemoryAllocatorDump instances. 52 // MemoryAllocatorDump instances.
55 using AllocatorDumpsMap = 53 using AllocatorDumpsMap =
56 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; 54 std::unordered_map<std::string, scoped_ptr<MemoryAllocatorDump>>;
57 55
58 using HeapDumpsMap = 56 using HeapDumpsMap =
59 SmallMap<hash_map<std::string, scoped_refptr<TracedValue>>>; 57 std::unordered_map<std::string, scoped_refptr<TracedValue>>;
60 58
61 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) 59 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED)
62 // Returns the total bytes resident for a virtual address range, with given 60 // Returns the total bytes resident for a virtual address range, with given
63 // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The 61 // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The
64 // value returned is valid only if the given range is currently mmapped by the 62 // value returned is valid only if the given range is currently mmapped by the
65 // process. The |start_address| must be page-aligned. 63 // process. The |start_address| must be page-aligned.
66 static size_t CountResidentBytes(void* start_address, size_t mapped_size); 64 static size_t CountResidentBytes(void* start_address, size_t mapped_size);
67 #endif 65 #endif
68 66
69 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); 67 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void AsValueInto(TracedValue* value) const; 162 void AsValueInto(TracedValue* value) const;
165 163
166 ProcessMemoryTotals* process_totals() { return &process_totals_; } 164 ProcessMemoryTotals* process_totals() { return &process_totals_; }
167 bool has_process_totals() const { return has_process_totals_; } 165 bool has_process_totals() const { return has_process_totals_; }
168 void set_has_process_totals() { has_process_totals_ = true; } 166 void set_has_process_totals() { has_process_totals_ = true; }
169 167
170 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } 168 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; }
171 bool has_process_mmaps() const { return has_process_mmaps_; } 169 bool has_process_mmaps() const { return has_process_mmaps_; }
172 void set_has_process_mmaps() { has_process_mmaps_ = true; } 170 void set_has_process_mmaps() { has_process_mmaps_ = true; }
173 171
172 const HeapDumpsMap& heap_dumps() const { return heap_dumps_; }
173
174 private: 174 private:
175 void AddAllocatorDumpInternal(MemoryAllocatorDump* mad); 175 MemoryAllocatorDump* AddAllocatorDumpInternal(
176 scoped_ptr<MemoryAllocatorDump> mad);
176 177
177 ProcessMemoryTotals process_totals_; 178 ProcessMemoryTotals process_totals_;
178 bool has_process_totals_; 179 bool has_process_totals_;
179 180
180 ProcessMemoryMaps process_mmaps_; 181 ProcessMemoryMaps process_mmaps_;
181 bool has_process_mmaps_; 182 bool has_process_mmaps_;
182 183
183 AllocatorDumpsMap allocator_dumps_; 184 AllocatorDumpsMap allocator_dumps_;
184 HeapDumpsMap heap_dumps_; 185 HeapDumpsMap heap_dumps_;
185 186
186 // ProcessMemoryDump handles the memory ownership of all its belongings.
187 ScopedVector<MemoryAllocatorDump> allocator_dumps_storage_;
188
189 // State shared among all PMDs instances created in a given trace session. 187 // State shared among all PMDs instances created in a given trace session.
190 scoped_refptr<MemoryDumpSessionState> session_state_; 188 scoped_refptr<MemoryDumpSessionState> session_state_;
191 189
192 // Keeps track of relationships between MemoryAllocatorDump(s). 190 // Keeps track of relationships between MemoryAllocatorDump(s).
193 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; 191 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_;
194 192
195 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); 193 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump);
196 }; 194 };
197 195
198 } // namespace trace_event 196 } // namespace trace_event
199 } // namespace base 197 } // namespace base
200 198
201 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ 199 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/process_memory_dump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698