 <p>You could look at the <a href="http://docs.python.org/library/trace.html" rel="nofollow noreferrer">trace</a> module in the standard library, which </p> <blockquote> <p>allows you to trace program execution, generate annotated statement coverage listings, print caller/callee relationships and list functions executed during a program run. It can be used in another program or from the command line.</p> </blockquote> <p>You can also log to disk:</p> <pre><code>import sys import trace # create a Trace object, telling it what to ignore, and whether to # do tracing or line-counting or both. tracer = trace.Trace( ignoredirs=[sys.prefix, sys.exec_prefix], trace=0, count=1) # run the new command using the given tracer tracer.run('main()') # make a report, placing output in /tmp r = tracer.results() r.write_results(show_missing=True, coverdir="/tmp") </code></pre>