[tools][perf] Fix linux-perf-d8.py with relative path args
We do change CWD in the script which breaks relative input paths to d8 and .js files for instance. Drive-by-fix: - Show clear warning if `perf record` failed Change-Id: Ib900ca6b53307e13be459beba1e96ddfc8ee9b79 No-try: true Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3593784 Reviewed-by: Victor Gomes <victorgomes@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/main@{#80057}
This commit is contained in:
parent
e2f9c45e6d
commit
6ca0c65c44
@ -81,7 +81,7 @@ def log(*args):
|
||||
if len(args) == 0:
|
||||
parser.error("No chrome binary provided")
|
||||
|
||||
chrome_bin = Path(args.pop(0))
|
||||
chrome_bin = Path(args.pop(0)).absolute()
|
||||
if not chrome_bin.exists():
|
||||
parser.error(f"Chrome '{chrome_bin}' does not exist")
|
||||
|
||||
@ -155,7 +155,10 @@ with tempfile.TemporaryDirectory(prefix="chrome-") as tmp_dir_path:
|
||||
log("LINUX PERF CMD: ", shlex.join(cmd))
|
||||
|
||||
if options.timeout is None:
|
||||
subprocess.run(cmd)
|
||||
try:
|
||||
subprocess.check_call(cmd)
|
||||
except:
|
||||
log("ERROR running perf record")
|
||||
else:
|
||||
process = subprocess.Popen(cmd)
|
||||
if not wait_for_process_timeout(process):
|
||||
@ -168,10 +171,14 @@ with tempfile.TemporaryDirectory(prefix="chrome-") as tmp_dir_path:
|
||||
child.send_signal(signal.SIGQUIT)
|
||||
# Wait for linux-perf to write out files
|
||||
time.sleep(1)
|
||||
process.send_signal(signal.SIGQUIT)
|
||||
process.wait()
|
||||
|
||||
# ==============================================================================
|
||||
return_status = process.poll()
|
||||
if return_status is None:
|
||||
log("Force quitting linux-perf")
|
||||
process.send_signal(signal.SIGQUIT)
|
||||
process.wait()
|
||||
elif return_status != 0:
|
||||
log("ERROR running perf record")
|
||||
# ==============================================================================
|
||||
log("PARALLEL POST PROCESSING: Injecting JS symbols")
|
||||
|
||||
|
||||
@ -182,7 +189,7 @@ def inject_v8_symbols(perf_dat_file):
|
||||
f"--output={output_file}"
|
||||
]
|
||||
try:
|
||||
subprocess.run(cmd)
|
||||
subprocess.check_call(cmd)
|
||||
print(f"Processed: {output_file}")
|
||||
except:
|
||||
print(shlex.join(cmd))
|
||||
|
@ -95,7 +95,7 @@ def log(*args):
|
||||
if len(args) == 0:
|
||||
parser.error("No d8 binary provided")
|
||||
|
||||
d8_bin = Path(args.pop(0))
|
||||
d8_bin = Path(args.pop(0)).absolute()
|
||||
if not d8_bin.exists():
|
||||
parser.error(f"D8 '{d8_bin}' does not exist")
|
||||
|
||||
@ -111,17 +111,38 @@ if not options.perf_data_dir.is_dir():
|
||||
if options.timeout and options.timeout < 0:
|
||||
parser.error("--timeout should be a positive number")
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
def make_path_absolute(maybe_path):
|
||||
if maybe_path.startswith("-"):
|
||||
return maybe_path
|
||||
path = Path(maybe_path)
|
||||
if path.exists():
|
||||
return str(path.absolute())
|
||||
return maybe_path
|
||||
|
||||
|
||||
def make_args_paths_absolute(args):
|
||||
return list(map(make_path_absolute, args))
|
||||
|
||||
|
||||
# Preprocess args if we change CWD to get cleaner output
|
||||
if options.perf_data_dir != Path.cwd():
|
||||
args = make_args_paths_absolute(args)
|
||||
|
||||
# ==============================================================================
|
||||
old_cwd = Path.cwd()
|
||||
os.chdir(options.perf_data_dir)
|
||||
|
||||
# ==============================================================================
|
||||
|
||||
cmd = [str(d8_bin), "--perf-prof"]
|
||||
|
||||
if not options.no_interpreted_frames_native_stack:
|
||||
cmd += ["--interpreted-frames-native-stack"]
|
||||
if options.perf_prof_annotate_wasm:
|
||||
cmd += ["--perf-prof-annotate-wasm"]
|
||||
|
||||
cmd += args
|
||||
log("D8 CMD: ", shlex.join(cmd))
|
||||
|
||||
@ -155,7 +176,10 @@ def wait_for_process_timeout(process):
|
||||
|
||||
|
||||
if options.timeout is None:
|
||||
subprocess.run(cmd)
|
||||
try:
|
||||
subprocess.check_call(cmd)
|
||||
except:
|
||||
log("ERROR running perf record")
|
||||
else:
|
||||
process = subprocess.Popen(cmd)
|
||||
if not wait_for_process_timeout(process):
|
||||
@ -168,8 +192,13 @@ else:
|
||||
child.send_signal(signal.SIGQUIT)
|
||||
# Wait for linux-perf to write out files
|
||||
time.sleep(1)
|
||||
process.send_signal(signal.SIGQUIT)
|
||||
process.wait()
|
||||
return_status = process.poll()
|
||||
if return_status is None:
|
||||
log("Force quitting linux-perf")
|
||||
process.send_signal(signal.SIGQUIT)
|
||||
process.wait()
|
||||
elif return_status != 0:
|
||||
log("ERROR running perf record")
|
||||
|
||||
# ==============================================================================
|
||||
log("POST PROCESSING: Injecting JS symbols")
|
||||
@ -182,7 +211,7 @@ def inject_v8_symbols(perf_dat_file):
|
||||
f"--output={output_file}"
|
||||
]
|
||||
try:
|
||||
subprocess.run(cmd)
|
||||
subprocess.check_call(cmd)
|
||||
print(f"Processed: {output_file}")
|
||||
except:
|
||||
print(shlex.join(cmd))
|
||||
|
Loading…
Reference in New Issue
Block a user