]>
Witch of Git - ivy/blob - tools/format_trace.py
8 result
= subprocess
.run(
9 ["nm", "-defined-only", "-demangle", program
],
15 for line
in result
.stdout
.split("\n"):
18 addr
, _
, name
= line
.split(" ", 2)
19 if name
.startswith("ivy_builtin$"):
20 name
= name
.split("$", 2)[1]
25 def handle_trace(lines
, syms
={}, only_debug
=False):
29 if int(x
, 16) % 2 == 1:
30 return int(x
, 16) >> 1
41 kind
, *args
= line
.split()
43 objs
[args
[0]] = syms
.get(args
[1], f
"fn@{args[1]}")
45 print("MAKE", objs
[args
[0]])
47 objs
[args
[1]] = obj(args
[0])
49 if int(args
[1], 16) == 0:
50 objs
[args
[0]] = f
"({obj(args[0])})"
52 objs
[args
[0]] = f
"({obj(args[0])} {obj(args[1])})"
54 print("APP", objs
[args
[0]])
59 print("DEBUG", obj(args
[0]))
64 print(kind
, *(obj(x
) for x
in args
))
67 if __name__
== "__main__":
68 parser
= argparse
.ArgumentParser(
69 description
="Make an Ivy runtime trace more readable",
71 parser
.add_argument("program", help="The program that produced the trace")
72 parser
.add_argument("trace", help="A file containing the trace")
77 help="If set, only print the DEBUG outputs",
79 if len(sys
.argv
) == 1:
82 args
= parser
.parse_args()
84 syms
= get_syms(args
.program
)
85 with
open(args
.trace
, "r") as f
:
86 lines
= [line
.strip() for line
in f
if line
.strip()]
87 handle_trace(lines
, syms
, ags
.only_debug
)