aboutsummaryrefslogtreecommitdiff
path: root/benchstrace/cli.py
blob: caa4c1922513af3bdf5994454fc6f1ae64160f0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from argparse import ArgumentParser
from .benchmark import Benchmark
import sys


def prof_mode(args):
    result = Benchmark(args.COMMAND, passes=args.passes, setup=args.setup, teardown=args.teardown)

    print(f"Records: {result.count}")
    if args.output_file:
        result.save(args.output_file, clobber=args.clobber)
    return 0


def diff_mode(args):
    left = Benchmark()
    left.load(args.left)
    right = Benchmark()
    right.load(args.right)
    left.diff(right)

    print("\nSUMMARY\n")
    left.diff_average(right)
    left.diff_total(right)
    return 0


def main():
    parser = ArgumentParser()
    subparsers = parser.add_subparsers()

    parser_prof = subparsers.add_parser("prof")
    parser_prof.add_argument("-o", "--output_file", type=str)
    parser_prof.add_argument("-c", "--clobber", action='store_true')
    parser_prof.add_argument("-p", "--passes", type=int, default=1)
    parser_prof.add_argument("-s", "--setup", type=str)
    parser_prof.add_argument("-t", "--teardown", type=str)
    parser_prof.add_argument("COMMAND")
    parser_prof.set_defaults(func=prof_mode)

    parser_diff = subparsers.add_parser("diff")
    parser_diff.add_argument("left")
    parser_diff.add_argument("right")
    parser_diff.set_defaults(func=diff_mode)

    args = parser.parse_args()
    if len(sys.argv) < 2:
        parser.print_help()
        exit(0)

    args.func(args)

if __name__ == "__main__":
    sys.exit(main())