Skip to content

Instantly share code, notes, and snippets.

@Starou
Created February 2, 2022 17:40
Show Gist options
  • Save Starou/065a5c53c612ed7099ec07f3504c42b5 to your computer and use it in GitHub Desktop.
Save Starou/065a5c53c612ed7099ec07f3504c42b5 to your computer and use it in GitHub Desktop.
Trace function calls in a Python program but ignore standard and site-packages lib calls.
import sys
import trace
tracer = trace.Trace(
ignoredirs=[
'/usr/local/lib/python3.6', # adapt to your environment.
'/path/to/lib/python3.6/site-packages',
],
trace=1,
count=0,
outfile=sys.stdout
)
# Use that instead of my_function(arg_1, arg_2)
tracer.runfunc(my_function, arg_1, arg_2)
def my_function(foo, bar):
# Do stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment