From be759e8b1203e29304d03ea0a8c9c3fc3b68bcb3 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 13 Jul 2012 17:58:52 -0700 Subject: Fix stuttering caused by mallinfo mallinfo will block any malloc/frees while it is running, and unfortunately it is rather slow - it takes upwards of 70ms. Fortunately, we don't need all the info mallinfo returns, and can instead query for the total usage directly. This call merely returns a global value, so the caching mechanism that is in place is no longer necessary. Change-Id: Ida3af9202a6825b19b8590d4b40ca72ba2230c90 --- .../WebKit/android/WebCoreSupport/MemoryUsage.cpp | 44 ++++------------------ 1 file changed, 8 insertions(+), 36 deletions(-) (limited to 'Source/WebKit') diff --git a/Source/WebKit/android/WebCoreSupport/MemoryUsage.cpp b/Source/WebKit/android/WebCoreSupport/MemoryUsage.cpp index 592fad3..5b8c33b 100644 --- a/Source/WebKit/android/WebCoreSupport/MemoryUsage.cpp +++ b/Source/WebKit/android/WebCoreSupport/MemoryUsage.cpp @@ -26,50 +26,22 @@ #include "config.h" #include "MemoryUsage.h" -#include -#include - #include -using namespace WTF; - -class MemoryUsageCache { -public: - MemoryUsageCache() - : m_cachedMemoryUsage(0) - , m_cacheTime(0) - { - } +// Workaround an issue where malloc_footprint is in malloc.h +// but is not actually implemented. +// See: http://code.google.com/p/android/issues/detail?id=34897 +extern "C" size_t dlmalloc_footprint(void); - int getCachedMemoryUsage(bool forceFresh); - -private: - unsigned m_cachedMemoryUsage; - double m_cacheTime; - static const int CACHE_VALIDITY_MS = 2000; -}; +using namespace WTF; -int MemoryUsageCache::getCachedMemoryUsage(bool forceFresh) +int MemoryUsage::memoryUsageMb(bool /* forceFresh */) { - if (!forceFresh && currentTimeMS() <= m_cacheTime + CACHE_VALIDITY_MS) - return m_cachedMemoryUsage; - - struct mallinfo minfo = mallinfo(); - m_cachedMemoryUsage = (minfo.hblkhd + minfo.arena) >> 20; - + size_t footprint = dlmalloc_footprint() >> 20; v8::HeapStatistics stat; v8::V8::GetHeapStatistics(&stat); unsigned v8Usage = stat.total_heap_size() >> 20; - m_cachedMemoryUsage += v8Usage; - - m_cacheTime = currentTimeMS(); - return m_cachedMemoryUsage; -} - -int MemoryUsage::memoryUsageMb(bool forceFresh) -{ - static MemoryUsageCache cache; - return cache.getCachedMemoryUsage(forceFresh); + return footprint + v8Usage; } int MemoryUsage::m_lowMemoryUsageMb = 0; -- cgit v1.1