OpenSource MemoryFootprint API for JSC command line tool
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Aug 2019 20:48:37 +0000 (20:48 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Aug 2019 20:48:37 +0000 (20:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200541

Reviewed by Saam Barati.

Source/JavaScriptCore:

Use wtf/spi/darwin/ProcessMemoryFootprint.h instead of WebKitAdditions/MemoryFootprint.h
for process memory stats.

* jsc.cpp:
(MemoryFootprint::MemoryFootprint):

Source/WTF:

OpenSource version of WebKitAdditions/MemoryFootprint.h.

* WTF.xcodeproj/project.pbxproj:
* wtf/spi/darwin/ProcessMemoryFootprint.h: Added.
(ProcessMemoryFootprint::now):
(ProcessMemoryFootprint::resetPeak):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/jsc.cpp
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/spi/darwin/ProcessMemoryFootprint.h [new file with mode: 0644]

index f91c245..d96b139 100644 (file)
@@ -1,3 +1,16 @@
+2019-08-08  Michael Saboff  <msaboff@apple.com>
+
+        OpenSource MemoryFootprint API for JSC command line tool
+        https://bugs.webkit.org/show_bug.cgi?id=200541
+
+        Reviewed by Saam Barati.
+
+        Use wtf/spi/darwin/ProcessMemoryFootprint.h instead of WebKitAdditions/MemoryFootprint.h
+        for process memory stats.
+
+        * jsc.cpp:
+        (MemoryFootprint::MemoryFootprint):
+
 2019-08-08  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: rename `queryObjects` to `queryInstances` for clarity
index ead01e2..4122fbe 100644 (file)
 #include <arm/arch.h>
 #endif
 
-#if __has_include(<WebKitAdditions/MemoryFootprint.h>)
-#include <WebKitAdditions/MemoryFootprint.h>
+#if OS(DARWIN)
+#include <wtf/spi/darwin/ProcessMemoryFootprint.h>
+struct MemoryFootprint : ProcessMemoryFootprint {
+    MemoryFootprint(const ProcessMemoryFootprint& src)
+        : ProcessMemoryFootprint(src)
+    {
+    }
+};
 #else
 struct MemoryFootprint {
     uint64_t current;
     uint64_t peak;
-    
+
     static MemoryFootprint now()
     {
         return { 0L, 0L };
index 737647f..e0832ef 100644 (file)
@@ -1,3 +1,17 @@
+2019-08-08  Michael Saboff  <msaboff@apple.com>
+
+        OpenSource MemoryFootprint API for JSC command line tool
+        https://bugs.webkit.org/show_bug.cgi?id=200541
+
+        Reviewed by Saam Barati.
+
+        OpenSource version of WebKitAdditions/MemoryFootprint.h.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/spi/darwin/ProcessMemoryFootprint.h: Added.
+        (ProcessMemoryFootprint::now):
+        (ProcessMemoryFootprint::resetPeak):
+
 2019-08-08  Per Arne Vollan  <pvollan@apple.com>
 
         [Mac] Use the PID of the WebContent process when issuing local file read sandbox extensions
index d1d5f9b..9ef5683 100644 (file)
                5FAD3AE021B9636600BEE178 /* URLHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = URLHelpers.h; sourceTree = "<group>"; };
                5FAD3AE121B9636600BEE178 /* URLHelpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLHelpers.cpp; sourceTree = "<group>"; };
                6541CAF41630DB26006D0DEC /* CopyWTFHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyWTFHeaders.xcconfig; sourceTree = "<group>"; };
+               6593CDE922FA4A520087714B /* ProcessMemoryFootprint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessMemoryFootprint.h; sourceTree = "<group>"; };
                70A993FC1AD7151300FA615B /* SymbolRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SymbolRegistry.cpp; sourceTree = "<group>"; };
                70A993FD1AD7151300FA615B /* SymbolRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SymbolRegistry.h; sourceTree = "<group>"; };
                70ECA60A1B02426800449739 /* AtomStringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomStringImpl.cpp; sourceTree = "<group>"; };
                                14933E21228C22DF00F79E46 /* DataVaultSPI.h */,
                                E431CC4A21187ADB000C8A07 /* DispatchSPI.h */,
                                93DDE9311CDC052D00FD3491 /* dyldSPI.h */,
+                               6593CDE922FA4A520087714B /* ProcessMemoryFootprint.h */,
                                A5098AFF1C169E0700087797 /* SandboxSPI.h */,
                                CE73E02419DCB7AB00580D5C /* XPCSPI.h */,
                        );
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                        shellPath = /bin/sh;
-                       shellScript = "if [[ \"${DEPLOYMENT_LOCATION}\" == \"NO\" ]]; then\n    PRIVATE_HEADERS_PATH=\"${TARGET_BUILD_DIR%/}/${PRIVATE_HEADERS_FOLDER_PATH}\"\n    ICU_PRIVATE_HEADERS_PATH=\"${TARGET_BUILD_DIR%/}/${ICU_PRIVATE_HEADERS_FOLDER_PATH}\"\nelse\n    PRIVATE_HEADERS_PATH=\"${DSTROOT}/${PRIVATE_HEADERS_FOLDER_PATH}\"\n    ICU_PRIVATE_HEADERS_PATH=\"${DSTROOT}/${ICU_PRIVATE_HEADERS_FOLDER_PATH}\"\nfi;\n\nmkdir -p \"${PRIVATE_HEADERS_PATH}\"\nrsync -av --no-owner --no-group --prune-empty-dirs --exclude \".svn\" --exclude \"usr\" --exclude \"DerivedSources\" --include \"*/\" --include \"*.h\" --exclude \"*\" \"${SRCROOT}/wtf/\" \"${PRIVATE_HEADERS_PATH}\"\n\nrsync -av --no-owner --no-group --prune-empty-dirs --exclude \".svn\" --exclude \"usr\" --exclude \"DerivedSources\" --include \"*/\" --include \"*.rb\" --exclude \"*\" \"${SRCROOT}/Scripts\" \"${PRIVATE_HEADERS_PATH}\"\n\nif [[ \"${USE_INTERNAL_SDK}\" != \"YES\" ]]; then\nmkdir -p \"${ICU_PRIVATE_HEADERS_PATH}\"\nrsync -av --no-owner --no-group --prune-empty-dirs --exclude \".svn\" --exclude \"usr\" --exclude \"DerivedSources\" --include \"*/\" --include \"*.h\" --exclude \"*\" \"${SRCROOT}/icu/\" \"${ICU_PRIVATE_HEADERS_PATH}\"\nfi";
+                       shellScript = "if [[ \"${DEPLOYMENT_LOCATION}\" == \"NO\" ]]; then\n    PRIVATE_HEADERS_PATH=\"${TARGET_BUILD_DIR%/}/${PRIVATE_HEADERS_FOLDER_PATH}\"\n    ICU_PRIVATE_HEADERS_PATH=\"${TARGET_BUILD_DIR%/}/${ICU_PRIVATE_HEADERS_FOLDER_PATH}\"\nelse\n    PRIVATE_HEADERS_PATH=\"${DSTROOT}/${PRIVATE_HEADERS_FOLDER_PATH}\"\n    ICU_PRIVATE_HEADERS_PATH=\"${DSTROOT}/${ICU_PRIVATE_HEADERS_FOLDER_PATH}\"\nfi;\n\nmkdir -p \"${PRIVATE_HEADERS_PATH}\"\nrsync -av --no-owner --no-group --prune-empty-dirs --exclude \".svn\" --exclude \"usr\" --exclude \"DerivedSources\" --include \"*/\" --include \"*.h\" --exclude \"*\" \"${SRCROOT}/wtf/\" \"${PRIVATE_HEADERS_PATH}\"\n\nrsync -av --no-owner --no-group --prune-empty-dirs --exclude \".svn\" --exclude \"usr\" --exclude \"DerivedSources\" --include \"*/\" --include \"*.rb\" --exclude \"*\" \"${SRCROOT}/Scripts\" \"${PRIVATE_HEADERS_PATH}\"\n\nif [[ \"${USE_INTERNAL_SDK}\" != \"YES\" ]]; then\nmkdir -p \"${ICU_PRIVATE_HEADERS_PATH}\"\nrsync -av --no-owner --no-group --prune-empty-dirs --exclude \".svn\" --exclude \"usr\" --exclude \"DerivedSources\" --include \"*/\" --include \"*.h\" --exclude \"*\" \"${SRCROOT}/icu/\" \"${ICU_PRIVATE_HEADERS_PATH}\"\nfi\n";
                };
 /* End PBXShellScriptBuildPhase section */
 
diff --git a/Source/WTF/wtf/spi/darwin/ProcessMemoryFootprint.h b/Source/WTF/wtf/spi/darwin/ProcessMemoryFootprint.h
new file mode 100644 (file)
index 0000000..90852df
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
+ *
+ * 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. ``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
+ * 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.
+ */
+
+#pragma once
+
+#if OS(DARWIN)
+
+#if !PLATFORM(IOS_FAMILY_SIMULATOR) && __has_include(<libproc.h>)
+#    include <libproc.h>
+#    if RUSAGE_INFO_CURRENT >= 4
+#        define HAS_MAX_FOOTPRINT
+#        if defined(RLIMIT_FOOTPRINT_INTERVAL) && __has_include(<libproc_internal.h>) \
+             && ((PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) \
+                 || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400))
+#            define HAS_RESET_FOOTPRINT_INTERVAL
+#            define MAX_FOOTPRINT_FIELD ri_interval_max_phys_footprint
+#            include <libproc_internal.h>
+#        else
+#            define MAX_FOOTPRINT_FIELD ri_lifetime_max_phys_footprint
+#        endif
+#    else
+#        define HAS_ONLY_PHYS_FOOTPRINT
+#    endif
+#endif
+
+struct ProcessMemoryFootprint {
+public:
+    uint64_t current;
+    uint64_t peak;
+
+    static ProcessMemoryFootprint now()
+    {
+#ifdef HAS_MAX_FOOTPRINT
+        rusage_info_v4 rusage;
+        if (proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&rusage))
+            return { 0L, 0L };
+
+        return { rusage.ri_phys_footprint, rusage.MAX_FOOTPRINT_FIELD };
+#elif defined(HAS_ONLY_PHYS_FOOTPRINT)
+        rusage_info_v0 rusage;
+        if (proc_pid_rusage(getpid(), RUSAGE_INFO_V0, (rusage_info_t *)&rusage))
+            return { 0L, 0L };
+
+        return { rusage.ri_phys_footprint, 0L };
+#else
+        return { 0L, 0L };
+#endif
+    }
+
+    static void resetPeak()
+    {
+#ifdef HAS_RESET_FOOTPRINT_INTERVAL
+        proc_reset_footprint_interval(getpid());
+#endif
+    }
+};
+
+#endif