I'm using python's trace module to trace some code. When I trace code this way, I can get one of the following two results:
Call:
tracer = trace.Trace(count=False, trace=True, ignoredirs=[sys.prefix, sys.exec_prefix])
r = tracer.run('run()')
tracer.results().write_results(show_missing=True)
Result:
<filename>(<line number>): <line of code>
Call [citation]:
tracer = trace.Trace(count=False, trace=True, ignoredirs=[sys.prefix, sys.exec_prefix], countfuncs=True)
r = tracer.run('run()')
tracer.results().write_results(show_missing=True)
Result:
filename:<filepath>, modulename:<module name>, funcname: <function name>
What I really need is a trace that gives me this:
<filepath> <line number>
It would seem that I could use the above information and interleave them to get what I need, but such an attempt would fail in the following use case:
sys.pathcontains directoryAand directoryB.- There are two files
A/foo.pyandB/foo.py - Both
A/foo.pyandB/foo.pycontain the functionbar, defined on lines 100 - 120 - There are some minor differences between
A/foo.pyandB/foo.py
In this scenario, using such interleaving to correctly identifying which bar is called is impossible (please correct me if I'm wrong) without statically analyzing the code within each bar, which itself is very difficult for non-trivial functions.
So, how can I get the correct trace output that I need?