summaryrefslogtreecommitdiffstats
path: root/Source/WebKit
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-07-13 17:58:52 -0700
committerJohn Reck <jreck@google.com>2012-07-13 17:58:52 -0700
commitbe759e8b1203e29304d03ea0a8c9c3fc3b68bcb3 (patch)
treeb3dcc50fbbba3053caebfd54988ccdd6be810a3d /Source/WebKit
parent8ad43ea5cc2ec08eaf11619f6c543e14bb5e1506 (diff)
downloadexternal_webkit-be759e8b1203e29304d03ea0a8c9c3fc3b68bcb3.zip
external_webkit-be759e8b1203e29304d03ea0a8c9c3fc3b68bcb3.tar.gz
external_webkit-be759e8b1203e29304d03ea0a8c9c3fc3b68bcb3.tar.bz2
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
Diffstat (limited to 'Source/WebKit')
-rw-r--r--Source/WebKit/android/WebCoreSupport/MemoryUsage.cpp44
1 files changed, 8 insertions, 36 deletions
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 <malloc.h>
-#include <wtf/CurrentTime.h>
-
#include <v8.h>
-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;