Title: [127195] trunk
Revision
127195
Author
[email protected]
Date
2012-08-30 14:56:45 -0700 (Thu, 30 Aug 2012)

Log Message

[EFL][WK2] Add WebMemorySampler feature.
https://bugs.webkit.org/show_bug.cgi?id=91214

Patch by JungJik Lee <[email protected]> on 2012-08-30
Reviewed by Kenneth Rohde Christiansen.

.:

Set WebMemorySampler feature on in EFL port.

* Source/cmake/OptionsEfl.cmake:
* Source/cmake/WebKitFeatures.cmake:
* Source/cmakeconfig.h.cmake:

Source/_javascript_Core:

WebMemorySampler collects _javascript_ stack and JIT memory usage in globalMemoryStatistics.

* PlatformEfl.cmake:

Source/WebKit2:

Add WebMemorySampler feature to EFL port. WebMemorySampler records memory usage of
WebProcess and UI Process and also it records application memory status in real time.
Included items on the result are JIT, JS heap, fastmalloc bytes and
application memory info from /proc/process_id/statm.

* PlatformEfl.cmake:
* Shared/linux/WebMemorySamplerLinux.cpp: Added.
(WebKit):
(ApplicationMemoryStats):
(WebKit::nextToken):
(WebKit::appendKeyValuePair):
(WebKit::sampleMemoryAllocatedForApplication):
(WebKit::WebMemorySampler::processName):
(WebKit::WebMemorySampler::sampleWebKit):
(WebKit::WebMemorySampler::sendMemoryPressureEvent):
* UIProcess/API/efl/ewk_context.cpp:
(_Ewk_Context::_Ewk_Context):

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (127194 => 127195)


--- trunk/ChangeLog	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/ChangeLog	2012-08-30 21:56:45 UTC (rev 127195)
@@ -1,3 +1,16 @@
+2012-08-30  JungJik Lee  <[email protected]>
+
+        [EFL][WK2] Add WebMemorySampler feature.
+        https://bugs.webkit.org/show_bug.cgi?id=91214
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Set WebMemorySampler feature on in EFL port.
+
+        * Source/cmake/OptionsEfl.cmake:
+        * Source/cmake/WebKitFeatures.cmake:
+        * Source/cmakeconfig.h.cmake:
+
 2012-08-30  Rob Buis  <[email protected]>
 
         [CMake] Suppress ANGLE compilation warnings

Modified: trunk/Source/_javascript_Core/ChangeLog (127194 => 127195)


--- trunk/Source/_javascript_Core/ChangeLog	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-08-30 21:56:45 UTC (rev 127195)
@@ -1,3 +1,14 @@
+2012-08-30  JungJik Lee  <[email protected]>
+
+        [EFL][WK2] Add WebMemorySampler feature.
+        https://bugs.webkit.org/show_bug.cgi?id=91214
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        WebMemorySampler collects _javascript_ stack and JIT memory usage in globalMemoryStatistics.
+
+        * PlatformEfl.cmake:
+
 2012-08-30  Benjamin Poulain  <[email protected]>
 
         Replace JSC::UString by WTF::String

Modified: trunk/Source/_javascript_Core/PlatformEfl.cmake (127194 => 127195)


--- trunk/Source/_javascript_Core/PlatformEfl.cmake	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/_javascript_Core/PlatformEfl.cmake	2012-08-30 21:56:45 UTC (rev 127195)
@@ -1,6 +1,8 @@
 LIST(APPEND _javascript_Core_SOURCES
     jit/ExecutableAllocatorFixedVMPool.cpp
     jit/ExecutableAllocator.cpp
+
+    runtime/MemoryStatistics.cpp
 )
 
 LIST(APPEND _javascript_Core_LIBRARIES

Modified: trunk/Source/WebKit2/ChangeLog (127194 => 127195)


--- trunk/Source/WebKit2/ChangeLog	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/WebKit2/ChangeLog	2012-08-30 21:56:45 UTC (rev 127195)
@@ -1,3 +1,28 @@
+2012-08-30  JungJik Lee  <[email protected]>
+
+        [EFL][WK2] Add WebMemorySampler feature.
+        https://bugs.webkit.org/show_bug.cgi?id=91214
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Add WebMemorySampler feature to EFL port. WebMemorySampler records memory usage of
+        WebProcess and UI Process and also it records application memory status in real time.
+        Included items on the result are JIT, JS heap, fastmalloc bytes and
+        application memory info from /proc/process_id/statm.
+
+        * PlatformEfl.cmake:
+        * Shared/linux/WebMemorySamplerLinux.cpp: Added.
+        (WebKit):
+        (ApplicationMemoryStats):
+        (WebKit::nextToken):
+        (WebKit::appendKeyValuePair):
+        (WebKit::sampleMemoryAllocatedForApplication):
+        (WebKit::WebMemorySampler::processName):
+        (WebKit::WebMemorySampler::sampleWebKit):
+        (WebKit::WebMemorySampler::sendMemoryPressureEvent):
+        * UIProcess/API/efl/ewk_context.cpp:
+        (_Ewk_Context::_Ewk_Context):
+
 2012-08-30  Pratik Solanki  <[email protected]>
 
         objc_msgSend and IMP should be cast appropriately before using

Modified: trunk/Source/WebKit2/PlatformEfl.cmake (127194 => 127195)


--- trunk/Source/WebKit2/PlatformEfl.cmake	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/WebKit2/PlatformEfl.cmake	2012-08-30 21:56:45 UTC (rev 127195)
@@ -15,6 +15,8 @@
     Platform/CoreIPC/unix/ConnectionUnix.cpp
     Platform/CoreIPC/unix/AttachmentUnix.cpp
 
+    Shared/WebMemorySampler.cpp
+
     Shared/API/c/cairo/WKImageCairo.cpp
 
     Shared/API/c/gtk/WKGraphicsContextGtk.cpp
@@ -28,6 +30,8 @@
     Shared/efl/ProcessExecutablePathEfl.cpp
     Shared/efl/WebEventFactory.cpp
 
+    Shared/linux/WebMemorySamplerLinux.cpp
+
     Shared/soup/PlatformCertificateInfo.cpp
     Shared/soup/WebCoreArgumentCodersSoup.cpp
 

Added: trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp (0 => 127195)


--- trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp	2012-08-30 21:56:45 UTC (rev 127195)
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebMemorySampler.h"
+
+#if ENABLE(MEMORY_SAMPLER)
+
+#include "NotImplemented.h"
+#include <_javascript_Core/MemoryStatistics.h>
+#include <WebCore/JSDOMWindow.h>
+#include <runtime/JSLock.h>
+#include <string.h>
+#include <sys/sysinfo.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/text/WTFString.h>
+
+using namespace WebCore;
+using namespace JSC;
+using namespace WTF;
+
+namespace WebKit {
+
+struct ApplicationMemoryStats {
+    size_t totalProgramSize;
+    size_t residentSetSize;
+    size_t sharedSize;
+    size_t textSize;
+    size_t librarySize;
+    size_t dataStackSize;
+    size_t dirtyPageSize;
+};
+
+static const unsigned int maxBuffer = 128;
+static const unsigned int maxProcessPath = 35;
+
+static inline String nextToken(FILE* file)
+{
+    ASSERT(file);
+    if (!file)
+        return String();
+
+    char buffer[maxBuffer] = {0, };
+    unsigned int index = 0;
+    while (index < maxBuffer) {
+        char ch = fgetc(file);
+        if (ch == EOF || (isASCIISpace(ch) && index)) // Break on non-initial ASCII space.
+            break;
+        if (!isASCIISpace(ch)) {
+            buffer[index] = ch;
+            index++;
+        }
+    }
+
+    return String(buffer);
+}
+
+static inline void appendKeyValuePair(WebMemoryStatistics& stats, const String& key, size_t value)
+{
+    stats.keys.append(key);
+    stats.values.append(value);
+}
+
+static ApplicationMemoryStats sampleMemoryAllocatedForApplication()
+{
+    ApplicationMemoryStats applicationStats;
+    char processPath[maxProcessPath];
+    snprintf(processPath, maxProcessPath, "/proc/self/statm");
+    FILE* statmFileDescriptor = fopen(processPath, "r");
+    if (!statmFileDescriptor)
+        return applicationStats;
+
+    applicationStats.totalProgramSize = nextToken(statmFileDescriptor).toInt();
+    applicationStats.residentSetSize = nextToken(statmFileDescriptor).toInt();
+    applicationStats.sharedSize = nextToken(statmFileDescriptor).toInt();
+    applicationStats.textSize = nextToken(statmFileDescriptor).toInt();
+    applicationStats.librarySize = nextToken(statmFileDescriptor).toInt();
+    applicationStats.dataStackSize = nextToken(statmFileDescriptor).toInt();
+    applicationStats.dirtyPageSize = nextToken(statmFileDescriptor).toInt();
+
+    fclose(statmFileDescriptor);
+
+    return applicationStats;
+}
+
+String WebMemorySampler::processName() const
+{
+    char processPath[maxProcessPath];
+    snprintf(processPath, maxProcessPath, "/proc/self/status");
+    FILE* statusFileDescriptor = fopen(processPath, "r");
+    if (!statusFileDescriptor)
+        return String();
+        
+    nextToken(statusFileDescriptor);
+    String processName = nextToken(statusFileDescriptor);
+
+    fclose(statusFileDescriptor);
+
+    return processName;
+}
+
+WebMemoryStatistics WebMemorySampler::sampleWebKit() const
+{
+    WebMemoryStatistics webKitMemoryStats;
+
+    double now = currentTime();
+
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Timestamp"), now);
+
+    ApplicationMemoryStats applicationStats = sampleMemoryAllocatedForApplication();
+
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Total Program Size"), applicationStats.totalProgramSize);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("RSS"), applicationStats.residentSetSize);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Shared"), applicationStats.sharedSize);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Text"), applicationStats.textSize);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Library"), applicationStats.librarySize);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Data/Stack"), applicationStats.dataStackSize);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Dirty"), applicationStats.dirtyPageSize);
+
+    size_t totalBytesInUse = 0;
+    size_t totalBytesCommitted = 0;
+
+#if ENABLE(GLOBAL_FASTMALLOC_NEW)
+    FastMallocStatistics fastMallocStatistics = WTF::fastMallocStatistics();
+    size_t fastMallocBytesInUse = fastMallocStatistics.committedVMBytes - fastMallocStatistics.freeListBytes;
+    size_t fastMallocBytesCommitted = fastMallocStatistics.committedVMBytes;
+    totalBytesInUse += fastMallocBytesInUse;
+    totalBytesCommitted += fastMallocBytesCommitted;
+
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Fast Malloc In Use"), fastMallocBytesInUse);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Fast Malloc Committed Memory"), fastMallocBytesCommitted);
+#endif
+
+#if USE(JSC)
+    size_t jscHeapBytesInUse = JSDOMWindow::commonJSGlobalData()->heap.size();
+    size_t jscHeapBytesCommitted = JSDOMWindow::commonJSGlobalData()->heap.capacity();
+    totalBytesInUse += jscHeapBytesInUse;
+    totalBytesCommitted += jscHeapBytesCommitted;
+
+    GlobalMemoryStatistics globalMemoryStats = globalMemoryStatistics();
+    totalBytesInUse += globalMemoryStats.stackBytes + globalMemoryStats.JITBytes;
+    totalBytesCommitted += globalMemoryStats.stackBytes + globalMemoryStats.JITBytes;
+
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("_javascript_ Heap In Use"), jscHeapBytesInUse);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("_javascript_ Heap Commited Memory"), jscHeapBytesCommitted);
+    
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("_javascript_ Stack Bytes"), globalMemoryStats.stackBytes);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("_javascript_ JIT Bytes"), globalMemoryStats.JITBytes);
+#endif
+
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Total Memory In Use"), totalBytesInUse);
+    appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Total Committed Memory"), totalBytesCommitted);
+
+    struct sysinfo systemInfo;
+    if (!sysinfo(&systemInfo)) {
+        appendKeyValuePair(webKitMemoryStats, ASCIILiteral("System Total Bytes"), systemInfo.totalram);
+        appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Available Bytes"), systemInfo.freeram);
+        appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Shared Bytes"), systemInfo.sharedram);
+        appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Buffer Bytes"), systemInfo.bufferram);
+        appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Total Swap Bytes"), systemInfo.totalswap);
+        appendKeyValuePair(webKitMemoryStats, ASCIILiteral("Available Swap Bytes"), systemInfo.freeswap);
+    }   
+
+    return webKitMemoryStats;
+}
+
+void WebMemorySampler::sendMemoryPressureEvent()
+{
+    notImplemented();
+}
+
+}
+#endif

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp (127194 => 127195)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp	2012-08-30 21:56:45 UTC (rev 127195)
@@ -25,6 +25,7 @@
 #include "VibrationProvider.h"
 #include "WKAPICast.h"
 #include "WKContextSoup.h"
+#include "WKNumber.h"
 #include "WKRetainPtr.h"
 #include "WKString.h"
 #include "ewk_context_download_client_private.h"
@@ -85,6 +86,16 @@
         vibrationProvider = VibrationProvider::create(wkVibrationRef);
 #endif
 
+#if ENABLE(MEMORY_SAMPLER)
+        static bool initializeMemorySampler = false;
+        static const char environmentVariable[] = "SAMPLE_MEMORY";
+
+        if (!initializeMemorySampler && getenv(environmentVariable)) {
+            WKRetainPtr<WKDoubleRef> interval(AdoptWK, WKDoubleCreate(0.0));
+            WKContextStartMemorySampler(context.get(), interval.get());
+            initializeMemorySampler = true;
+        }
+#endif
         ewk_context_request_manager_client_attach(this);
         ewk_context_download_client_attach(this);
     }

Modified: trunk/Source/cmake/OptionsEfl.cmake (127194 => 127195)


--- trunk/Source/cmake/OptionsEfl.cmake	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/cmake/OptionsEfl.cmake	2012-08-30 21:56:45 UTC (rev 127195)
@@ -78,6 +78,7 @@
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_LEGACY_WEBKIT_BLOB_BUILDER ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_LINK_PREFETCH ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_CAPTURE ON)
+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEMORY_SAMPLER ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MICRODATA ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NAVIGATOR_CONTENT_UTILS ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API OFF)

Modified: trunk/Source/cmake/WebKitFeatures.cmake (127194 => 127195)


--- trunk/Source/cmake/WebKitFeatures.cmake	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/cmake/WebKitFeatures.cmake	2012-08-30 21:56:45 UTC (rev 127195)
@@ -77,6 +77,7 @@
     WEBKIT_OPTION_DEFINE(ENABLE_MEDIA_SOURCE "Toggle Media Source support" OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_MEDIA_STATISTICS "Toggle Media Statistics support" OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_MEDIA_STREAM "Toggle Media Stream API support" OFF)
+    WEBKIT_OPTION_DEFINE(ENABLE_MEMORY_SAMPLER "Toggle Memory Sampler support" OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_METER_ELEMENT "Toggle Meter Tag support" ON)
     WEBKIT_OPTION_DEFINE(ENABLE_MHTML "Toggle MHTML support" OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_MICRODATA "Toggle Microdata support" OFF)

Modified: trunk/Source/cmakeconfig.h.cmake (127194 => 127195)


--- trunk/Source/cmakeconfig.h.cmake	2012-08-30 21:41:22 UTC (rev 127194)
+++ trunk/Source/cmakeconfig.h.cmake	2012-08-30 21:56:45 UTC (rev 127195)
@@ -67,6 +67,7 @@
 #cmakedefine01 ENABLE_MATHML
 #cmakedefine01 ENABLE_MEDIA_CAPTURE
 #cmakedefine01 ENABLE_MEDIA_STREAM
+#cmakedefine01 ENABLE_MEMORY_SAMPLER
 #cmakedefine01 ENABLE_METER_ELEMENT
 #cmakedefine01 ENABLE_MICRODATA
 #cmakedefine01 ENABLE_MUTATION_OBSERVERS
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to