In order to debug how a complicated library executes a function call, e.g. pd.Series(np.NaN)|pd.Series("True")
I would like to generate a list of all states of the stack during the execution of that function. So for every line of Python code executed (even inside functions and functions called by functions), there should be one entry in the list of stack traces).
This is a bit like a profile generated by a sampling profiler. But in contrast, I don't want a stack trace for every millisecond, but for every line of Python code executed.
I know I can manually call this function using pdb
, and repeatedly enter step
to step into any function calls and where
to print stack traces of the current state - but I want to do this automatically.
How can I automate this stack trace collection? Is there a package for this? If not, how do I automate that with, for example, pdb
or another tool that does the job? Is there an accepted word for such a list of stack traces?
That stack list could be used for at least two purposes: a) quickly finding all code that is reached, reducing the scope for finding relevant lines, b) creating a "flamegraph" of execution.
Somewhat related questions:
What cool hacks can be done using sys.settrace?
sandboxing/running python code line by line