| 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 #include "base/trace_event/malloc_dump_provider.h" | 5 #include "base/trace_event/malloc_dump_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
| 10 #include "base/allocator/allocator_shim.h" | 10 #include "base/allocator/allocator_shim.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 struct WinHeapInfo { | 98 struct WinHeapInfo { |
| 99 size_t committed_size; | 99 size_t committed_size; |
| 100 size_t uncommitted_size; | 100 size_t uncommitted_size; |
| 101 size_t allocated_size; | 101 size_t allocated_size; |
| 102 size_t block_count; | 102 size_t block_count; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // NOTE: crbug.com/665516 | 105 // NOTE: crbug.com/665516 |
| 106 // Unfortunately, there is no safe way to collect information from secondary | 106 // Unfortunately, there is no safe way to collect information from secondary |
| 107 // heaps due to limitations and racy nature of this piece of WinAPI. | 107 // heaps due to limitations and racy nature of this piece of WinAPI. |
| 108 void WinHeapMemoryDumpImpl(WinHeapInfo* main_heap_info) { | 108 void WinHeapMemoryDumpImpl(WinHeapInfo* crt_heap_info) { |
| 109 #if defined(SYZYASAN) | 109 #if defined(SYZYASAN) |
| 110 if (base::debug::IsBinaryInstrumented()) | 110 if (base::debug::IsBinaryInstrumented()) |
| 111 return; | 111 return; |
| 112 #endif | 112 #endif |
| 113 HANDLE main_heap = ::GetProcessHeap(); | 113 |
| 114 ::HeapLock(main_heap); | 114 // Iterate through whichever heap our CRT is using. |
| 115 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
| 116 ::HeapLock(crt_heap); |
| 115 PROCESS_HEAP_ENTRY heap_entry; | 117 PROCESS_HEAP_ENTRY heap_entry; |
| 116 heap_entry.lpData = nullptr; | 118 heap_entry.lpData = nullptr; |
| 117 // Walk over all the entries in the main heap. | 119 // Walk over all the entries in the main heap. |
| 118 while (::HeapWalk(main_heap, &heap_entry) != FALSE) { | 120 while (::HeapWalk(crt_heap, &heap_entry) != FALSE) { |
| 119 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { | 121 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { |
| 120 main_heap_info->allocated_size += heap_entry.cbData; | 122 crt_heap_info->allocated_size += heap_entry.cbData; |
| 121 main_heap_info->block_count++; | 123 crt_heap_info->block_count++; |
| 122 } else if ((heap_entry.wFlags & PROCESS_HEAP_REGION) != 0) { | 124 } else if ((heap_entry.wFlags & PROCESS_HEAP_REGION) != 0) { |
| 123 main_heap_info->committed_size += heap_entry.Region.dwCommittedSize; | 125 crt_heap_info->committed_size += heap_entry.Region.dwCommittedSize; |
| 124 main_heap_info->uncommitted_size += heap_entry.Region.dwUnCommittedSize; | 126 crt_heap_info->uncommitted_size += heap_entry.Region.dwUnCommittedSize; |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 CHECK(::HeapUnlock(main_heap) == TRUE); | 129 CHECK(::HeapUnlock(crt_heap) == TRUE); |
| 128 } | 130 } |
| 129 #endif // defined(OS_WIN) | 131 #endif // defined(OS_WIN) |
| 130 } // namespace | 132 } // namespace |
| 131 | 133 |
| 132 // static | 134 // static |
| 133 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; | 135 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; |
| 134 | 136 |
| 135 // static | 137 // static |
| 136 MallocDumpProvider* MallocDumpProvider::GetInstance() { | 138 MallocDumpProvider* MallocDumpProvider::GetInstance() { |
| 137 return Singleton<MallocDumpProvider, | 139 return Singleton<MallocDumpProvider, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 tid_dumping_heap_ == PlatformThread::CurrentId()) | 313 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 312 return; | 314 return; |
| 313 AutoLock lock(allocation_register_lock_); | 315 AutoLock lock(allocation_register_lock_); |
| 314 if (!allocation_register_) | 316 if (!allocation_register_) |
| 315 return; | 317 return; |
| 316 allocation_register_->Remove(address); | 318 allocation_register_->Remove(address); |
| 317 } | 319 } |
| 318 | 320 |
| 319 } // namespace trace_event | 321 } // namespace trace_event |
| 320 } // namespace base | 322 } // namespace base |
| OLD | NEW |