]>
Witch of Git - ivy/blob - tools/format_trace.py
7 result
= subprocess
.run(
8 ["nm", "-defined-only", "-demangle", program
],
14 for line
in result
.stdout
.split("\n"):
17 addr
, _
, name
= line
.split(' ', 2)
18 if name
.startswith("ivy_builtin$"):
19 name
= name
.split("$", 2)[1]
24 def handle_trace(lines
, syms
={}, only_debug
=False):
27 if int(x
, 16) % 2 == 1:
28 return int(x
, 16) >> 1
39 kind
, *args
= line
.split()
41 objs
[args
[0]] = syms
.get(args
[1], f
"fn@{args[1]}")
43 print("MAKE", objs
[args
[0]])
45 objs
[args
[1]] = obj(args
[0])
47 if int(args
[1], 16) == 0:
48 objs
[args
[0]] = f
"({obj(args[0])})"
50 objs
[args
[0]] = f
"({obj(args[0])} {obj(args[1])})"
52 print("APP", objs
[args
[0]])
57 print("DEBUG", obj(args
[0]))
62 print(kind
, *(obj(x
) for x
in args
))
65 if __name__
== "__main__":
66 parser
= argparse
.ArgumentParser(
67 description
="Make an Ivy runtime trace more readable",
69 parser
.add_argument("program", help="The program that produced the trace")
70 parser
.add_argument("trace", help="A file containing the trace")
72 "-d", "--only-debug", action
="store_true",
73 help="If set, only print the DEBUG outputs",
75 if len(sys
.argv
) == 1:
78 args
= parser
.parse_args()
80 syms
= get_syms(args
.program
)
81 with
open(args
.trace
, "r") as f
:
82 lines
= [line
.strip() for line
in f
if line
.strip()]
83 handle_trace(lines
, syms
, ags
.only_debug
)