Chromium Code Reviews| Index: Source/platform/heap/ThreadState.cpp |
| diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp |
| index 1b20f981cf9b388edb60b2582881add495171f4b..f289063a61f1db89b18ab55201c5fedaf7c2571e 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); |
|
Primiano Tucci (use gerrit)
2015/05/21 18:43:10
Ok to this as a temporary hack, but plz add a clea
ssid
2015/05/22 13:34:06
Done. Check heap.cpp
|
| + if (!enabled) |
| + return; |
| + |
| + m_lastProcessMemoryDump = adoptPtr(Platform::current()->createProcessMemoryDump()); |
| + |
| +#define SNAPSHOT_HEAP(HeapType) \ |
| + { \ |
| + String allocatorBaseName; \ |
| + if (isMainThread()) { \ |
| + allocatorBaseName = String("blink_gc/thread_main/heaps/" #HeapType); \ |
| + } \ |
| + else { \ |
| + allocatorBaseName = String::format("blink_gc/thread_%ld/heaps/" #HeapType, m_thread); \ |
| + } \ |
| + m_heaps[HeapType##HeapIndex]->dumpMemoryInto(m_lastProcessMemoryDump.get(), &allocatorBaseName); \ |
| + } |
| + |
| + SNAPSHOT_HEAP(NormalPage1); |
|
Primiano Tucci (use gerrit)
2015/05/21 18:43:10
You either want to remove the ; here (otherwise so
ssid
2015/05/22 13:34:07
This is the style in the same file. function Threa
|
| + 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 |
| + // (crbug.com/490087). |
|
Primiano Tucci (use gerrit)
2015/05/21 18:43:10
Maybe add a line here saying: For the moment the d
ssid
2015/05/22 13:34:06
done at heap.cpp
|
| +} |
| + |
| #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; |
|
Primiano Tucci (use gerrit)
2015/05/21 18:43:10
Ok for now, but this should really return false.
I
ssid
2015/05/22 13:34:06
Not sure if this is relevant any more.
|
| + |
| + memoryDump->takeAllDumpsFrom(m_lastProcessMemoryDump.get()); |
| + return true; |
| +} |
| + |
| #if ENABLE(GC_PROFILING) |
| const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
| { |