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

Unified Diff: third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp

Issue 1642023007: Refactoring: Move functions from WebMemoryDumpProviderAdapter to PartitionAllocMemoryDumpProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: primiano's review Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
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..b96fdb7ce7abd6ab2f7fa7d1838a65f20caae817 100644
--- a/third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp
+++ b/third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp
@@ -4,6 +4,11 @@
#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/process_memory_dump.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 +20,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 +109,19 @@ PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance()
bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump)
{
+ if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed && m_isHeapProfilingEnabled) {
+ 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);
+ }
+ memoryDump->dumpHeapUsage(bytesByContext, overhead, "partition_alloc");
+ }
+
PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail);
WebMemoryAllocatorDump* partitionsDump = memoryDump->createMemoryAllocatorDump(
@@ -110,6 +138,8 @@ bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail l
}
PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider()
+ : m_allocationRegister(adoptPtr(new base::trace_event::AllocationRegister()))
+ , m_isHeapProfilingEnabled(false)
{
}
@@ -117,12 +147,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
« no previous file with comments | « third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.h ('k') | third_party/WebKit/public/platform/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698