[GTK] Add initial implementation of resource usage overlay
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Feb 2017 13:03:33 +0000 (13:03 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Feb 2017 13:03:33 +0000 (13:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167731

Reviewed by Michael Catanzaro.

.:

Enable RESOURCE_USAGE.

* Source/cmake/OptionsGTK.cmake:

Source/JavaScriptCore:

Also expose nextFireTime() for GTK+ port.

* heap/GCActivityCallback.cpp:
(JSC::GCActivityCallback::scheduleTimer):
(JSC::GCActivityCallback::cancelTimer):
* heap/GCActivityCallback.h:

Source/WebCore:

Add an implementation of ResourceUsageOverlay and ResourceUsageThread for Linux systems.

* PlatformGTK.cmake: Add new new files to compilation.
* page/Page.cpp:
(WebCore::Page::setResourceUsageOverlayVisible): Do not create the page overlay if accelerated compositing is
not enabled.
* page/ResourceUsageOverlay.h:
* page/linux/ResourceUsageOverlayLinux.cpp: Added.
(WebCore::cpuUsageString):
(WebCore::formatByteNumber):
(WebCore::gcTimerString):
(WebCore::ResourceUsageOverlay::platformInitialize):
(WebCore::ResourceUsageOverlay::platformDestroy):
* page/linux/ResourceUsageThreadLinux.cpp: Added.
(WebCore::cpuPeriod):
(WebCore::cpuUsage):
(WebCore::ResourceUsageThread::platformThreadBody):

Source/WebKit2:

Toggle the resource usage overlay visibility by pressing CTRL + Shift + G. Only available when building with
developer mode enabled.

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseKeyPressEvent):

Source/WTF:

Enable RESOURCE_USAGE for GTK+ port too.

* wtf/Platform.h:

LayoutTests:

Unskip inpector tests depending on RESOURCE_USAGE.

* platform/gtk/TestExpectations:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@211631 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/platform/gtk/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/GCActivityCallback.cpp
Source/JavaScriptCore/heap/GCActivityCallback.h
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/page/Page.cpp
Source/WebCore/page/ResourceUsageOverlay.h
Source/WebCore/page/ResourceUsageThread.h
Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp [new file with mode: 0644]
Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/cmake/OptionsGTK.cmake

index d8d11c2..baed24a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial implementation of resource usage overlay
+        https://bugs.webkit.org/show_bug.cgi?id=167731
+
+        Reviewed by Michael Catanzaro.
+
+        Enable RESOURCE_USAGE.
+
+        * Source/cmake/OptionsGTK.cmake:
+
 2017-02-02  Alex Christensen  <achristensen@webkit.org>
 
         Build fix after r211602
index 833b76e..653b63f 100644 (file)
@@ -1,3 +1,14 @@
+2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial implementation of resource usage overlay
+        https://bugs.webkit.org/show_bug.cgi?id=167731
+
+        Reviewed by Michael Catanzaro.
+
+        Unskip inpector tests depending on RESOURCE_USAGE.
+
+        * platform/gtk/TestExpectations:
+
 2017-02-03  Antoine Quint  <graouts@apple.com>
 
         LayoutTest media/modern-media-controls/tracks-panel/tracks-panel-hide-click-outside.html is a flaky timeout
index a40d656..dc7639c 100644 (file)
@@ -644,9 +644,6 @@ webkit.org/b/152620 css3/font-variant-small-caps-synthesis.html [ ImageOnlyFailu
 # Requires ENABLE(SAMPLING_PROFILER)
 webkit.org/b/153466 inspector/sampling-profiler [ Skip ]
 
-# Requires ENABLE(RESOURCE_USAGE).
-inspector/memory [ Skip ]
-
 # This requires a specific font on Mac
 fast/text/hidpi-text-selection-gap-between-words.html [ Skip ]
 
index a4459c5..59adb08 100644 (file)
@@ -1,3 +1,17 @@
+2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial implementation of resource usage overlay
+        https://bugs.webkit.org/show_bug.cgi?id=167731
+
+        Reviewed by Michael Catanzaro.
+
+        Also expose nextFireTime() for GTK+ port.
+
+        * heap/GCActivityCallback.cpp:
+        (JSC::GCActivityCallback::scheduleTimer):
+        (JSC::GCActivityCallback::cancelTimer):
+        * heap/GCActivityCallback.h:
+
 2017-02-03  Csaba Osztrogonác  <ossy@webkit.org>
 
         [cmake] Unreviewed AArch64 buildfix after r211603.
index e55dc6e..593b20b 100644 (file)
@@ -123,6 +123,7 @@ void GCActivityCallback::scheduleTimer(double newDelay)
         return;
 
     m_delay = newDelay;
+    m_nextFireTime = WTF::currentTime() + newDelay;
     if (!m_delay) {
         g_source_set_ready_time(m_timer.get(), 0);
         return;
@@ -141,6 +142,7 @@ void GCActivityCallback::scheduleTimer(double newDelay)
 void GCActivityCallback::cancelTimer()
 {
     m_delay = -1;
+    m_nextFireTime = 0;
     g_source_set_ready_time(m_timer.get(), -1);
 }
 #endif
index ec988c8..3baa21b 100644 (file)
@@ -59,7 +59,7 @@ public:
 
     static bool s_shouldCreateGCTimer;
 
-#if USE(CF) || PLATFORM(EFL)
+#if USE(CF) || USE(GLIB)
     double nextFireTime() const { return m_nextFireTime; }
 #endif
 
index eab9f5c..9d17672 100644 (file)
@@ -1,3 +1,14 @@
+2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial implementation of resource usage overlay
+        https://bugs.webkit.org/show_bug.cgi?id=167731
+
+        Reviewed by Michael Catanzaro.
+
+        Enable RESOURCE_USAGE for GTK+ port too.
+
+        * wtf/Platform.h:
+
 2017-02-02  Andreas Kling  <akling@apple.com>
 
         [Mac] In-process memory pressure monitor for WebContent processes AKA websam
index b9bdd38..f49f3c7 100644 (file)
 #define USE_IOSURFACE 1
 #endif
 
-#if PLATFORM(COCOA)
+#if PLATFORM(COCOA) || PLATFORM(GTK)
 #define ENABLE_RESOURCE_USAGE 1
 #endif
 
index 7133f46..9921ebd 100644 (file)
@@ -1,3 +1,28 @@
+2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial implementation of resource usage overlay
+        https://bugs.webkit.org/show_bug.cgi?id=167731
+
+        Reviewed by Michael Catanzaro.
+
+        Add an implementation of ResourceUsageOverlay and ResourceUsageThread for Linux systems.
+
+        * PlatformGTK.cmake: Add new new files to compilation.
+        * page/Page.cpp:
+        (WebCore::Page::setResourceUsageOverlayVisible): Do not create the page overlay if accelerated compositing is
+        not enabled.
+        * page/ResourceUsageOverlay.h:
+        * page/linux/ResourceUsageOverlayLinux.cpp: Added.
+        (WebCore::cpuUsageString):
+        (WebCore::formatByteNumber):
+        (WebCore::gcTimerString):
+        (WebCore::ResourceUsageOverlay::platformInitialize):
+        (WebCore::ResourceUsageOverlay::platformDestroy):
+        * page/linux/ResourceUsageThreadLinux.cpp: Added.
+        (WebCore::cpuPeriod):
+        (WebCore::cpuUsage):
+        (WebCore::ResourceUsageThread::platformThreadBody):
+
 2017-02-03  Enrique Ocaña González  <eocanha@igalia.com>
 
         [GStreamer] Store preloaded media in webkit's cache
index b1c6e6b..c0bcd2a 100644 (file)
@@ -62,6 +62,9 @@ list(APPEND WebCore_SOURCES
     loader/soup/CachedRawResourceSoup.cpp
     loader/soup/SubresourceLoaderSoup.cpp
 
+    page/linux/ResourceUsageOverlayLinux.cpp
+    page/linux/ResourceUsageThreadLinux.cpp
+
     platform/KillRingNone.cpp
     platform/StaticPasteboard.cpp
     platform/UserAgentQuirks.cpp
index adf48a7..9fe6b13 100644 (file)
@@ -2146,7 +2146,7 @@ void Page::setResourceUsageOverlayVisible(bool visible)
         return;
     }
 
-    if (!m_resourceUsageOverlay)
+    if (!m_resourceUsageOverlay && m_settings->acceleratedCompositingEnabled())
         m_resourceUsageOverlay = std::make_unique<ResourceUsageOverlay>(*this);
 }
 #endif
index 6b75168..b9d0538 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(RESOURCE_USAGE)
 
 #include "FloatRect.h"
+#include "GraphicsLayer.h"
 #include "IntRect.h"
 #include "MainFrame.h"
 #include "PageOverlay.h"
@@ -82,6 +83,11 @@ private:
     RetainPtr<CALayer> m_layer;
     RetainPtr<CALayer> m_containerLayer;
 #endif
+
+#if OS(LINUX)
+    std::unique_ptr<GraphicsLayer> m_paintLayer;
+    std::unique_ptr<GraphicsLayerClient> m_overlayPainter;
+#endif
 };
 
 } // namespace WebCore
index 18a1e67..6f9b677 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(RESOURCE_USAGE)
+#if ENABLE(RESOURCE_USAGE) && OS(LINUX)
 
 #include "ResourceUsageData.h"
 #include <array>
@@ -87,4 +87,4 @@ void logFootprintComparison(const std::array<TagInfo, 256>&, const std::array<Ta
 
 } // namespace WebCore
 
-#endif // ENABLE(RESOURCE_USAGE)
+#endif // ENABLE(RESOURCE_USAGE) && OS(LINUX)
diff --git a/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp b/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp
new file mode 100644 (file)
index 0000000..cff63e0
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * 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 "ResourceUsageOverlay.h"
+
+#if ENABLE(RESOURCE_USAGE) && OS(LINUX)
+
+#include "Chrome.h"
+#include "ChromeClient.h"
+#include "CommonVM.h"
+#include "GraphicsContext.h"
+#include "Page.h"
+#include "RenderTheme.h"
+#include "ResourceUsageThread.h"
+#include <runtime/VM.h>
+
+namespace WebCore {
+
+static ResourceUsageData gData;
+
+static String cpuUsageString(float cpuUsage)
+{
+    if (cpuUsage < 0)
+        return ASCIILiteral("<unknown>");
+    return String::format("%.1f%%", cpuUsage);
+}
+
+static String formatByteNumber(size_t number)
+{
+    if (number >= 1024 * 1048576)
+        return String::format("%.3f GB", static_cast<double>(number) / (1024 * 1048576));
+    if (number >= 1048576)
+        return String::format("%.2f MB", static_cast<double>(number) / 1048576);
+    if (number >= 1024)
+        return String::format("%.1f kB", static_cast<double>(number) / 1024);
+    return String::format("%lu", number);
+}
+
+static String gcTimerString(double timerFireDate, double now)
+{
+    if (!timerFireDate)
+        return ASCIILiteral("[not scheduled]");
+    return String::format("%g", timerFireDate - now);
+}
+
+static const float gFontSize = 14;
+
+class ResourceUsageOverlayPainter final : public GraphicsLayerClient {
+public:
+    ResourceUsageOverlayPainter(ResourceUsageOverlay& overlay)
+        : m_overlay(overlay)
+    {
+        FontCascadeDescription fontDescription;
+        RenderTheme::defaultTheme()->systemFont(CSSValueMessageBox, fontDescription);
+        fontDescription.setComputedSize(gFontSize);
+        m_textFont = FontCascade(fontDescription, 0, 0);
+        m_textFont.update(nullptr);
+    }
+
+    ~ResourceUsageOverlayPainter()
+    {
+    }
+
+private:
+    void paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& clip) override
+    {
+        GraphicsContextStateSaver stateSaver(context);
+        context.fillRect(clip, Color(0.0f, 0.0f, 0.0f, 0.8f));
+        context.setFillColor(Color(0.9f, 0.9f, 0.9f, 1.f));
+
+        FloatPoint position = { 10, 20 };
+        String string =  "CPU: " + cpuUsageString(gData.cpu);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+
+        string = "Memory: " + formatByteNumber(gData.totalDirtySize);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+
+        string = "External: " + formatByteNumber(gData.totalExternalSize);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+
+        string = "GC Heap: " + formatByteNumber(gData.categories[MemoryCategory::GCHeap].dirtySize);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+
+        string = "GC owned: " + formatByteNumber(gData.categories[MemoryCategory::GCOwned].dirtySize);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+
+        double now = WTF::currentTime();
+        string = "Eden GC: " + gcTimerString(gData.timeOfNextEdenCollection, now);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+
+        string = "Full GC: " + gcTimerString(gData.timeOfNextFullCollection, now);
+        context.drawText(m_textFont, TextRun(string), position);
+        position.move(0, gFontSize + 2);
+    }
+
+    void notifyFlushRequired(const GraphicsLayer*) override
+    {
+        m_overlay.overlay().page()->chrome().client().scheduleCompositingLayerFlush();
+    }
+
+    ResourceUsageOverlay& m_overlay;
+    FontCascade m_textFont;
+};
+
+void ResourceUsageOverlay::platformInitialize()
+{
+    m_overlayPainter = std::make_unique<ResourceUsageOverlayPainter>(*this);
+    m_paintLayer = GraphicsLayer::create(overlay().page()->chrome().client().graphicsLayerFactory(), *m_overlayPainter);
+    m_paintLayer->setAnchorPoint(FloatPoint3D());
+    m_paintLayer->setSize({ normalWidth, normalHeight });
+    m_paintLayer->setBackgroundColor(Color(0.0f, 0.0f, 0.0f, 0.8f));
+    m_paintLayer->setDrawsContent(true);
+    overlay().layer().addChild(m_paintLayer.get());
+
+    ResourceUsageThread::addObserver(this, [this] (const ResourceUsageData& data) {
+        gData = data;
+        m_paintLayer->setNeedsDisplay();
+    });
+}
+
+void ResourceUsageOverlay::platformDestroy()
+{
+    ResourceUsageThread::removeObserver(this);
+    if (!m_paintLayer)
+        return;
+
+    m_paintLayer->removeFromParent();
+    m_paintLayer = nullptr;
+    m_overlayPainter = nullptr;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(RESOURCE_USAGE) && OS(LINUX)
diff --git a/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp b/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp
new file mode 100644 (file)
index 0000000..86a518f
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * 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 "ResourceUsageThread.h"
+
+#if ENABLE(RESOURCE_USAGE)
+
+#include "CurrentProcessMemoryStatus.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <heap/GCActivityCallback.h>
+#include <runtime/VM.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+namespace WebCore {
+
+static float cpuPeriod()
+{
+    FILE* file = fopen("/proc/stat", "r");
+    if (!file)
+        return 0;
+
+    static const unsigned statMaxLineLength = 512;
+    char buffer[statMaxLineLength + 1];
+    char* line = fgets(buffer, statMaxLineLength, file);
+    if (!line) {
+        fclose(file);
+        return 0;
+    }
+
+    unsigned long long userTime, niceTime, systemTime, idleTime;
+    unsigned long long ioWait, irq, softIrq, steal, guest, guestnice;
+    ioWait = irq = softIrq = steal = guest = guestnice = 0;
+    sscanf(buffer, "cpu  %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu",
+        &userTime, &niceTime, &systemTime, &idleTime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
+
+    // Keep parsing if we still don't know cpuCount.
+    static unsigned cpuCount = 0;
+    if (!cpuCount) {
+        while ((line = fgets(buffer, statMaxLineLength, file))) {
+            if (strlen(line) > 4 && line[0] == 'c' && line[1] == 'p' && line[2] == 'u')
+                cpuCount++;
+            else
+                break;
+        }
+    }
+    fclose(file);
+
+    if (!cpuCount)
+        return 0;
+
+    static unsigned long long previousTotalTime = 0;
+    unsigned long long totalTime = userTime + niceTime + systemTime + irq + softIrq + idleTime + ioWait + steal;
+    unsigned long long period = totalTime > previousTotalTime ? totalTime - previousTotalTime : 0;
+    previousTotalTime = totalTime;
+    return static_cast<float>(period) / cpuCount;
+}
+
+static float cpuUsage()
+{
+    float period = cpuPeriod();
+    if (!period)
+        return -1;
+
+    int fd = open("/proc/self/stat", O_RDONLY);
+    if (fd < 0)
+        return -1;
+
+    static const ssize_t maxBufferLength = BUFSIZ - 1;
+    char buffer[BUFSIZ];
+    buffer[0] = '\0';
+
+    ssize_t totalBytesRead = 0;
+    while (totalBytesRead < maxBufferLength) {
+        ssize_t bytesRead = read(fd, buffer + totalBytesRead, maxBufferLength - totalBytesRead);
+        if (bytesRead < 0) {
+            if (errno != EINTR) {
+                close(fd);
+                return -1;
+            }
+            continue;
+        }
+
+        if (!bytesRead)
+            break;
+
+        totalBytesRead += bytesRead;
+    }
+    close(fd);
+    buffer[totalBytesRead] = '\0';
+
+    // Skip pid and process name.
+    char* position = strrchr(buffer, ')');
+    if (!position)
+        return -1;
+
+    // Move after state.
+    position += 4;
+
+    // Skip ppid, pgrp, sid, tty_nr, tty_pgrp, flags, min_flt, cmin_flt, maj_flt, cmaj_flt.
+    unsigned tokensToSkip = 10;
+    while (tokensToSkip--) {
+        while (!isASCIISpace(position[0]))
+            position++;
+        position++;
+    }
+
+    static unsigned long long previousUtime = 0;
+    static unsigned long long previousStime = 0;
+    unsigned long long utime = strtoull(position, &position, 10);
+    unsigned long long stime = strtoull(position, &position, 10);
+    float usage = (utime + stime - (previousUtime + previousStime)) / period * 100.0;
+    previousUtime = utime;
+    previousStime = stime;
+
+    return clampTo<float>(usage, 0, 100);
+}
+
+void ResourceUsageThread::platformThreadBody(JSC::VM* vm, ResourceUsageData& data)
+{
+    data.cpu = cpuUsage();
+
+    ProcessMemoryStatus memoryStatus;
+    currentProcessMemoryStatus(memoryStatus);
+    data.totalDirtySize = memoryStatus.resident - memoryStatus.shared;
+
+    size_t currentGCHeapCapacity = vm->heap.blockBytesAllocated();
+    size_t currentGCOwnedExtra = vm->heap.extraMemorySize();
+    size_t currentGCOwnedExternal = vm->heap.externalMemorySize();
+    RELEASE_ASSERT(currentGCOwnedExternal <= currentGCOwnedExtra);
+
+    data.categories[MemoryCategory::GCHeap].dirtySize = currentGCHeapCapacity;
+    data.categories[MemoryCategory::GCOwned].dirtySize = currentGCOwnedExtra - currentGCOwnedExternal;
+    data.categories[MemoryCategory::GCOwned].externalSize = currentGCOwnedExternal;
+
+    data.totalExternalSize = currentGCOwnedExternal;
+
+    data.timeOfNextEdenCollection = vm->heap.edenActivityCallback()->nextFireTime();
+    data.timeOfNextFullCollection = vm->heap.fullActivityCallback()->nextFireTime();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(RESOURCE_USAGE)
index e1c81af..2f678b3 100644 (file)
@@ -1,5 +1,18 @@
 2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Add initial implementation of resource usage overlay
+        https://bugs.webkit.org/show_bug.cgi?id=167731
+
+        Reviewed by Michael Catanzaro.
+
+        Toggle the resource usage overlay visibility by pressing CTRL + Shift + G. Only available when building with
+        developer mode enabled.
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseKeyPressEvent):
+
+2017-02-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         REGRESSION(r211486) [GTK] The MiniBrowser doesn't work anymore.
         https://bugs.webkit.org/show_bug.cgi?id=167776
 
index 04c7e95..b55af3e 100644 (file)
@@ -683,6 +683,15 @@ static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* k
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
+#if ENABLE(DEVELOPER_MODE) && OS(LINUX)
+    if ((keyEvent->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) && keyEvent->keyval == GDK_KEY_G) {
+        auto& preferences = priv->pageProxy->preferences();
+        preferences.setResourceUsageOverlayVisible(!preferences.resourceUsageOverlayVisible());
+        priv->shouldForwardNextKeyEvent = FALSE;
+        return TRUE;
+    }
+#endif
+
     if (priv->authenticationDialog)
         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, keyEvent);
 
index f24f169..71e1cb0 100644 (file)
@@ -171,6 +171,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_CONTROLS_SCRIPT PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MHTML PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NOTIFICATIONS PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PUBLIC_SUFFIX_LIST PRIVATE ON)
+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_RESOURCE_USAGE PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SMOOTH_SCROLLING PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_USERSELECT_ALL PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_USER_MESSAGE_HANDLERS PRIVATE ON)