I am new in a large complicated codebase. I would like to follow a request as it is being processed. For this I'd like to have a feature that enables printing each function that is being called without having to add trace functionality everywhere in the codebase (see e.g. crate trace).
Ideally I would like exactly this python solution, but in rust (see SO post):
def tracefunc(frame, event, arg, indent=[0]):
if event == "call":
indent[0] += 2
print("-" * indent[0] + "> call function", frame.f_code.co_name)
elif event == "return":
print("<" + "-" * indent[0], "exit function", frame.f_code.co_name)
indent[0] -= 2
return tracefunc
import sys
sys.setprofile(tracefunc)
main() # or whatever kicks off your script
EDIT:
A tool that does this may even be better. See e.g. this solution for C++