| Index: third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp
|
| diff --git a/third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp b/third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp
|
| index fec85c042be7c276827f6c5d325d415c302acc8c..47c8f4f94a8a8bdc2d0fd57db806c5a6339f5e38 100644
|
| --- a/third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp
|
| +++ b/third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp
|
| @@ -4,6 +4,13 @@
|
|
|
| #include "platform/PartitionAllocMemoryDumpProvider.h"
|
|
|
| +#include "base/trace_event/heap_profiler_allocation_context.h"
|
| +#include "base/trace_event/heap_profiler_allocation_context_tracker.h"
|
| +#include "base/trace_event/heap_profiler_allocation_register.h"
|
| +#include "base/trace_event/heap_profiler_heap_dump_writer.h"
|
| +#include "base/trace_event/process_memory_dump.h"
|
| +#include "base/trace_event/trace_event_argument.h"
|
| +#include "base/trace_event/trace_event_memory_overhead.h"
|
| #include "public/platform/WebMemoryAllocatorDump.h"
|
| #include "public/platform/WebProcessMemoryDump.h"
|
| #include "wtf/Partitions.h"
|
| @@ -15,6 +22,16 @@ namespace {
|
|
|
| using namespace WTF;
|
|
|
| +void reportAllocation(void* address, size_t size, const char* typeName)
|
| +{
|
| + PartitionAllocMemoryDumpProvider::instance()->insert(address, size, typeName);
|
| +}
|
| +
|
| +void reportFree(void* address)
|
| +{
|
| + PartitionAllocMemoryDumpProvider::instance()->remove(address);
|
| +}
|
| +
|
| const char kPartitionAllocDumpName[] = "partition_alloc";
|
| const char kPartitionsDumpName[] = "partitions";
|
|
|
| @@ -94,6 +111,23 @@ PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance()
|
|
|
| bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump)
|
| {
|
| + if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed && m_isHeapProfilingEnabled) {
|
| + base::trace_event::ProcessMemoryDump* pmd = memoryDump->getProcessMemoryDump();
|
| + base::trace_event::TraceEventMemoryOverhead overhead;
|
| + base::hash_map<base::trace_event::AllocationContext, size_t> bytesByContext;
|
| + {
|
| + MutexLocker locker(m_allocationRegisterMutex);
|
| + for (const auto& allocSize : *m_allocationRegister)
|
| + bytesByContext[allocSize.context] += allocSize.size;
|
| +
|
| + m_allocationRegister->EstimateTraceMemoryOverhead(&overhead);
|
| + }
|
| +
|
| + scoped_refptr<base::trace_event::TracedValue> heapDump = ExportHeapDump(bytesByContext, pmd->session_state()->stack_frame_deduplicator(), pmd->session_state()->type_name_deduplicator());
|
| + pmd->AddHeapDump("partition_alloc", heapDump);
|
| + overhead.DumpInto("tracing/heap_profiler", pmd);
|
| + }
|
| +
|
| PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail);
|
|
|
| WebMemoryAllocatorDump* partitionsDump = memoryDump->createMemoryAllocatorDump(
|
| @@ -110,6 +144,8 @@ bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail l
|
| }
|
|
|
| PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider()
|
| + : m_allocationRegister(adoptPtr(new base::trace_event::AllocationRegister()))
|
| + , m_isHeapProfilingEnabled(false)
|
| {
|
| }
|
|
|
| @@ -117,12 +153,30 @@ PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider()
|
| {
|
| }
|
|
|
| -void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled(AllocationHook* allocationHook, FreeHook* freeHook)
|
| +void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled(bool enabled)
|
| +{
|
| + if (enabled) {
|
| + PartitionAllocHooks::setAllocationHook(reportAllocation);
|
| + PartitionAllocHooks::setFreeHook(reportFree);
|
| + } else {
|
| + PartitionAllocHooks::setAllocationHook(nullptr);
|
| + PartitionAllocHooks::setFreeHook(nullptr);
|
| + }
|
| + m_isHeapProfilingEnabled = enabled;
|
| +}
|
| +
|
| +void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const char* typeName)
|
| +{
|
| + base::trace_event::AllocationContext context = base::trace_event::AllocationContextTracker::GetContextSnapshot();
|
| + context.type_name = typeName;
|
| + MutexLocker locker(m_allocationRegisterMutex);
|
| + m_allocationRegister->Insert(address, size, context);
|
| +}
|
| +
|
| +void PartitionAllocMemoryDumpProvider::remove(void* address)
|
| {
|
| - // Make PartitionAlloc call |allocationHook| and |freeHook| for every
|
| - // subsequent allocation and free (or not if the pointers are null).
|
| - PartitionAllocHooks::setAllocationHook(allocationHook);
|
| - PartitionAllocHooks::setFreeHook(freeHook);
|
| + MutexLocker locker(m_allocationRegisterMutex);
|
| + m_allocationRegister->Remove(address);
|
| }
|
|
|
| } // namespace blink
|
|
|