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