[WTF] Add generic implementation for Memory querying
authordon.olmstead@sony.com <don.olmstead@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2018 03:01:40 +0000 (03:01 +0000)
committerdon.olmstead@sony.com <don.olmstead@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2018 03:01:40 +0000 (03:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188867

Reviewed by Fujii Hironori.

Moves generic implementation of MemoryPressureHandler from
MemoryPressureHandler.cpp into MemoryPressureHandlerGeneric
and generic implementation of memoryFootprint from
MemoryFootprintLinux.cpp to MemoryFootprintGeneric.

* wtf/MemoryPressureHandler.cpp:
(WTF::MemoryPressureHandler::install): Deleted.
(WTF::MemoryPressureHandler::uninstall): Deleted.
(WTF::MemoryPressureHandler::respondToMemoryPressure): Deleted.
(WTF::MemoryPressureHandler::platformReleaseMemory): Deleted.
(WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage): Deleted.
* wtf/PlatformJSCOnly.cmake:
* wtf/generic/MemoryFootprintGeneric.cpp: Added.
(WTF::memoryFootprint):
* wtf/generic/MemoryPressureHandlerGeneric.cpp: Added.
(WTF::MemoryPressureHandler::memoryMeasurementTimerFired):
(WTF::MemoryPressureHandler::platformReleaseMemory):
(WTF::MemoryPressureHandler::install):
(WTF::MemoryPressureHandler::uninstall):
(WTF::MemoryPressureHandler::holdOff):
(WTF::MemoryPressureHandler::respondToMemoryPressure):
(WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
* wtf/linux/CurrentProcessMemoryStatus.cpp:
* wtf/linux/CurrentProcessMemoryStatus.h:
* wtf/linux/MemoryFootprintLinux.cpp:
(WTF::computeMemoryFootprint):
(WTF::memoryFootprint):
* wtf/linux/MemoryPressureHandlerLinux.cpp:

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

Source/WTF/ChangeLog
Source/WTF/wtf/MemoryPressureHandler.cpp
Source/WTF/wtf/PlatformJSCOnly.cmake
Source/WTF/wtf/generic/MemoryFootprintGeneric.cpp [new file with mode: 0644]
Source/WTF/wtf/generic/MemoryPressureHandlerGeneric.cpp [new file with mode: 0644]
Source/WTF/wtf/linux/CurrentProcessMemoryStatus.cpp
Source/WTF/wtf/linux/CurrentProcessMemoryStatus.h
Source/WTF/wtf/linux/MemoryFootprintLinux.cpp
Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp

index d4eaa08..a30e24d 100644 (file)
@@ -1,3 +1,39 @@
+2018-08-22  Don Olmstead  <don.olmstead@sony.com>
+
+        [WTF] Add generic implementation for Memory querying
+        https://bugs.webkit.org/show_bug.cgi?id=188867
+
+        Reviewed by Fujii Hironori.
+
+        Moves generic implementation of MemoryPressureHandler from
+        MemoryPressureHandler.cpp into MemoryPressureHandlerGeneric
+        and generic implementation of memoryFootprint from
+        MemoryFootprintLinux.cpp to MemoryFootprintGeneric.
+
+        * wtf/MemoryPressureHandler.cpp:
+        (WTF::MemoryPressureHandler::install): Deleted.
+        (WTF::MemoryPressureHandler::uninstall): Deleted.
+        (WTF::MemoryPressureHandler::respondToMemoryPressure): Deleted.
+        (WTF::MemoryPressureHandler::platformReleaseMemory): Deleted.
+        (WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage): Deleted.
+        * wtf/PlatformJSCOnly.cmake:
+        * wtf/generic/MemoryFootprintGeneric.cpp: Added.
+        (WTF::memoryFootprint):
+        * wtf/generic/MemoryPressureHandlerGeneric.cpp: Added.
+        (WTF::MemoryPressureHandler::memoryMeasurementTimerFired):
+        (WTF::MemoryPressureHandler::platformReleaseMemory):
+        (WTF::MemoryPressureHandler::install):
+        (WTF::MemoryPressureHandler::uninstall):
+        (WTF::MemoryPressureHandler::holdOff):
+        (WTF::MemoryPressureHandler::respondToMemoryPressure):
+        (WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
+        * wtf/linux/CurrentProcessMemoryStatus.cpp:
+        * wtf/linux/CurrentProcessMemoryStatus.h:
+        * wtf/linux/MemoryFootprintLinux.cpp:
+        (WTF::computeMemoryFootprint):
+        (WTF::memoryFootprint):
+        * wtf/linux/MemoryPressureHandlerLinux.cpp:
+
 2018-08-21  Antti Koivisto  <antti@apple.com>
 
         Allow creating WeakPtrs to const objects
index a7e4f42..9d0a140 100644 (file)
@@ -294,14 +294,6 @@ void MemoryPressureHandler::ReliefLogger::logMemoryUsageChange()
         m_initialMemory->physical, currentMemory->physical, physicalDiff);
 }
 
-#if !PLATFORM(COCOA) && !OS(LINUX) && !OS(WINDOWS)
-void MemoryPressureHandler::install() { }
-void MemoryPressureHandler::uninstall() { }
-void MemoryPressureHandler::respondToMemoryPressure(Critical, Synchronous) { }
-void MemoryPressureHandler::platformReleaseMemory(Critical) { }
-std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage() { return std::nullopt; }
-#endif
-
 #if !OS(WINDOWS)
 void MemoryPressureHandler::platformInitialize() { }
 #endif
index 525d9ee..4d0e0f1 100644 (file)
@@ -30,7 +30,6 @@ else ()
             unix/CPUTimeUnix.cpp
         )
     endif ()
-
 endif ()
 
 if (WIN32)
@@ -57,9 +56,19 @@ elseif (APPLE)
     list(APPEND WTF_INCLUDE_DIRECTORIES
         ${DERIVED_SOURCES_WTF_DIR}
     )
-else ()
+elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
     list(APPEND WTF_SOURCES
+        linux/CurrentProcessMemoryStatus.cpp
         linux/MemoryFootprintLinux.cpp
+        linux/MemoryPressureHandlerLinux.cpp
+    )
+    list(APPEND WTF_PUBLIC_HEADERS
+        linux/CurrentProcessMemoryStatus.h
+    )
+else ()
+    list(APPEND WTF_SOURCES
+        generic/MemoryFootprintGeneric.cpp
+        generic/MemoryPressureHandlerGeneric.cpp
     )
 endif ()
 
diff --git a/Source/WTF/wtf/generic/MemoryFootprintGeneric.cpp b/Source/WTF/wtf/generic/MemoryFootprintGeneric.cpp
new file mode 100644 (file)
index 0000000..f2ae830
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 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 "MemoryFootprint.h"
+
+namespace WTF {
+
+size_t memoryFootprint()
+{
+    return 0;
+}
+
+} // namespace WTF
diff --git a/Source/WTF/wtf/generic/MemoryPressureHandlerGeneric.cpp b/Source/WTF/wtf/generic/MemoryPressureHandlerGeneric.cpp
new file mode 100644 (file)
index 0000000..a2b570e
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2018 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 "MemoryPressureHandler.h"
+
+namespace WTF {
+
+void MemoryPressureHandler::memoryMeasurementTimerFired()
+{
+}
+
+void MemoryPressureHandler::platformReleaseMemory(Critical)
+{
+}
+
+void MemoryPressureHandler::install()
+{
+}
+
+void MemoryPressureHandler::uninstall()
+{
+}
+
+void MemoryPressureHandler::holdOff(Seconds seconds)
+{
+}
+
+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
+{
+}
+
+std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
+{
+    return std::nullopt;
+}
+
+} // namespace WTF
index 52ef0bb..8bb214a 100644 (file)
@@ -26,8 +26,6 @@
 #include "config.h"
 #include "CurrentProcessMemoryStatus.h"
 
-#if OS(LINUX)
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -73,5 +71,3 @@ void currentProcessMemoryStatus(ProcessMemoryStatus& memoryStatus)
 }
 
 } // namespace WTF
-
-#endif // OS(LINUX)
index 4082504..27b5b3e 100644 (file)
@@ -25,8 +25,6 @@
 
 #pragma once
 
-#if OS(LINUX)
-
 namespace WTF {
 
 struct ProcessMemoryStatus {
@@ -45,5 +43,3 @@ void currentProcessMemoryStatus(ProcessMemoryStatus&);
 
 using WTF::ProcessMemoryStatus;
 using WTF::currentProcessMemoryStatus;
-
-#endif // OS(LINUX)
index 7bc9d7c..0e4d546 100644 (file)
 #include "config.h"
 #include "MemoryFootprint.h"
 
-#if OS(LINUX)
 #include "MonotonicTime.h"
 #include <stdio.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringView.h>
-#endif
 
 namespace WTF {
 
-#if OS(LINUX)
 static const Seconds s_memoryFootprintUpdateInterval = 1_s;
 
 template<typename Functor>
@@ -88,11 +85,9 @@ static size_t computeMemoryFootprint()
     fclose(file);
     return totalPrivateDirtyInKB * KB;
 }
-#endif
 
 size_t memoryFootprint()
 {
-#if OS(LINUX)
     static size_t footprint = 0;
     static MonotonicTime previousUpdateTime = { };
     Seconds elapsed = MonotonicTime::now() - previousUpdateTime;
@@ -102,8 +97,6 @@ size_t memoryFootprint()
     }
 
     return footprint;
-#endif
-    return 0;
 }
 
-}
+} // namespace WTF
index 274367f..f9fbe23 100644 (file)
@@ -28,8 +28,6 @@
 #include "config.h"
 #include "MemoryPressureHandler.h"
 
-#if OS(LINUX)
-
 #include <malloc.h>
 #include <unistd.h>
 #include <wtf/MainThread.h>
@@ -138,7 +136,4 @@ std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHa
     return MemoryUsage {processMemoryUsage(), memoryFootprint()};
 }
 
-
 } // namespace WTF
-
-#endif // OS(LINUX)