Index: Source/platform/heap/ThreadState.cpp |
diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp |
index 1b20f981cf9b388edb60b2582881add495171f4b..fc2967d20d372b12b0e3f2f2207a9576d8b0c951 100644 |
--- a/Source/platform/heap/ThreadState.cpp |
+++ b/Source/platform/heap/ThreadState.cpp |
@@ -39,6 +39,8 @@ |
#include "platform/heap/Heap.h" |
#include "platform/heap/SafePoint.h" |
#include "public/platform/Platform.h" |
+#include "public/platform/WebMemoryAllocatorDump.h" |
+#include "public/platform/WebProcessMemoryDump.h" |
#include "public/platform/WebScheduler.h" |
#include "public/platform/WebThread.h" |
#include "public/platform/WebTraceLocation.h" |
@@ -127,11 +129,18 @@ ThreadState::ThreadState() |
clearHeapAges(); |
m_weakCallbackStack = new CallbackStack(); |
+ |
+ if (Platform::current()->currentThread()) |
+ Platform::current()->registerMemoryDumpProvider(this); |
} |
ThreadState::~ThreadState() |
{ |
checkThread(); |
+ |
+ if (Platform::current()->currentThread()) |
+ Platform::current()->unregisterMemoryDumpProvider(this); |
+ |
delete m_weakCallbackStack; |
m_weakCallbackStack = nullptr; |
for (int i = 0; i < NumberOfHeaps; ++i) |
@@ -380,6 +389,46 @@ void ThreadState::visitPersistents(Visitor* visitor) |
} |
} |
+void ThreadState::dumpMemoryIfNecessary() |
+{ |
+ bool enabled; |
+ TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory-infra"), &enabled); |
+ if (!enabled) |
+ return; |
+ |
+ dumpMemory(); |
+} |
+ |
+void ThreadState::dumpMemory() |
+{ |
+ ASSERT(checkThread()); |
ssid
2015/05/21 16:55:28
This check is not required here, since method can
|
+ if (!m_lastProcessMemoryDump.get()) { |
+ // TODO(ssid): uncomment the following line once the support is available, |
+ // and remove the return statement. |
+ // m_lastProcessMemoryDump.reset(Platform::current()->getExtraProcessMemoryDump()); |
+ return; |
+ } |
+ |
+#define SNAPSHOT_HEAP(HeapType) m_heaps[HeapType##HeapIndex]->dumpMemoryInto(m_lastProcessMemoryDump.get(), #HeapType); |
+ |
+ SNAPSHOT_HEAP(NormalPage1); |
+ SNAPSHOT_HEAP(NormalPage2); |
+ SNAPSHOT_HEAP(NormalPage3); |
+ SNAPSHOT_HEAP(NormalPage4); |
+ SNAPSHOT_HEAP(Vector1); |
+ SNAPSHOT_HEAP(Vector2); |
+ SNAPSHOT_HEAP(Vector3); |
+ SNAPSHOT_HEAP(Vector4); |
+ SNAPSHOT_HEAP(InlineVector); |
+ SNAPSHOT_HEAP(HashTable); |
+ SNAPSHOT_HEAP(LargeObject); |
+ FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP); |
+ |
+#undef SNAPSHOT_HEAP |
+ |
+ // TODO(ssid): Request global dump from blink when support is available. |
+} |
+ |
#if ENABLE(GC_PROFILING) |
const GCInfo* ThreadState::findGCInfo(Address address) |
{ |
@@ -842,6 +891,7 @@ void ThreadState::postGC(GCType gcType) |
{ |
ASSERT(isInGC()); |
+ dumpMemoryIfNecessary(); |
#if ENABLE(GC_PROFILING) |
// We snapshot the heap prior to sweeping to get numbers for both resources |
// that have been allocated since the last GC and for resources that are |
@@ -1223,6 +1273,18 @@ void ThreadState::promptlyFreed(size_t gcInfoIndex) |
m_likelyToBePromptlyFreed[entryIndex] += 3; |
} |
+bool ThreadState::onMemoryDump(WebProcessMemoryDump* memoryDump) |
+{ |
+ // Returns true because it might be able to provide dump in future. On |
+ // returning false, the memory dump manager stops collecting dumps from |
+ // this provider. |
+ if (!m_lastProcessMemoryDump.get()) |
+ return true; |
+ |
+ // memoryDump->TakeAllDumpsFrom(m_lastProcessMemoryDump.get()); |
+ return true; |
+} |
+ |
#if ENABLE(GC_PROFILING) |
const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
{ |