benfred / py-spy

Sampling profiler for Python programs
MIT License
12.53k stars 414 forks source link

Prefix the thread names with the pid with --subprocess #439

Closed ogrisel closed 3 years ago

ogrisel commented 3 years ago

At the moment, when profiling a multiprocess Python program many threads are named MainThread when --subprocess is passed to py-spy record. This makes it hard to browse to navigate the speedscope report:

image

One possible solution would be to prefix the thread name with the pid of the process. This would make it easier to understand how threads are grouped.

ogrisel commented 3 years ago

Related, if speedscope ever supports multitracks rendering, one would expect one track per process with subtracks per threads, or althernatively one track per threads but tracks belonging to the same process grouped together, with the parent process at the top.

https://github.com/jlfwong/speedscope/issues/117#issuecomment-901167139

benfred commented 3 years ago

Thanks for pointing this out! I've fixed in #440 - it will now display both the process id and thread id in the profile names.

I have also caught another issue with speedscope format when profiling with subprocesses when fixing this: the profiles were being keyed by the pthread id - which isn't unique across processes. This caused profiles from different processes to be merged together for me, and made the 'time order' view confusing.

ogrisel commented 3 years ago

Nice, I also suspected a bug related in the handling of multiprocess/multithreaded traces but wasn't sure. Thanks for confirming and for the fix!

benfred commented 3 years ago

Fix is in v0.3.9