Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: base/trace_event/winheap_dump_provider_win.cc

Issue 1105143003: [tracing] Simplify the MemoryAllocatorDump API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplif_2
Patch Set: Fix Win build Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/process_memory_dump.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 namespace base { 11 namespace base {
12 namespace trace_event { 12 namespace trace_event {
13 13
14 namespace { 14 namespace {
15 15
16 const char kDumperFriendlyName[] = "winheap";
17
18 // Report a heap dump to a process memory dump. The |heap_info| structure 16 // Report a heap dump to a process memory dump. The |heap_info| structure
19 // contains the information about this heap, and |heap_name| will be used to 17 // contains the information about this heap, and |dump_absolute_name| will be
20 // represent it in the report. 18 // used to represent it in the report.
21 bool ReportHeapDump(ProcessMemoryDump* pmd, 19 bool ReportHeapDump(ProcessMemoryDump* pmd,
22 const WinHeapInfo& heap_info, 20 const WinHeapInfo& heap_info,
23 const std::string& heap_name) { 21 const std::string& dump_absolute_name) {
24 MemoryAllocatorDump* dump = 22 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_absolute_name);
25 pmd->CreateAllocatorDump(kDumperFriendlyName, heap_name);
26 if (!dump) 23 if (!dump)
27 return false; 24 return false;
28 dump->set_physical_size_in_bytes(heap_info.committed_size); 25 dump->AddScalar(MemoryAllocatorDump::kNameOuterSize,
29 dump->set_allocated_objects_count(heap_info.block_count); 26 MemoryAllocatorDump::kUnitsBytes, heap_info.committed_size);
30 dump->set_allocated_objects_size_in_bytes(heap_info.allocated_size); 27 dump->AddScalar(MemoryAllocatorDump::kNameInnerSize,
28 MemoryAllocatorDump::kUnitsBytes, heap_info.allocated_size);
29 dump->AddScalar(MemoryAllocatorDump::kNameObjectsCount,
30 MemoryAllocatorDump::kUnitsObjects, heap_info.block_count);
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
(...skipping 20 matching lines...) Expand all
61 for (size_t i = 0; i < number_of_heaps; ++i) { 61 for (size_t i = 0; i < number_of_heaps; ++i) {
62 WinHeapInfo heap_info = {0}; 62 WinHeapInfo heap_info = {0};
63 heap_info.heap_id = all_heaps[i]; 63 heap_info.heap_id = all_heaps[i];
64 GetHeapInformation(&heap_info, block_to_skip); 64 GetHeapInformation(&heap_info, block_to_skip);
65 65
66 all_heap_info.allocated_size += heap_info.allocated_size; 66 all_heap_info.allocated_size += heap_info.allocated_size;
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, "winheap"))
72 return false; 72 return false;
73 73
74 return true; 74 return true;
75 } 75 }
76 76
77 bool WinHeapDumpProvider::GetHeapInformation( 77 bool WinHeapDumpProvider::GetHeapInformation(
78 WinHeapInfo* heap_info, 78 WinHeapInfo* heap_info,
79 const std::set<void*>& block_to_skip) { 79 const std::set<void*>& block_to_skip) {
80 CHECK(::HeapLock(heap_info->heap_id) == TRUE); 80 CHECK(::HeapLock(heap_info->heap_id) == TRUE);
81 PROCESS_HEAP_ENTRY heap_entry; 81 PROCESS_HEAP_ENTRY heap_entry;
82 heap_entry.lpData = nullptr; 82 heap_entry.lpData = nullptr;
83 // Walk over all the entries in this heap. 83 // Walk over all the entries in this heap.
84 while (::HeapWalk(heap_info->heap_id, &heap_entry) != FALSE) { 84 while (::HeapWalk(heap_info->heap_id, &heap_entry) != FALSE) {
85 if (block_to_skip.count(heap_entry.lpData) == 1) 85 if (block_to_skip.count(heap_entry.lpData) == 1)
86 continue; 86 continue;
87 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { 87 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
88 heap_info->allocated_size += heap_entry.cbData; 88 heap_info->allocated_size += heap_entry.cbData;
89 heap_info->block_count++; 89 heap_info->block_count++;
90 } else if ((heap_entry.wFlags & PROCESS_HEAP_REGION) != 0) { 90 } else if ((heap_entry.wFlags & PROCESS_HEAP_REGION) != 0) {
91 heap_info->committed_size += heap_entry.Region.dwCommittedSize; 91 heap_info->committed_size += heap_entry.Region.dwCommittedSize;
92 } 92 }
93 } 93 }
94 CHECK(::HeapUnlock(heap_info->heap_id) == TRUE); 94 CHECK(::HeapUnlock(heap_info->heap_id) == TRUE);
95 return true; 95 return true;
96 } 96 }
97 97
98 } // namespace trace_event 98 } // namespace trace_event
99 } // namespace base 99 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/process_memory_dump.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698