def config(path, samrai_dir=None, cxx_flags=None, use_ninja=False, use_ccache=False, extra=""): cmd = make_config_str(path, samrai_dir, cxx_flags, use_ninja, extra) run(cmd, capture_output=False)
def check(force_kernel_space=False): """ perf can require some system config / read the error if thrown """ kernel_space_opt = "a" if force_kernel_space else "" run(f"perf stat -{kernel_space_opt}d sleep 1", shell=True, capture_output=True, check=True) record("ls", [], "/tmp/perf_record_check.dat")
def checkout(branch, create=False, recreate=False): if recreate: delete_branch(branch) create = True if create and not branch_exists(branch): run(f"git checkout -b {branch}") else: run(f"git checkout {branch}")
def build(use_ninja=False, threads=1): run("ninja" if use_ninja else f"make -j{threads}", capture_output=False)
def record(exe, events, output_file=None): return run(record_cmd(exe, events, output_file), check=True)
def stat(exe, events, output_file=None): return run(stat_cmd(exe, events, output_file), check=True)
def version(): # validated on perf version: 5.19 proc = run("perf -v", shell=True, capture_output=True) if " " not in proc or "." not in proc: raise ValueError("Unparsable result from 'perf -v'") return [int(digit) for digit in proc.split(" ").split(".")]
def run_test(test, verbose=False, capture_output=False): run(test_cmd(cmd, verbose=verbose), capture_output=capture_output)
def list_tests(): proc = run("ctest -N", capture_output=True) out = decode_bytes(proc.stdout) return [line.split(" ")[-1] for line in out.splitlines()[1:-2]]
def hashes(N=1): return decode_bytes( run(f"git log -{N} --pretty=format:%h").stdout).splitlines()
def current_branch(): return decode_bytes(run("git branch --show-current").stdout)
def branch_exists(branch): try: run(f"git show-branch {branch}", check=True) except subprocess.CalledProcessError as e: return False # exit failure means branch does not exist return True
def log(N=10, use_short=False): """ enjoy """ short = '--pretty=format:"%h%x09%an%x09%ad%x09%s"' if use_short else "" return decode_bytes(run(f"git log -{N} {short}").stdout)