Commit 18cbf05e authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[gcmole] Re-write gcmole runner in Python

This removes the dependency on Lua for running gcmole, and Python's
expressiveness lets us clean up the code a bit, including getting rid
of global variables, embedding the multiprocessing (removing the need
for a separate `parallel.py`), and using difflib for printing the test
expectation diff.

Bug: v8:11169, v8:8590, chromium:1097212
Change-Id: If0ab5ea6f764864855d73cd0ba63cb37c1823955
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543927
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarLiviu Rau <liviurau@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71253}
parent 9f5b10b1
......@@ -8,12 +8,10 @@ group("v8_run_gcmole") {
testonly = true
data = [
"gccause.lua",
"GCMOLE.gn",
"gcmole.lua",
"gcmole.py",
"gcmole-test.cc",
"gcmole-tools/",
"parallel.py",
"run-gcmole.py",
"suspects.whitelist",
"ignored_files",
......
......@@ -117,5 +117,5 @@ set +x
echo
echo You can now run gcmole using this command:
echo
echo CLANG_BIN=\"tools/gcmole/gcmole-tools/bin\" lua tools/gcmole/gcmole.lua
echo CLANG_BIN=\"tools/gcmole/gcmole-tools/bin\" python tools/gcmole/gcmole.py
echo
-- Copyright 2011 the V8 project authors. All rights reserved.
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * 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.
-- * Neither the name of Google Inc. nor the names of its
-- contributors may be used to endorse or promote products derived
-- from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
-- OWNER 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.
-- This is an auxiliary tool that reads gccauses file generated by
-- gcmole.lua and prints tree of the calls that can potentially cause a GC
-- inside a given function.
--
-- Usage: lua tools/gcmole/gccause.lua <function-name-pattern>
--
assert(loadfile "gccauses")()
local P = ...
local T = {}
local function TrackCause(name, lvl)
io.write((" "):rep(lvl or 0), name, "\n")
if GC[name] then
local causes = GC[name]
for i = 1, #causes do
local f = causes[i]
if not T[f] then
T[f] = true
TrackCause(f, (lvl or 0) + 1)
end
if f == '<GC>' then break end
end
end
end
for name, _ in pairs(GC) do
if name:match(P) then
T = {}
TrackCause(name)
end
end
This diff is collapsed.
This diff is collapsed.
......@@ -49,5 +49,5 @@ echo $(readlink -f "${PACKAGE_FILE}")
echo
echo You can now run gcmole using this command:
echo
echo CLANG_BIN=\"tools/gcmole/gcmole-tools/bin\" lua tools/gcmole/gcmole.lua
echo CLANG_BIN=\"tools/gcmole/gcmole-tools/bin\" python tools/gcmole/gcmole.py
echo
#!/usr/bin/env python
# Copyright 2015 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
This script calls the first argument for each of the following arguments in
parallel. E.g.
parallel.py "clang --opt" file1 file2
calls
clang --opt file1
clang --opt file2
The output (stdout and stderr) is concatenated sequentially in the form:
______________ file1
<output of clang --opt file1>
______________ finish <exit code of clang --opt file1> ______________
______________ file2
<output of clang --opt file2>
______________ finish <exit code of clang --opt file2> ______________
"""
# for py2/py3 compatibility
from __future__ import print_function
import itertools
import multiprocessing
import subprocess
import sys
def invoke(cmdline):
try:
return (subprocess.check_output(
cmdline, shell=True, stderr=subprocess.STDOUT), 0)
except subprocess.CalledProcessError as e:
return (e.output, e.returncode)
if __name__ == '__main__':
assert len(sys.argv) > 2
processes = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=processes)
cmdlines = ["%s %s" % (sys.argv[1], filename) for filename in sys.argv[2:]]
for filename, result in itertools.izip(
sys.argv[2:], pool.imap(invoke, cmdlines)):
print("______________ %s" % filename)
print(result[0])
print("______________ finish %d ______________" % result[1])
......@@ -15,19 +15,18 @@ import sys
GCMOLE_PATH = os.path.dirname(os.path.abspath(__file__))
CLANG_BIN = os.path.join(GCMOLE_PATH, 'gcmole-tools', 'bin')
CLANG_PLUGINS = os.path.join(GCMOLE_PATH, 'gcmole-tools')
LUA = os.path.join(GCMOLE_PATH, 'gcmole-tools', 'lua52')
DRIVER = os.path.join(GCMOLE_PATH, 'gcmole.lua')
DRIVER = os.path.join(GCMOLE_PATH, 'gcmole.py')
BASE_PATH = os.path.dirname(os.path.dirname(GCMOLE_PATH))
assert len(sys.argv) == 2
assert len(sys.argv) >= 2
if not os.path.isfile("out/build/gen/torque-generated/builtin-definitions.h"):
print("Expected generated headers in out/build/gen.")
print("Either build v8 in out/build or change gcmole.lua:115")
print("Either build v8 in out/build or change the 'out/build/gen' location in gcmole.py")
sys.exit(-1)
proc = subprocess.Popen(
[LUA, DRIVER, sys.argv[1]],
["python", DRIVER] + sys.argv[1:],
env={'CLANG_BIN': CLANG_BIN, 'CLANG_PLUGINS': CLANG_PLUGINS},
cwd=BASE_PATH,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment