Title: [259652] trunk
Revision
259652
Author
sbar...@apple.com
Date
2020-04-07 11:41:13 -0700 (Tue, 07 Apr 2020)

Log Message

RAMification should have a way of gathering vmmaps for each test at the end of each run
https://bugs.webkit.org/show_bug.cgi?id=210060

Reviewed by Yusuke Suzuki.

PerformanceTests:

When I was debugging a memory issue, I needed to gather vmmaps for each
RAMification subtest. This patch is checking in the code I wrote to be able
to do this. It works by:
- Passing in an argument to RAMification saying we want vmmaps at the end of
each subtest run.
- RAMification invokes jsc with an environment variable that tells the shell
to wait for one character of input from stdin before exiting.
- The jsc shell also disables the bmalloc scavenger while waiting for input so the
vmmap we take from the python runner script represents the "footprint" score
of the benchmark. If the scavenger ran, it would end up releasing too much
memory for the vmmap to be useful.
- The python script runs a vmmap, and then communicates to the jsc process
when the vmmap finishes running.

* JetStream2/RAMification.py:
(parseArgs):
(BaseRunner.__init__):
(BaseRunner.getResults):
(LocalRunner.runOneTest):
(main):
(main.runTestList):

Source/bmalloc:

* bmalloc/Scavenger.cpp:
(bmalloc::Scavenger::scavenge):
(bmalloc::Scavenger::partialScavenge):
* bmalloc/Scavenger.h:
(bmalloc::Scavenger::disable):
* bmalloc/bmalloc.cpp:
(bmalloc::api::disableScavenger):
* bmalloc/bmalloc.h:

Source/_javascript_Core:

* jsc.cpp:
(main):

Source/WTF:

* wtf/FastMalloc.cpp:
(WTF::fastDisableScavenger):
* wtf/FastMalloc.h:

Modified Paths

Diff

Modified: trunk/PerformanceTests/ChangeLog (259651 => 259652)


--- trunk/PerformanceTests/ChangeLog	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/PerformanceTests/ChangeLog	2020-04-07 18:41:13 UTC (rev 259652)
@@ -1,3 +1,32 @@
+2020-04-07  Saam Barati  <sbar...@apple.com>
+
+        RAMification should have a way of gathering vmmaps for each test at the end of each run
+        https://bugs.webkit.org/show_bug.cgi?id=210060
+
+        Reviewed by Yusuke Suzuki.
+
+        When I was debugging a memory issue, I needed to gather vmmaps for each
+        RAMification subtest. This patch is checking in the code I wrote to be able
+        to do this. It works by:
+        - Passing in an argument to RAMification saying we want vmmaps at the end of
+        each subtest run.
+        - RAMification invokes jsc with an environment variable that tells the shell
+        to wait for one character of input from stdin before exiting.
+        - The jsc shell also disables the bmalloc scavenger while waiting for input so the
+        vmmap we take from the python runner script represents the "footprint" score
+        of the benchmark. If the scavenger ran, it would end up releasing too much
+        memory for the vmmap to be useful.
+        - The python script runs a vmmap, and then communicates to the jsc process
+        when the vmmap finishes running.
+
+        * JetStream2/RAMification.py:
+        (parseArgs):
+        (BaseRunner.__init__):
+        (BaseRunner.getResults):
+        (LocalRunner.runOneTest):
+        (main):
+        (main.runTestList):
+
 2020-04-06  Saam Barati  <sbar...@apple.com>
 
         Implement 1GB of executable memory on arm64

Modified: trunk/PerformanceTests/JetStream2/RAMification.py (259651 => 259652)


--- trunk/PerformanceTests/JetStream2/RAMification.py	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/PerformanceTests/JetStream2/RAMification.py	2020-04-07 18:41:13 UTC (rev 259652)
@@ -43,7 +43,7 @@
 footprintRE = re.compile("Current Footprint: (\d+(?:.\d+)?)")
 peakFootprintRE = re.compile("Peak Footprint: (\d+(?:.\d+)?)")
 
-TestResult = collections.namedtuple("TestResult", ["name", "returnCode", "footprint", "peakFootprint"])
+TestResult = collections.namedtuple("TestResult", ["name", "returnCode", "footprint", "peakFootprint", "vmmapOutput"])
 
 ramification_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
 
@@ -120,6 +120,7 @@
     parser.add_argument("-l", "--lua", dest="runLuaTests", nargs="?", const=True, default=None, type=optStrToBool, metavar="true / false", help="Run Lua comparison tests [default]")
     parser.add_argument("-n", "--run-no-jit", dest="runNoJITTests", nargs="?", const=True, default=None, type=optStrToBool, metavar="true / false", help="Run no JIT tests [default]")
     parser.add_argument("-o", "--output", dest="jsonFilename", type=str, default=None, metavar="JSON-output-file", help="Path to JSON output")
+    parser.add_argument("-m", "--vmmap", dest="takeVmmap", action="" default=False, help="Take a vmmap after each test")
 
     args = parser.parse_args()
 
@@ -146,6 +147,7 @@
     def __init__(self, args):
         self.rootDir = args.testDir
         self.environmentVars = {}
+        self.vmmapOutput = ""
 
     def setup(self):
         pass
@@ -178,7 +180,7 @@
         self.returnCode = returnCode
 
     def getResults(self):
-        return TestResult(name=self.testName, returnCode=self.returnCode, footprint=self.footprint, peakFootprint=self.peakFootprint)
+        return TestResult(name=self.testName, returnCode=self.returnCode, footprint=self.footprint, peakFootprint=self.peakFootprint, vmmapOutput=self.vmmapOutput)
 
 
 class LocalRunner(BaseRunner):
@@ -200,7 +202,7 @@
 
         self.resetForTest(test)
 
-        proc = subprocess.Popen(args, cwd=self.rootDir, env=self.environmentVars, stdout=subprocess.PIPE, stderr=None, shell=False)
+        proc = subprocess.Popen(args, cwd=self.rootDir, env=self.environmentVars, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=None, shell=False)
         while True:
             line = proc.stdout.readline()
             if sys.version_info[0] >= 3:
@@ -208,6 +210,13 @@
 
             self.processLine(line)
 
+            if "js shell waiting for input to exit" in line:
+                self.vmmapOutput = subprocess.Popen(['vmmap', '--summary', '{}'.format(proc.pid)], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE).stdout.read()
+                if sys.version_info[0] >= 3:
+                    self.vmmapOutput = str(self.vmmapOutput, "utf-8")
+                proc.stdin.write(b"done\n")
+                proc.stdin.flush()
+
             if line == "":
                 break
 
@@ -226,6 +235,10 @@
 
     testRunner = args.runner(args)
 
+
+    if args.takeVmmap:
+        testRunner.setEnv("JS_SHELL_WAIT_FOR_INPUT_TO_EXIT", "1")
+
     dyldFrameworkPath = frameworkPathFromExecutablePath(args.jscCommand)
     if dyldFrameworkPath:
         testRunner.setEnv("DYLD_FRAMEWORK_PATH", dyldFrameworkPath)
@@ -255,6 +268,8 @@
             if testResult.returnCode == 0 and testResult.footprint and testResult.peakFootprint:
                 if args.verbose:
                     print("footprint: {}, peak footprint: {}".format(testResult.footprint, testResult.peakFootprint))
+                    if testResult.vmmapOutput:
+                        print(testResult.vmmapOutput)
                 else:
                     print
 

Modified: trunk/Source/_javascript_Core/ChangeLog (259651 => 259652)


--- trunk/Source/_javascript_Core/ChangeLog	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-04-07 18:41:13 UTC (rev 259652)
@@ -1,3 +1,13 @@
+2020-04-07  Saam Barati  <sbar...@apple.com>
+
+        RAMification should have a way of gathering vmmaps for each test at the end of each run
+        https://bugs.webkit.org/show_bug.cgi?id=210060
+
+        Reviewed by Yusuke Suzuki.
+
+        * jsc.cpp:
+        (main):
+
 2020-04-07  Yusuke Suzuki  <ysuz...@apple.com>
 
         [JSC] ScopedArgumentsTable should handle OOM in tolerant manner

Modified: trunk/Source/_javascript_Core/jsc.cpp (259651 => 259652)


--- trunk/Source/_javascript_Core/jsc.cpp	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/_javascript_Core/jsc.cpp	2020-04-07 18:41:13 UTC (rev 259652)
@@ -2528,6 +2528,12 @@
         res = jscmain(argc, argv);
     EXCEPT(res = 3)
     finalizeStatsAtEndOfTesting();
+    if (getenv("JS_SHELL_WAIT_FOR_INPUT_TO_EXIT")) {
+        WTF::fastDisableScavenger();
+        fprintf(stdout, "\njs shell waiting for input to exit\n");
+        fflush(stdout);
+        getc(stdin);
+    }
 
     jscExit(res);
 }

Modified: trunk/Source/WTF/ChangeLog (259651 => 259652)


--- trunk/Source/WTF/ChangeLog	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/WTF/ChangeLog	2020-04-07 18:41:13 UTC (rev 259652)
@@ -1,3 +1,14 @@
+2020-04-07  Saam Barati  <sbar...@apple.com>
+
+        RAMification should have a way of gathering vmmaps for each test at the end of each run
+        https://bugs.webkit.org/show_bug.cgi?id=210060
+
+        Reviewed by Yusuke Suzuki.
+
+        * wtf/FastMalloc.cpp:
+        (WTF::fastDisableScavenger):
+        * wtf/FastMalloc.h:
+
 2020-04-06  Ross Kirsling  <ross.kirsl...@sony.com>
 
         Update minimum ICU version to 60.2

Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (259651 => 259652)


--- trunk/Source/WTF/wtf/FastMalloc.cpp	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp	2020-04-07 18:41:13 UTC (rev 259652)
@@ -274,6 +274,8 @@
 
 void fastEnableMiniMode() { }
 
+void fastDisableScavenger() { }
+
 void fastMallocDumpMallocStats() { }
 
 } // namespace WTF
@@ -632,6 +634,11 @@
     bmalloc::api::enableMiniMode();
 }
 
+void fastDisableScavenger()
+{
+    bmalloc::api::disableScavenger();
+}
+
 } // namespace WTF
 
 #endif // defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC

Modified: trunk/Source/WTF/wtf/FastMalloc.h (259651 => 259652)


--- trunk/Source/WTF/wtf/FastMalloc.h	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/WTF/wtf/FastMalloc.h	2020-04-07 18:41:13 UTC (rev 259652)
@@ -76,6 +76,8 @@
 
 WTF_EXPORT_PRIVATE void fastEnableMiniMode();
 
+WTF_EXPORT_PRIVATE void fastDisableScavenger();
+
 struct FastMallocStatistics {
     size_t reservedVMBytes;
     size_t committedVMBytes;

Modified: trunk/Source/bmalloc/ChangeLog (259651 => 259652)


--- trunk/Source/bmalloc/ChangeLog	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/bmalloc/ChangeLog	2020-04-07 18:41:13 UTC (rev 259652)
@@ -1,3 +1,19 @@
+2020-04-07  Saam Barati  <sbar...@apple.com>
+
+        RAMification should have a way of gathering vmmaps for each test at the end of each run
+        https://bugs.webkit.org/show_bug.cgi?id=210060
+
+        Reviewed by Yusuke Suzuki.
+
+        * bmalloc/Scavenger.cpp:
+        (bmalloc::Scavenger::scavenge):
+        (bmalloc::Scavenger::partialScavenge):
+        * bmalloc/Scavenger.h:
+        (bmalloc::Scavenger::disable):
+        * bmalloc/bmalloc.cpp:
+        (bmalloc::api::disableScavenger):
+        * bmalloc/bmalloc.h:
+
 2020-04-03  David Kilzer  <ddkil...@apple.com>
 
         [Xcode] Replace ASAN_OTHER_CFLAGS and ASAN_OTHER_CPLUSPLUSFLAGS with $(inherited)

Modified: trunk/Source/bmalloc/bmalloc/Scavenger.cpp (259651 => 259652)


--- trunk/Source/bmalloc/bmalloc/Scavenger.cpp	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/bmalloc/bmalloc/Scavenger.cpp	2020-04-07 18:41:13 UTC (rev 259652)
@@ -204,6 +204,9 @@
 
 void Scavenger::scavenge()
 {
+    if (!m_isEnabled)
+        return;
+
     UniqueLockHolder lock(m_scavengingMutex);
 
     if (verbose) {
@@ -279,6 +282,9 @@
 #if BUSE(PARTIAL_SCAVENGE)
 void Scavenger::partialScavenge()
 {
+    if (!m_isEnabled)
+        return;
+
     UniqueLockHolder lock(m_scavengingMutex);
 
     if (verbose) {

Modified: trunk/Source/bmalloc/bmalloc/Scavenger.h (259651 => 259652)


--- trunk/Source/bmalloc/bmalloc/Scavenger.h	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/bmalloc/bmalloc/Scavenger.h	2020-04-07 18:41:13 UTC (rev 259652)
@@ -74,6 +74,9 @@
 
     void enableMiniMode();
 
+    // Used for debugging only.
+    void disable() { m_isEnabled = false; }
+
 private:
     enum class State { Sleep, Run, RunSoon };
     
@@ -115,6 +118,7 @@
 #endif
     
     Vector<DeferredDecommit> m_deferredDecommits;
+    bool m_isEnabled { true };
 };
 DECLARE_STATIC_PER_PROCESS_STORAGE(Scavenger);
 

Modified: trunk/Source/bmalloc/bmalloc/bmalloc.cpp (259651 => 259652)


--- trunk/Source/bmalloc/bmalloc/bmalloc.cpp	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.cpp	2020-04-07 18:41:13 UTC (rev 259652)
@@ -135,5 +135,11 @@
         Scavenger::get()->enableMiniMode();
 }
 
+void disableScavenger()
+{
+    if (!DebugHeap::tryGet())
+        Scavenger::get()->disable();
+}
+
 } } // namespace bmalloc::api
 

Modified: trunk/Source/bmalloc/bmalloc/bmalloc.h (259651 => 259652)


--- trunk/Source/bmalloc/bmalloc/bmalloc.h	2020-04-07 18:40:07 UTC (rev 259651)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.h	2020-04-07 18:41:13 UTC (rev 259652)
@@ -129,5 +129,8 @@
 
 BEXPORT void enableMiniMode();
 
+// Used for debugging only.
+BEXPORT void disableScavenger();
+
 } // namespace api
 } // namespace bmalloc
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to