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/winheap_dump_provider_win.h" | 5 #include "base/trace_event/winheap_dump_provider_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/trace_event/process_memory_dump.h" | 9 #include "base/trace_event/process_memory_dump.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 return true; | 31 return true; |
32 } | 32 } |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 WinHeapDumpProvider* WinHeapDumpProvider::GetInstance() { | 36 WinHeapDumpProvider* WinHeapDumpProvider::GetInstance() { |
37 return Singleton<WinHeapDumpProvider, | 37 return Singleton<WinHeapDumpProvider, |
38 LeakySingletonTraits<WinHeapDumpProvider>>::get(); | 38 LeakySingletonTraits<WinHeapDumpProvider>>::get(); |
39 } | 39 } |
40 | 40 |
41 bool WinHeapDumpProvider::DumpInto(ProcessMemoryDump* pmd) { | 41 bool WinHeapDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { |
42 // Retrieves the number of heaps in the current process. | 42 // Retrieves the number of heaps in the current process. |
43 DWORD number_of_heaps = ::GetProcessHeaps(0, NULL); | 43 DWORD number_of_heaps = ::GetProcessHeaps(0, NULL); |
44 WinHeapInfo all_heap_info = {0}; | 44 WinHeapInfo all_heap_info = {0}; |
45 | 45 |
46 // Try to retrieve a handle to all the heaps owned by this process. Returns | 46 // Try to retrieve a handle to all the heaps owned by this process. Returns |
47 // false if the number of heaps has changed. | 47 // false if the number of heaps has changed. |
48 // | 48 // |
49 // This is inherently racy as is, but it's not something that we observe a lot | 49 // This is inherently racy as is, but it's not something that we observe a lot |
50 // in Chrome, the heaps tend to be created at startup only. | 50 // in Chrome, the heaps tend to be created at startup only. |
51 scoped_ptr<HANDLE[]> all_heaps(new HANDLE[number_of_heaps]); | 51 scoped_ptr<HANDLE[]> all_heaps(new HANDLE[number_of_heaps]); |
(...skipping 15 matching lines...) Expand all Loading... |
67 all_heap_info.committed_size += heap_info.committed_size; | 67 all_heap_info.committed_size += heap_info.committed_size; |
68 all_heap_info.block_count += heap_info.block_count; | 68 all_heap_info.block_count += heap_info.block_count; |
69 } | 69 } |
70 // Report the heap dump. | 70 // Report the heap dump. |
71 if (!ReportHeapDump(pmd, all_heap_info, MemoryAllocatorDump::kRootHeap)) | 71 if (!ReportHeapDump(pmd, all_heap_info, MemoryAllocatorDump::kRootHeap)) |
72 return false; | 72 return false; |
73 | 73 |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 const char* WinHeapDumpProvider::GetFriendlyName() const { | |
78 return kDumperFriendlyName; | |
79 } | |
80 | |
81 bool WinHeapDumpProvider::GetHeapInformation( | 77 bool WinHeapDumpProvider::GetHeapInformation( |
82 WinHeapInfo* heap_info, | 78 WinHeapInfo* heap_info, |
83 const std::set<void*>& block_to_skip) { | 79 const std::set<void*>& block_to_skip) { |
84 CHECK(::HeapLock(heap_info->heap_id) == TRUE); | 80 CHECK(::HeapLock(heap_info->heap_id) == TRUE); |
85 PROCESS_HEAP_ENTRY heap_entry; | 81 PROCESS_HEAP_ENTRY heap_entry; |
86 heap_entry.lpData = nullptr; | 82 heap_entry.lpData = nullptr; |
87 // Walk over all the entries in this heap. | 83 // Walk over all the entries in this heap. |
88 while (::HeapWalk(heap_info->heap_id, &heap_entry) != FALSE) { | 84 while (::HeapWalk(heap_info->heap_id, &heap_entry) != FALSE) { |
89 if (block_to_skip.count(heap_entry.lpData) == 1) | 85 if (block_to_skip.count(heap_entry.lpData) == 1) |
90 continue; | 86 continue; |
91 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { | 87 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { |
92 heap_info->allocated_size += heap_entry.cbData; | 88 heap_info->allocated_size += heap_entry.cbData; |
93 heap_info->block_count++; | 89 heap_info->block_count++; |
94 } else if ((heap_entry.wFlags & PROCESS_HEAP_REGION) != 0) { | 90 } else if ((heap_entry.wFlags & PROCESS_HEAP_REGION) != 0) { |
95 heap_info->committed_size += heap_entry.Region.dwCommittedSize; | 91 heap_info->committed_size += heap_entry.Region.dwCommittedSize; |
96 } | 92 } |
97 } | 93 } |
98 CHECK(::HeapUnlock(heap_info->heap_id) == TRUE); | 94 CHECK(::HeapUnlock(heap_info->heap_id) == TRUE); |
99 return true; | 95 return true; |
100 } | 96 } |
101 | 97 |
102 } // namespace trace_event | 98 } // namespace trace_event |
103 } // namespace base | 99 } // namespace base |
OLD | NEW |