Chromium Code Reviews| 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" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/containers/small_map.h" | 12 #include "base/containers/small_map.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/trace_event/memory_allocator_dump.h" | 15 #include "base/trace_event/memory_allocator_dump.h" |
| 16 #include "base/trace_event/memory_allocator_dump_guid.h" | 16 #include "base/trace_event/memory_allocator_dump_guid.h" |
| 17 #include "base/trace_event/memory_dump_session_state.h" | 17 #include "base/trace_event/memory_dump_session_state.h" |
| 18 #include "base/trace_event/process_memory_maps.h" | 18 #include "base/trace_event/process_memory_maps.h" |
| 19 #include "base/trace_event/process_memory_totals.h" | 19 #include "base/trace_event/process_memory_totals.h" |
| 20 #include "base/trace_event/trace_event_argument.h" | |
|
Primiano Tucci (use gerrit)
2015/10/26 11:52:07
can't TracedValue be fwd declared here?
Ruud van Asseldonk
2015/10/26 14:51:27
Yes it can. Fixed.
| |
| 20 | 21 |
| 21 // Define COUNT_RESIDENT_BYTES_SUPPORTED if platform supports counting of the | 22 // Define COUNT_RESIDENT_BYTES_SUPPORTED if platform supports counting of the |
| 22 // resident memory. | 23 // resident memory. |
| 23 #if defined(OS_POSIX) && !defined(OS_NACL) | 24 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 24 #define COUNT_RESIDENT_BYTES_SUPPORTED | 25 #define COUNT_RESIDENT_BYTES_SUPPORTED |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 namespace base { | 28 namespace base { |
| 28 namespace trace_event { | 29 namespace trace_event { |
| 29 | 30 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 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 |