pyinstrument icon indicating copy to clipboard operation
pyinstrument copied to clipboard

Feature Request: pstats output

Open paulromano opened this issue 5 years ago • 1 comments

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).

paulromano avatar Apr 25 '19 12:04 paulromano

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.

joerick avatar Dec 22 '19 19:12 joerick

I agree, generally it would be useful to add in gprof2dot or similar as a render.

mlucool avatar Jan 19 '23 18:01 mlucool

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.

mattip avatar Apr 07 '23 09:04 mattip