benfred / py-spy

Sampling profiler for Python programs
MIT License
12.16k stars 401 forks source link

speedgraph startValue is always 0 #544

Open dvarrazzo opened 1 year ago

dvarrazzo commented 1 year ago

Hello,

I am trying to debug a concurrency problem in psycopg 3, namely the fact that thread don't seem to run in parallel as much as in psycopg 2. In py-spy flamegraphs of multithread runs I can see long spells of time spent trying to acquire the GIL after sections in which it was released.

image

What I need is to answer the question: "when thread t is locked on GIL acquisition, which thread has the control, and what is it doing?"

I have tried to use the speedgraph to answer this question. Unfortunately it seems that the startValue for each Profile is always 0:

https://github.com/benfred/py-spy/blob/master/src/speedscope.rs#L144

As a consequence, two threads' profiles cannot be aligned precisely and the question of what a thread is doing cannot be answered consistently.

Would it be possible to set startValue either to the absolute start time of the thread, or to a relative time starting from the first thread start, so that the threads profiles can be aligned?