[WinCairo] Implement cpu and memory measuring functions.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Jun 2019 19:15:21 +0000 (19:15 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Jun 2019 19:15:21 +0000 (19:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198466

Patch by Takashi Komori <Takashi.Komori@sony.com> on 2019-06-04
Reviewed by Don Olmstead.

.:

* Source/cmake/OptionsWin.cmake:

Source/WebCore:

Tests: inspector/memory/tracking.html
       inspector/cpu-profiler/tracking.html

* PlatformWinCairo.cmake:
* page/ResourceUsageThread.h:
* page/win/ResourceUsageOverlayWin.cpp: Copied from Tools/WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp.
(WebCore::ResourceUsageOverlay::platformInitialize):
(WebCore::ResourceUsageOverlay::platformDestroy):
* page/win/ResourceUsageThreadWin.cpp: Added.
(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting):
(WebCore::fileTimeToUint64):
(WebCore::getCurrentCpuTime):
(WebCore::cpuUsage):
(WebCore::memoryUsage):
(WebCore::ResourceUsageThread::platformCollectCPUData):
(WebCore::ResourceUsageThread::platformCollectMemoryData):

Tools:

* WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp:
(WTR::TestRunner::inspectorTestStubURL):

LayoutTests:

* platform/wincairo/TestExpectations:

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

ChangeLog
LayoutTests/ChangeLog
LayoutTests/platform/wincairo/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/PlatformWinCairo.cmake
Source/WebCore/page/ResourceUsageThread.h
Source/WebCore/page/win/ResourceUsageOverlayWin.cpp [new file with mode: 0644]
Source/WebCore/page/win/ResourceUsageThreadWin.cpp [new file with mode: 0644]
Source/cmake/OptionsWin.cmake
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp

index 84c3750..78c804e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-06-04  Takashi Komori  <Takashi.Komori@sony.com>
+
+        [WinCairo] Implement cpu and memory measuring functions.
+        https://bugs.webkit.org/show_bug.cgi?id=198466
+
+        Reviewed by Don Olmstead.
+
+        * Source/cmake/OptionsWin.cmake:
+
 2019-06-03  Zan Dobersek  <zdobersek@igalia.com>
 
         [Nicosia] Disable async scrolling until implemented
index d2fb485..99432ed 100644 (file)
@@ -1,3 +1,12 @@
+2019-06-04  Takashi Komori  <Takashi.Komori@sony.com>
+
+        [WinCairo] Implement cpu and memory measuring functions.
+        https://bugs.webkit.org/show_bug.cgi?id=198466
+
+        Reviewed by Don Olmstead.
+
+        * platform/wincairo/TestExpectations:
+
 2019-06-02  Antoine Quint  <graouts@apple.com>
 
         [Pointer Events] Expose navigator.maxTouchPoints
index 5f10b53..8a9cd8a 100644 (file)
@@ -1564,6 +1564,9 @@ imported/blink [ Skip ]
 imported/mozilla [ Skip ]
 imported/w3c [ Skip ]
 inspector [ Skip ]
+inspector/memory/ [ Pass ]
+inspector/cpu-profiler/ [ Pass ]
+inspector/cpu-profiler/threads.html [ Failure ]
 js/dom/deep-recursion-test.html [ Failure ]
 js/dom/dom-static-property-for-in-iteration.html [ Failure ]
 js/dom/regress-157246.html [ Failure ]
index 62c174f..fd3a463 100644 (file)
@@ -1,3 +1,27 @@
+2019-06-04  Takashi Komori  <Takashi.Komori@sony.com>
+
+        [WinCairo] Implement cpu and memory measuring functions.
+        https://bugs.webkit.org/show_bug.cgi?id=198466
+
+        Reviewed by Don Olmstead.
+
+        Tests: inspector/memory/tracking.html
+               inspector/cpu-profiler/tracking.html
+
+        * PlatformWinCairo.cmake:
+        * page/ResourceUsageThread.h:
+        * page/win/ResourceUsageOverlayWin.cpp: Copied from Tools/WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp.
+        (WebCore::ResourceUsageOverlay::platformInitialize):
+        (WebCore::ResourceUsageOverlay::platformDestroy):
+        * page/win/ResourceUsageThreadWin.cpp: Added.
+        (WebCore::ResourceUsageThread::platformSaveStateBeforeStarting):
+        (WebCore::fileTimeToUint64):
+        (WebCore::getCurrentCpuTime):
+        (WebCore::cpuUsage):
+        (WebCore::memoryUsage):
+        (WebCore::ResourceUsageThread::platformCollectCPUData):
+        (WebCore::ResourceUsageThread::platformCollectMemoryData):
+
 2019-06-04  Antoine Quint  <graouts@apple.com>
 
         [Pointer Events] Only allow pointer capture if the pointer is in the active buttons state
index ed69d74..be04b83 100644 (file)
@@ -12,6 +12,8 @@ list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES
 
 list(APPEND WebCore_SOURCES
     page/win/FrameCairoWin.cpp
+    page/win/ResourceUsageOverlayWin.cpp
+    page/win/ResourceUsageThreadWin.cpp
 
     platform/graphics/GLContext.cpp
     platform/graphics/PlatformDisplay.cpp
index 35ae3f0..0e35ea2 100644 (file)
@@ -72,7 +72,7 @@ private:
     void recomputeCollectionMode();
 
     void createThreadIfNeeded();
-    void threadBody();
+    NO_RETURN void threadBody();
 
     void platformSaveStateBeforeStarting();
     void platformCollectCPUData(JSC::VM*, ResourceUsageData&);
diff --git a/Source/WebCore/page/win/ResourceUsageOverlayWin.cpp b/Source/WebCore/page/win/ResourceUsageOverlayWin.cpp
new file mode 100644 (file)
index 0000000..b7ba951
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ * Copyright (C) 2019 Sony Interactive Entertainment Inc.
+ *
+ * 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)
+
+namespace WebCore {
+
+void ResourceUsageOverlay::platformInitialize()
+{
+}
+
+void ResourceUsageOverlay::platformDestroy()
+{
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/page/win/ResourceUsageThreadWin.cpp b/Source/WebCore/page/win/ResourceUsageThreadWin.cpp
new file mode 100644 (file)
index 0000000..6ccd16c
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2019 Sony Interactive Entertainment Inc.
+ *
+ * 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 <JavaScriptCore/GCActivityCallback.h>
+#include <JavaScriptCore/VM.h>
+#include <psapi.h>
+
+namespace WebCore {
+
+void ResourceUsageThread::platformSaveStateBeforeStarting()
+{
+}
+
+static uint64_t fileTimeToUint64(FILETIME ft)
+{
+    ULARGE_INTEGER u;
+    u.LowPart = ft.dwLowDateTime;
+    u.HighPart = ft.dwHighDateTime;
+
+    return u.QuadPart;
+}
+
+static bool getCurrentCpuTime(uint64_t& nowTime, uint64_t& userTime, uint64_t& kernelTime)
+{
+    FILETIME creationFileTime, exitFileTime, kernelFileTime, userFileTime;
+    if (!GetProcessTimes(GetCurrentProcess(), &creationFileTime, &exitFileTime, &kernelFileTime, &userFileTime))
+        return false;
+
+    FILETIME nowFileTime;
+    GetSystemTimeAsFileTime(&nowFileTime);
+
+    nowTime = fileTimeToUint64(nowFileTime);
+    userTime = fileTimeToUint64(userFileTime);
+    kernelTime  = fileTimeToUint64(kernelFileTime);
+
+    return true;
+}
+
+static float cpuUsage()
+{
+    static int numberOfProcessors = 0;
+    static uint64_t lastTime = 0;
+    static uint64_t lastKernelTime = 0;
+    static uint64_t lastUserTime = 0;
+
+    if (!lastTime) {
+        SYSTEM_INFO systemInfo;
+        GetSystemInfo(&systemInfo);
+        numberOfProcessors = systemInfo.dwNumberOfProcessors;
+
+        getCurrentCpuTime(lastTime, lastKernelTime, lastUserTime);
+        return 0;
+    }
+
+    uint64_t nowTime, kernelTime, userTime;
+    if (!getCurrentCpuTime(nowTime, kernelTime, userTime))
+        return 0;
+
+    uint64_t elapsed = nowTime - lastTime;
+    uint64_t totalCPUTime = (kernelTime - lastKernelTime);
+    totalCPUTime += (userTime - lastUserTime);
+
+    lastTime = nowTime;
+    lastKernelTime = kernelTime;
+    lastUserTime = userTime;
+
+    float usage =  (100.0 * totalCPUTime) / elapsed / numberOfProcessors;
+    return clampTo<float>(usage, 0, 100);
+}
+
+static size_t memoryUsage()
+{
+    PROCESS_MEMORY_COUNTERS_EX pmc;
+    if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)))
+        return pmc.PrivateUsage;
+
+    return 0;
+}
+
+void ResourceUsageThread::platformCollectCPUData(JSC::VM*, ResourceUsageData& data)
+{
+    data.cpu = cpuUsage();
+
+    // FIXME: Exclude the ResourceUsage thread.
+    // FIXME: Exclude the SamplingProfiler thread.
+    // FIXME: Classify usage per thread.
+    data.cpuExcludingDebuggerThreads = data.cpu;
+}
+
+void ResourceUsageThread::platformCollectMemoryData(JSC::VM* vm, ResourceUsageData& data)
+{
+    data.totalDirtySize = memoryUsage();
+
+    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 = data.timestamp + vm->heap.edenActivityCallback()->timeUntilFire().valueOr(Seconds(std::numeric_limits<double>::infinity()));
+    data.timeOfNextFullCollection = data.timestamp + vm->heap.fullActivityCallback()->timeUntilFire().valueOr(Seconds(std::numeric_limits<double>::infinity()));
+}
+
+}
+
+#endif
index eae94ab..50e325b 100644 (file)
@@ -90,6 +90,7 @@ if (${WTF_PLATFORM_WIN_CAIRO})
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FILTERS_LEVEL_2 PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_REMOTE_INSPECTOR PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_RESOURCE_LOAD_STATISTICS PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
+    WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_RESOURCE_USAGE PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SERVICE_WORKER PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_VARIATION_FONTS PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEBDRIVER PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
index d6b3dc2..cc208af 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-04  Takashi Komori  <Takashi.Komori@sony.com>
+
+        [WinCairo] Implement cpu and memory measuring functions.
+        https://bugs.webkit.org/show_bug.cgi?id=198466
+
+        Reviewed by Don Olmstead.
+
+        * WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp:
+        (WTR::TestRunner::inspectorTestStubURL):
+
 2019-06-04  Zan Dobersek  <zdobersek@igalia.com>
 
         [misc] Remove JSCOnly ARMv7 Traditional bot
index 793b59b..79dc9fd 100644 (file)
@@ -27,6 +27,8 @@
 #include "TestRunner.h"
 
 #include "ActivateFonts.h"
+#include <shlwapi.h>
+#include <wininet.h>
 
 namespace WTR {
 
@@ -37,7 +39,25 @@ JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef)
 
 JSRetainPtr<JSStringRef> TestRunner::inspectorTestStubURL()
 {
-    return JSStringCreateWithUTF8CString("");
+    wchar_t exePath[MAX_PATH];
+    if (::GetModuleFileName(nullptr, exePath, MAX_PATH)) {
+        wchar_t drive[_MAX_DRIVE];
+        wchar_t dir[_MAX_DIR];
+        _wsplitpath(exePath, drive, dir, nullptr, nullptr);
+
+        wchar_t stubPath[MAX_PATH];
+        wcsncpy(stubPath, drive, MAX_PATH);
+        wcsncat(stubPath, dir, MAX_PATH - wcslen(stubPath));
+        wcsncat(stubPath, L"\\WebKit.resources\\WebInspectorUI\\TestStub.html", MAX_PATH - wcslen(stubPath));
+
+        wchar_t fileURI[INTERNET_MAX_PATH_LENGTH];
+        DWORD fileURILength = INTERNET_MAX_PATH_LENGTH;
+        UrlCreateFromPathW(stubPath, fileURI, &fileURILength, 0);
+
+        return JSStringCreateWithCharacters(fileURI, fileURILength);
+    }
+
+    return nullptr;
 }
 
 void TestRunner::platformInitialize()