1

I am trying to debug some code written long ago, and due to the scarce documentation would like a way to trace the functions being called from execution to final output, possibly with which parameters they were called with. A sort of sys.traceback but in the case of no errors. It would also be nice to get the report as a HTML or another exportable format. Something along the lines of:

main()->class->run()->getData()->saveData()

I already looked at Can I trace all the functions/methods executing in a python script? but it doesn't answer the question as functions are not reportd.

1
  • 1
    trace with the --trace option does report function calls Commented Dec 14, 2015 at 12:01

2 Answers 2

1

Try using pycallgraph or another "call graph" visualization tool.

Sign up to request clarification or add additional context in comments.

1 Comment

I like this answer a lot. While it may not provide a lot of added value in a (simple) script, for larger projects, such a visualization tool can be invaluable. Exceptionally useful in development!
0

probably you need settrace function

CODE

import sys

def traceit(frame, event, arg):
    if event == "call":
        co = frame.f_code
        func_name = co.co_name
        print("event:", event,"of function",func_name)
    return traceit

def main():
    print ("In main")
    for i in range(5):
        print (i, i*3)
    print ("Done.")


sys.settrace(traceit)
main()

OUT PUT

event: call of function main
In main
0 0
1 3
2 6
3 9
4 12
Done.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.