benfred / py-spy

Sampling profiler for Python programs
MIT License
12.14k stars 400 forks source link

[speedscope] Save timestamp of first sample in a new thread #589

Open mabrowning opened 1 year ago

mabrowning commented 1 year ago

Even though py-spy is a sampling profiler and the timelines should not be trusted, the speedscope format allows for multiple parallel timelines. At a sufficiently course sampling granularity (assuming no skipped steps), these timelines can be usefully correlated if we had the relative offset between them.

If we saved the current timestamp when taking the first sample of a new process/thread around here: https://github.com/benfred/py-spy/blob/master/src/speedscope.rs#L220-L227

And added that offset to start_value and end_value here: https://github.com/benfred/py-spy/blob/master/src/speedscope.rs#L144-L145

That would allow correlating timelines between threads/processes.