]> Witch of Git - ivy/blob - tools/trace.py
[tools] Add tools/run.py to compile and immediately run scripts
[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 def trace(command, only_debug):
19 syms = format_trace.get_syms(command)
20 lines = get_trace(command)
21 format_trace.handle_trace(lines, syms, only_debug)
22
23
24 def main():
25 parser = argparse.ArgumentParser(
26 description="Run an Ivy executable and format its runtime trace.",
27 )
28 parser.add_argument(
29 "command",
30 help="The command to execute.",
31 )
32 parser.add_argument(
33 "-d", "--only-debug", action="store_true",
34 help="If set, only print the DEBUG outputs",
35 )
36 if len(sys.argv) <= 1:
37 parser.print_help()
38 sys.exit(0)
39 args = parser.parse_args()
40 trace(args.command, args.only_debug)
41
42
43 if __name__ == '__main__':
44 main()