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