Skip to content
Snippets Groups Projects
launch.py 2.14 KiB
Newer Older
#!/usr/bin/env python

import argparse
import os
import subprocess
import sys


def shell_exec(command, env=None):
    # Simulate bash script printing the commands it runs
    print("+ %s" % command)
    process = subprocess.Popen(command, shell=False, env=env)
    retcode = process.wait()
    if retcode:
        raise subprocess.CalledProcessError(retcode, command)


def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "target", nargs="?", help="the changesets to run benchmarks against"
    )
Boris Feld's avatar
Boris Feld committed
    parser.add_argument(
Boris Feld's avatar
Boris Feld committed
        "--force",
        help="force running all selected benchmarks for the selected changesets",
        action="store_const",
        const=True,
        default=False,
    )
Boris Feld's avatar
Boris Feld committed
    parser.add_argument(
        "-q",
        "--quiet",
        help="make asv run quieter",
        action="store_const",
        const=True,
        default=False,
    )
    args, unknown = parser.parse_known_args(args)

    # Process target
    if args.target is None:
        target = "1.9:: and tagged()"
    else:
        target = args.target

    # Prepare all files
    shell_exec(["./lib/before-check.sh"])
    # Force ASV to spawn a separate process per test, so it kills childrens
    # when the test timeout. In the fork_server mode (the default), it kill
    # the process group at the very end only so some perf* commands might
    # still be running while other tests started
    run_command.extend(["--launch-method", "spawn"])

    # Run ASV on specific cores for stability
    # Examples, `2,3`, `0-4`, `0`
    cpu_affinity = os.environ.get("ASV_CPU_AFFINITY")
    if cpu_affinity:
        run_command.extend(["--cpu-affinity", cpu_affinity])

Pierre-Yves David's avatar
Pierre-Yves David committed
    if not args.quiet:
Boris Feld's avatar
Boris Feld committed
        asv_flags = ["--verbose", "--show-stderr"]
    else:
        asv_flags = []
Boris Feld's avatar
Boris Feld committed

    if not args.force:
        asv_flags.append("--skip-existing-successful")

    run_command.extend(asv_flags)

    run_command.append(target)

    run_command.extend(unknown)

    env = os.environ.copy()
    env["HGRCPATH"] = ""

    shell_exec(run_command, env=env)

if __name__ == "__main__":
    main(sys.argv[1:])