Last active
August 29, 2015 13:56
-
-
Save prasoon2211/9285630 to your computer and use it in GitHub Desktop.
pytrace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, linecache | |
def tracefunc(frame, event, arg, indent=[0]): | |
if event == "call" or event == "return": | |
lineno = frame.f_lineno | |
filename = frame.f_globals["__file__"] | |
if filename == "<stdin>": | |
filename = "traceit.py" | |
if (filename.endswith(".pyc") or | |
filename.endswith(".pyo")): | |
filename = filename[:-1] | |
if event == "call": | |
indent[0] += 2 | |
print "-" * indent[0] + "> call function", frame.f_code.co_name, filename, lineno | |
elif event == "return": | |
print "<" + "-" * indent[0], "exit function", frame.f_code.co_name, filename, lineno | |
indent[0] -= 2 | |
return tracefunc | |
sys.settrace(tracefunc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment