pyinstrument
pyinstrument copied to clipboard
Feature Request: pstats output
One thing that would be very useful is to be able to produce output from pyinstrument in a Python pstats file. That would allow it to, for example, be passed to gprof2dot
to produce a call-graph tree. It looks like the file format is pretty simple -- some data in a dictionary gets dumped using marshal.dump (see here).
Happy to accept a PR for this - hopefully it should be implementable with a custom renderer. Although pyinstrument doesn't record 'number of calls' (being a statistical profiler) so that field might have to be stubbed out.
I agree, generally it would be useful to add in gprof2dot or similar as a render.
It looks like the file format is pretty simple
While not explicitly documented, the file is a dump of a marshaled dictionary. The keys are (file_name, line_number, func_name)
(where builtin functions are like ('', 0, 'compile')
. The value is (call_time, number_calls, total_time, cumulative_time, callers)
, where callers
is a dict of (key, count)
of places the function is called.