Skip to content

Add function trace utils #2143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions scripts/func-trace-utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
default: bin.trace bin.trace.interleaved

vmlinux.dump: boards/default/linux/vmlinux
riscv64-unknown-elf-objdump -D $< > $@

busybox.dump: wlutil/busybox/busybox_unstripped
riscv64-unknown-linux-gnu-objdump -D -S $< > $@

# userspace binary
USERSPACE_BIN ?=
bin.dump: $(USERSPACE_BIN)
riscv64-unknown-elf-objdump -D -S $< > $@

# logfile from spike or CY RTL sim.
IN_LOG ?=
bin.trace: vmlinux.dump busybox.dump bin.dump $(IN_LOG)
./create-func-trace.py $^
mv $(IN_LOG).functrace $@

bin.trace.interleaved: vmlinux.dump busybox.dump bin.dump $(IN_LOG)
./create-func-trace-interleaved.py $^
mv $(IN_LOG).functrace $@

.PHONY: dumps
dumps: busybox.dump bin.dump vmlinux.dump

.PHONY: clean
clean:
rm -rf *.trace*
58 changes: 58 additions & 0 deletions scripts/func-trace-utils/create-func-trace-int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3

import sys
import re

back_args = sys.argv[1:]
files_to_check = back_args[:-1]
outfile = back_args[-1]

print(f"Checking {files_to_check}")

func_names = {}

for dumpfile in files_to_check:
with open(dumpfile, 'r') as ld:
for l in ld:
match = re.match(r"^([a-fA-F0-9]+) <(.*)>:", l)
if match:
pc, name = match.groups()
if pc in func_names:
func_names[pc] = func_names[pc] + " or " + name
else:
func_names[pc] = name

print(f"Got {len(func_names)} functions from files")
print(f"Creating function trace from {outfile}")

with open(outfile, 'r') as of:
with open(outfile + ".functrace", 'w') as wf:
lines = of.readlines()
tlc = len(lines)
lno = 0
for l in lines:
match = re.search(r"\[1\] pc=\[([a-fA-F0-9]+)\]", l)
if match:
pc = match.groups()[0]
if pc in func_names:
wf.write(f"{pc}: {func_names[pc]}\n")
#wf.write(f"{(100*lno/tlc):.1f}: {pc}: {func_names[pc]}\n")
else:
match = re.search(r": 0x([a-fA-F0-9]+) ", l)
if match:
pc = match.groups()[0]
if pc in func_names:
wf.write(f"{pc}: {func_names[pc]}\n")
#wf.write(f"{(100*lno/tlc):.1f}: {pc}: {func_names[pc]}\n")
# match = re.search(r": exception.*,", l)
# if match:
# wf.write(l)

# match = re.search(r"\[0\] pc=\[0000000000193f80\]", l)
# if match:
# wf.write(l)

wf.write(l)
lno = lno + 1

print(f"Done: {outfile}.functrace")
57 changes: 57 additions & 0 deletions scripts/func-trace-utils/create-func-trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

import sys
import re

back_args = sys.argv[1:]
files_to_check = back_args[:-1]
outfile = back_args[-1]

print(f"Checking {files_to_check}")

func_names = {}

for dumpfile in files_to_check:
with open(dumpfile, 'r') as ld:
for l in ld:
match = re.match(r"^([a-fA-F0-9]+) <(.*)>:", l)
if match:
pc, name = match.groups()
if pc in func_names:
func_names[pc] = func_names[pc] + " or " + name
else:
func_names[pc] = name

print(f"Got {len(func_names)} functions from files")
print(f"Creating function trace from {outfile}")

with open(outfile, 'r') as of:
with open(outfile + ".functrace", 'w') as wf:
lines = of.readlines()
tlc = len(lines)
lno = 0
for l in lines:
match = re.search(r"\[1\] pc=\[([a-fA-F0-9]+)\]", l)
if match:
pc = match.groups()[0]
if pc in func_names:
wf.write(f"{pc}: {func_names[pc]}\n")
#wf.write(f"{(100*lno/tlc):.1f}: {pc}: {func_names[pc]}\n")
else:
match = re.search(r": 0x([a-fA-F0-9]+) ", l)
if match:
pc = match.groups()[0]
if pc in func_names:
wf.write(f"{pc}: {func_names[pc]}\n")
#wf.write(f"{(100*lno/tlc):.1f}: {pc}: {func_names[pc]}\n")
#wf.write(l)
match = re.search(r": exception.*,", l)
if match:
wf.write(l)

match = re.search(r"\[0\] pc=\[0000000000193f80\]", l)
if match:
wf.write(l)
lno = lno + 1

print(f"Done: {outfile}.functrace")
Loading