Commit 7415a3db authored by tasak's avatar tasak Committed by Commit bot

Make GetMallocUsages to check only the default process heap.

BUG=671459
TBR=avi@chromium.org

Review-Url: https://codereview.chromium.org/2565273002
Cr-Commit-Position: refs/heads/master@{#437819}
parent 7028deb3
......@@ -1809,31 +1809,20 @@ void RenderThreadImpl::OnProcessPurgeAndSuspend() {
namespace {
static size_t GetMallocUsage() {
DWORD number_of_heaps = ::GetProcessHeaps(0, NULL);
if (number_of_heaps <= 0)
// Only checks the default process heap.
HANDLE heap = ::GetProcessHeap();
if (heap == NULL)
return 0;
if (!::HeapLock(heap))
return 0 ;
size_t malloc_usage = 0;
std::unique_ptr<HANDLE[]> heaps(new HANDLE[number_of_heaps]);
// If some heaps were gone between the first GetProcessHeaps and here,
// GetProcessHeaps obtains small number of heaps.
// If some new heaps were available between the first GetProcessHeaps and
// here, GetProcessHeaps returns larger number than number_of_heaps.
// So we need to see min(number_of_obtained_heaps, number_of_heaps).
DWORD number_of_obtained_heaps =
::GetProcessHeaps(number_of_heaps, heaps.get());
for (size_t i = 0; i < number_of_heaps && i < number_of_obtained_heaps; i++) {
PROCESS_HEAP_ENTRY heap_entry;
::HeapLock(heaps[i]);
heap_entry.lpData = NULL;
while (::HeapWalk(heaps[i], &heap_entry) != 0) {
if (heap_entry.lpData == heaps.get())
continue;
if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0)
malloc_usage += heap_entry.cbData;
}
::HeapUnlock(heaps[i]);
PROCESS_HEAP_ENTRY heap_entry;
heap_entry.lpData = NULL;
while (::HeapWalk(heap, &heap_entry) != 0) {
if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0)
malloc_usage += heap_entry.cbData;
}
::HeapUnlock(heap);
return malloc_usage;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment