]> Witch of Git - ivy/blob - tools/trace.py
[Parser] Support code with trailing comments
[ivy] / tools / trace.py
1 #!/usr/bin/env python3
2 import argparse
3 import format_trace
4 import subprocess
5 import sys
6
7
8 def get_trace(command):
9 result = subprocess.run(
10 ["lldb", "-b", "-o", "run", command],
11 env={"IVY_RT_TRACE": "1"},
12 capture_output=True,
13 encoding="utf8",
14 )
15 lines = result.stdout.split("\n")
16 return lines[3:-4]
17
18
19 def trace(command, only_debug):
20 syms = format_trace.get_syms(command)
21 lines = get_trace(command)
22 format_trace.handle_trace(lines, syms, only_debug)
23
24
25 def main():
26 parser = argparse.ArgumentParser(
27 description="Run an Ivy executable and format its runtime trace.",
28 )
29 parser.add_argument(
30 "command",
31 help="The command to execute.",
32 )
33 parser.add_argument(
34 "-d", "--only-debug", action="store_true",
35 help="If set, only print the DEBUG outputs",
36 )
37 if len(sys.argv) <= 1:
38 parser.print_help()
39 sys.exit(0)
40 args = parser.parse_args()
41 trace(args.command, args.only_debug)
42
43
44 if __name__ == '__main__':
45 main()