def main(args: argparse.Namespace) -> None:
    mz_root = os.environ['MZ_ROOT']
    os.chdir(mz_root)
    worker_counts = enumerate_cpu_counts()
    if args.no_benchmark_this_checkout:
        git_references = args.git_references
    else:
        git_references = [None, *args.git_references]
    if args.verbose:
        build_tags = [None, *[mzbuild_tag(ref) for ref in args.git_references]]
        print(f'DEBUG: num_iterations={args.num_measurements}')
        print(f'DEBUG: worker_counts={worker_counts}')
        print(f'DEBUG: mzbuild_tags={build_tags}')
    if (args.size == 'benchmark-ci'):
        worker_counts = [1]
    setup_benchmark = [mzcompose_location(mz_root), '--mz-find', args.composition, 'run', f'setup-benchmark-{args.size}']
    run_benchmark = [mzcompose_location(mz_root), '--mz-find', args.composition, 'run', f'run-benchmark-{args.size}']
    field_names = ['git_revision', 'num_workers', 'iteration', 'seconds_taken', 'rows_per_second', 'grafana_url']
    results_writer = csv.DictWriter(sys.stdout, field_names)
    results_writer.writeheader()
    try:
        subprocess.check_output(setup_benchmark, stderr=subprocess.STDOUT)
    except (subprocess.CalledProcessError,) as e:
        print(f'''Setup benchmark failed! Output from failed command:
{e.output.decode()}''')
        raise
    if args.web:
        try:
            web_command = [mzcompose_location(mz_root), '--mz-find', args.composition, 'web', f'perf-dash-web']
            output = subprocess.check_output(web_command, stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError,) as e:
            print(f'''Failed to open browser to perf-dash:
{e.output.decode()}''')
            raise
    iterations = range(0, args.num_measurements)
    for (iteration, worker_count, git_ref) in itertools.product(iterations, worker_counts, git_references):
        child_env = os.environ.copy()
        child_env['MZ_ROOT'] = mz_root
        child_env['MZ_WORKERS'] = str(worker_count)
        child_env['MZBENCH_ID'] = args.benchmark_id
        child_env['MZBUILD_WAIT_FOR_IMAGE'] = 'true'
        if git_ref:
            child_env['MZBENCH_GIT_REF'] = git_ref
            child_env['MZBUILD_MATERIALIZED_TAG'] = mzbuild_tag(git_ref)
        try:
            output = subprocess.check_output(run_benchmark, env=child_env, stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError,) as e:
            print(f'''Setup benchmark failed! Output from failed command:
{e.output.decode()}''')
            raise
        for line in output.decode().splitlines():
            if line.startswith('SUCCESS!'):
                for token in line.split(' '):
                    if token.startswith('seconds_taken='):
                        seconds_taken = token[len('seconds_taken='):]
                    elif token.startswith('rows_per_sec='):
                        rows_per_second = token[len('rows_per_sec='):]
            elif line.startswith('Grafana URL: '):
                grafana_url = line[len('Grafana URL: '):]
        results_writer.writerow({'git_revision': (git_ref if git_ref else 'None'), 'num_workers': worker_count, 'iteration': iteration, 'seconds_taken': seconds_taken, 'rows_per_second': rows_per_second, 'grafana_url': grafana_url})
def main(args: argparse.Namespace) -> None:
    mz_root = os.environ['MZ_ROOT']
    os.chdir(mz_root)
    worker_counts = enumerate_cpu_counts()
    if args.no_benchmark_this_checkout:
        git_references = args.git_references
    else:
        git_references = [None, *args.git_references]
    if args.verbose:
        build_tags = [None, *[mzbuild_tag(ref) for ref in args.git_references]]
        print(f'DEBUG: num_iterations={args.num_measurements}')
        print(f'DEBUG: worker_counts={worker_counts}')
        print(f'DEBUG: mzbuild_tags={build_tags}')
    if (args.size == 'benchmark-ci'):
        worker_counts = [1]
    setup_benchmark = [mzcompose_location(mz_root), '--mz-find', args.composition, 'run', f'setup-benchmark-{args.size}']
    run_benchmark = [mzcompose_location(mz_root), '--mz-find', args.composition, 'run', f'run-benchmark-{args.size}']
    field_names = ['git_revision', 'num_workers', 'iteration', 'seconds_taken', 'rows_per_second', 'grafana_url']
    results_writer = csv.DictWriter(sys.stdout, field_names)
    results_writer.writeheader()
    try:
        subprocess.check_output(setup_benchmark, stderr=subprocess.STDOUT)
    except (subprocess.CalledProcessError,) as e:
        print(f'Setup benchmark failed! Output from failed command:
{e.output.decode()}')
        raise
    if args.web:
        try:
            web_command = [mzcompose_location(mz_root), '--mz-find', args.composition, 'web', f'perf-dash-web']
            output = subprocess.check_output(web_command, stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError,) as e:
            print(f'Failed to open browser to perf-dash:
{e.output.decode()}')
            raise
    iterations = range(0, args.num_measurements)
    for (iteration, worker_count, git_ref) in itertools.product(iterations, worker_counts, git_references):
        child_env = os.environ.copy()
        child_env['MZ_ROOT'] = mz_root
        child_env['MZ_WORKERS'] = str(worker_count)
        child_env['MZBENCH_ID'] = args.benchmark_id
        child_env['MZBUILD_WAIT_FOR_IMAGE'] = 'true'
        if git_ref:
            child_env['MZBENCH_GIT_REF'] = git_ref
            child_env['MZBUILD_MATERIALIZED_TAG'] = mzbuild_tag(git_ref)
        try:
            output = subprocess.check_output(run_benchmark, env=child_env, stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError,) as e:
            print(f'Setup benchmark failed! Output from failed command:
{e.output.decode()}')
            raise
        for line in output.decode().splitlines():
            if line.startswith('SUCCESS!'):
                for token in line.split(' '):
                    if token.startswith('seconds_taken='):
                        seconds_taken = token[len('seconds_taken='):]
                    elif token.startswith('rows_per_sec='):
                        rows_per_second = token[len('rows_per_sec='):]
            elif line.startswith('Grafana URL: '):
                grafana_url = line[len('Grafana URL: '):]
        results_writer.writerow({'git_revision': (git_ref if git_ref else 'None'), 'num_workers': worker_count, 'iteration': iteration, 'seconds_taken': seconds_taken, 'rows_per_second': rows_per_second, 'grafana_url': grafana_url})