Index: base/trace_event/winheap_dump_provider_win.cc |
diff --git a/base/trace_event/winheap_dump_provider_win.cc b/base/trace_event/winheap_dump_provider_win.cc |
index e1e9bcf4a7c454bbdfb1daf72b1c266c0eea7132..82bb01646f9f909e2fd13b8062e355314efb4b40 100644 |
--- a/base/trace_event/winheap_dump_provider_win.cc |
+++ b/base/trace_event/winheap_dump_provider_win.cc |
@@ -7,6 +7,7 @@ |
#include <windows.h> |
#include "base/trace_event/process_memory_dump.h" |
+#include "base/win/windows_version.h" |
namespace base { |
namespace trace_event { |
@@ -16,19 +17,23 @@ namespace { |
// Report a heap dump to a process memory dump. The |heap_info| structure |
// contains the information about this heap, and |dump_absolute_name| will be |
// used to represent it in the report. |
-bool ReportHeapDump(ProcessMemoryDump* pmd, |
+void ReportHeapDump(ProcessMemoryDump* pmd, |
const WinHeapInfo& heap_info, |
const std::string& dump_absolute_name) { |
- MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_absolute_name); |
- if (!dump) |
- return false; |
- dump->AddScalar(MemoryAllocatorDump::kNameOuterSize, |
- MemoryAllocatorDump::kUnitsBytes, heap_info.committed_size); |
- dump->AddScalar(MemoryAllocatorDump::kNameInnerSize, |
- MemoryAllocatorDump::kUnitsBytes, heap_info.allocated_size); |
- dump->AddScalar(MemoryAllocatorDump::kNameObjectsCount, |
- MemoryAllocatorDump::kUnitsObjects, heap_info.block_count); |
- return true; |
+ MemoryAllocatorDump* outer_dump = |
+ pmd->CreateAllocatorDump(dump_absolute_name); |
+ outer_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
+ MemoryAllocatorDump::kUnitsBytes, |
+ heap_info.committed_size); |
+ |
+ MemoryAllocatorDump* inner_dump = |
+ pmd->CreateAllocatorDump(dump_absolute_name + "/allocated_objects"); |
+ inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
+ MemoryAllocatorDump::kUnitsBytes, |
+ heap_info.allocated_size); |
+ inner_dump->AddScalar(MemoryAllocatorDump::kNameObjectsCount, |
+ MemoryAllocatorDump::kUnitsObjects, |
+ heap_info.block_count); |
} |
} // namespace |
@@ -39,6 +44,21 @@ WinHeapDumpProvider* WinHeapDumpProvider::GetInstance() { |
} |
bool WinHeapDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { |
+ // This method might be flaky for 2 reasons: |
+ // - GetProcessHeaps is racy by design. It returns a snapshot of the |
+ // available heaps, but there's no guarantee that that snapshot remains |
+ // valid. If a heap disappears between GetProcessHeaps() and HeapWalk() |
+ // then chaos should be assumed. This flakyness is acceptable for tracing. |
+ // - The MSDN page for HeapLock says: "If the HeapLock function is called on |
+ // a heap created with the HEAP_NO_SERIALIZATION flag, the results are |
+ // undefined.". This is a problem on Windows XP where some system DLLs are |
+ // known for creating heaps with this particular flag. For this reason |
+ // this function should be disabled on XP. |
+ // |
+ // See https://crbug.com/487291 for more details about this. |
+ if (base::win::GetVersion() < base::win::VERSION_VISTA) |
+ return false; |
+ |
// Retrieves the number of heaps in the current process. |
DWORD number_of_heaps = ::GetProcessHeaps(0, NULL); |
WinHeapInfo all_heap_info = {0}; |
@@ -68,9 +88,7 @@ bool WinHeapDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { |
all_heap_info.block_count += heap_info.block_count; |
} |
// Report the heap dump. |
- if (!ReportHeapDump(pmd, all_heap_info, "winheap")) |
- return false; |
- |
+ ReportHeapDump(pmd, all_heap_info, "winheap"); |
return true; |
} |