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 <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/hash_tables.h" |
|
petrcermak
2016/02/22 13:33:25
Do you still need this include?
Primiano Tucci (use gerrit)
2016/02/22 15:56:07
Good spot. Removed.
| |
| 14 #include "base/containers/small_map.h" | |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/trace_event/memory_allocator_dump.h" | 18 #include "base/trace_event/memory_allocator_dump.h" |
| 19 #include "base/trace_event/memory_allocator_dump_guid.h" | 19 #include "base/trace_event/memory_allocator_dump_guid.h" |
| 20 #include "base/trace_event/memory_dump_session_state.h" | 20 #include "base/trace_event/memory_dump_session_state.h" |
| 21 #include "base/trace_event/process_memory_maps.h" | 21 #include "base/trace_event/process_memory_maps.h" |
| 22 #include "base/trace_event/process_memory_totals.h" | 22 #include "base/trace_event/process_memory_totals.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 | 24 |
| 25 // Define COUNT_RESIDENT_BYTES_SUPPORTED if platform supports counting of the | 25 // Define COUNT_RESIDENT_BYTES_SUPPORTED if platform supports counting of the |
| 26 // resident memory. | 26 // resident memory. |
| 27 // TODO(crbug.com/542671): COUNT_RESIDENT_BYTES_SUPPORTED is disabled on iOS | 27 // TODO(crbug.com/542671): COUNT_RESIDENT_BYTES_SUPPORTED is disabled on iOS |
| 28 // as it cause memory corruption on iOS 9.0+ devices. | 28 // as it cause memory corruption on iOS 9.0+ devices. |
| 29 #if (defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_IOS)) || \ | 29 #if (defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_IOS)) || \ |
| 30 defined(OS_WIN) | 30 defined(OS_WIN) |
| 31 #define COUNT_RESIDENT_BYTES_SUPPORTED | 31 #define COUNT_RESIDENT_BYTES_SUPPORTED |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 namespace base { | 34 namespace base { |
| 35 namespace trace_event { | 35 namespace trace_event { |
| 36 | 36 |
| 37 class ConvertableToTraceFormat; | |
| 38 class MemoryDumpManager; | 37 class MemoryDumpManager; |
| 39 class MemoryDumpSessionState; | 38 class MemoryDumpSessionState; |
| 40 class TracedValue; | 39 class TracedValue; |
| 41 | 40 |
| 42 // ProcessMemoryDump is as a strongly typed container which holds the dumps | 41 // ProcessMemoryDump is as a strongly typed container which holds the dumps |
| 43 // produced by the MemoryDumpProvider(s) for a specific process. | 42 // produced by the MemoryDumpProvider(s) for a specific process. |
| 44 class BASE_EXPORT ProcessMemoryDump { | 43 class BASE_EXPORT ProcessMemoryDump { |
| 45 public: | 44 public: |
| 46 struct MemoryAllocatorDumpEdge { | 45 struct MemoryAllocatorDumpEdge { |
| 47 MemoryAllocatorDumpGuid source; | 46 MemoryAllocatorDumpGuid source; |
| 48 MemoryAllocatorDumpGuid target; | 47 MemoryAllocatorDumpGuid target; |
| 49 int importance; | 48 int importance; |
| 50 const char* type; | 49 const char* type; |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to | 52 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to |
| 54 // MemoryAllocatorDump instances. | 53 // MemoryAllocatorDump instances. |
| 55 using AllocatorDumpsMap = | 54 using AllocatorDumpsMap = |
| 56 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; | 55 std::unordered_map<std::string, scoped_ptr<MemoryAllocatorDump>>; |
| 57 | 56 |
| 58 using HeapDumpsMap = | 57 using HeapDumpsMap = |
| 59 SmallMap<hash_map<std::string, scoped_refptr<TracedValue>>>; | 58 std::unordered_map<std::string, scoped_refptr<TracedValue>>; |
| 60 | 59 |
| 61 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 60 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 62 // Returns the total bytes resident for a virtual address range, with given | 61 // 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 | 62 // |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 | 63 // value returned is valid only if the given range is currently mmapped by the |
| 65 // process. The |start_address| must be page-aligned. | 64 // process. The |start_address| must be page-aligned. |
| 66 static size_t CountResidentBytes(void* start_address, size_t mapped_size); | 65 static size_t CountResidentBytes(void* start_address, size_t mapped_size); |
| 67 #endif | 66 #endif |
| 68 | 67 |
| 69 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); | 68 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 void AsValueInto(TracedValue* value) const; | 163 void AsValueInto(TracedValue* value) const; |
| 165 | 164 |
| 166 ProcessMemoryTotals* process_totals() { return &process_totals_; } | 165 ProcessMemoryTotals* process_totals() { return &process_totals_; } |
| 167 bool has_process_totals() const { return has_process_totals_; } | 166 bool has_process_totals() const { return has_process_totals_; } |
| 168 void set_has_process_totals() { has_process_totals_ = true; } | 167 void set_has_process_totals() { has_process_totals_ = true; } |
| 169 | 168 |
| 170 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } | 169 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } |
| 171 bool has_process_mmaps() const { return has_process_mmaps_; } | 170 bool has_process_mmaps() const { return has_process_mmaps_; } |
| 172 void set_has_process_mmaps() { has_process_mmaps_ = true; } | 171 void set_has_process_mmaps() { has_process_mmaps_ = true; } |
| 173 | 172 |
| 173 const HeapDumpsMap& heap_dumps() const { return heap_dumps_; } | |
| 174 | |
| 174 private: | 175 private: |
| 175 void AddAllocatorDumpInternal(MemoryAllocatorDump* mad); | 176 MemoryAllocatorDump* AddAllocatorDumpInternal( |
| 177 scoped_ptr<MemoryAllocatorDump> mad); | |
| 176 | 178 |
| 177 ProcessMemoryTotals process_totals_; | 179 ProcessMemoryTotals process_totals_; |
| 178 bool has_process_totals_; | 180 bool has_process_totals_; |
| 179 | 181 |
| 180 ProcessMemoryMaps process_mmaps_; | 182 ProcessMemoryMaps process_mmaps_; |
| 181 bool has_process_mmaps_; | 183 bool has_process_mmaps_; |
| 182 | 184 |
| 183 AllocatorDumpsMap allocator_dumps_; | 185 AllocatorDumpsMap allocator_dumps_; |
| 184 HeapDumpsMap heap_dumps_; | 186 HeapDumpsMap heap_dumps_; |
| 185 | 187 |
| 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. | 188 // State shared among all PMDs instances created in a given trace session. |
| 190 scoped_refptr<MemoryDumpSessionState> session_state_; | 189 scoped_refptr<MemoryDumpSessionState> session_state_; |
| 191 | 190 |
| 192 // Keeps track of relationships between MemoryAllocatorDump(s). | 191 // Keeps track of relationships between MemoryAllocatorDump(s). |
| 193 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; | 192 std::vector<MemoryAllocatorDumpEdge> allocator_dumps_edges_; |
| 194 | 193 |
| 195 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); | 194 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); |
| 196 }; | 195 }; |
| 197 | 196 |
| 198 } // namespace trace_event | 197 } // namespace trace_event |
| 199 } // namespace base | 198 } // namespace base |
| 200 | 199 |
| 201 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 200 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
| OLD | NEW |