Chromium Code Reviews| Index: third_party/WebKit/Source/platform/MemoryUsageProvider.cpp |
| diff --git a/third_party/WebKit/Source/platform/MemoryUsageProvider.cpp b/third_party/WebKit/Source/platform/MemoryUsageProvider.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1defd66978887744956bc54d0944d6020005dc6 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/MemoryUsageProvider.cpp |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "platform/MemoryUsageProvider.h" |
| + |
| +#include "platform/heap/Heap.h" |
| +#include "public/platform/WebMemoryAllocatorDump.h" |
| +#include "public/platform/WebProcessMemoryDump.h" |
| +#include "wtf/Partitions.h" |
| +#include "wtf/Threading.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +#include <v8.h> |
| + |
| +namespace blink { |
| + |
| +MemoryUsageProvider* MemoryUsageProvider::instance() |
| +{ |
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<MemoryUsageProvider>, provider, new ThreadSpecific<MemoryUsageProvider>); |
| + return provider; |
| +} |
| + |
| +MemoryUsageProvider::MemoryUsageProvider() |
| + : m_isolate(nullptr) |
| + , m_previousSize(0) |
| +{ |
| +} |
| + |
| +MemoryUsageProvider::~MemoryUsageProvider() |
| +{ |
| +} |
| + |
| +bool MemoryUsageProvider::adjustAmountOfAllocatedMemory() |
| +{ |
| + if (!m_isolate) |
| + return false; |
| + |
| + // TODO(peria): Use thread specific heap usage methods, if available. |
| + int64_t currentTotalSize = Heap::allocatedObjectSize() + Heap::markedObjectSize(); |
|
haraken
2016/02/08 11:17:20
This is not what we want to report. Heap::allocate
peria
2016/02/09 06:39:59
Done.
|
| + int64_t diff = currentTotalSize - m_previousSize; |
| + m_isolate->AdjustAmountOfExternalAllocatedMemory(diff); |
| + m_previousSize = currentTotalSize; |
| + |
| + return true; |
| +} |
| + |
| +} // namespace blink |