main.py 1.24 KB
Newer Older
1
2
3
4
5
#!/usr/bin/env python3

import argparse
import sys

one's avatar
one committed
6
7
from .runner import run_with_input
from .utils import get_mpi_rank
8
9


one's avatar
one committed
10
def create_parser():
one's avatar
one committed
11
12
13
14
15
16
17
    parser = argparse.ArgumentParser(
        description="RCCL Log Parser Wrapper\n\n"
        "Usage modes:\n"
        "  1. Pipe input:    cat log.txt | xcl-lens\n"
        "  2. Read files:    xcl-lens log1.txt log2.txt\n"
        "  3. Wrap command:  xcl-lens ./all_reduce_perf",
        formatter_class=argparse.RawDescriptionHelpFormatter,
18
    )
one's avatar
one committed
19
    parser.add_argument("--summary", action="store_true", help="Print summary report only")
one's avatar
one committed
20
    parser.add_argument("-v", "--verbose", action="store_true", help="Print verbose reports")
21
    parser.add_argument(
one's avatar
one committed
22
        "command", nargs=argparse.REMAINDER, help="Executable to run, or log files to read"
23
    )
one's avatar
one committed
24
    return parser
25

one's avatar
one committed
26

one's avatar
one committed
27
28
def main():
    rank = get_mpi_rank()
29

one's avatar
one committed
30
31
    parser = create_parser()
    args = parser.parse_args()
32
33

    try:
one's avatar
one committed
34
35
36
        exit_code = run_with_input(args, rank)
        if exit_code is not None:
            sys.exit(exit_code)
37
38
    except KeyboardInterrupt:
        sys.exit(130)
one's avatar
one committed
39
40
41
42
43

    # If we got here, no command was provided and stdin is a tty
    if rank == 0:
        parser.print_help()
    sys.exit(1)
44
45
46
47


if __name__ == "__main__":
    main()