Provide a warning when time is likely spent in another thread
pyinstrument only records one thread at a time. However, due to the GIL, the performance of one thread could be affected by a different active thread in the same program.
Python can now give CPU time per-thread:
- https://docs.python.org/3/library/time.html#time.thread_time
- https://docs.python.org/3/library/time.html#time.clock_gettime
This could be compared with the program CPU time - if the current thread is less than 80% of the program's CPU time, it's likely that that other thread was slowing the profiled one down - this should be communicated in pyinstrument's output.
It would be even better if we could track the time spent inside the GIL (and even subtract it), but I'm not sure how to do that!
Was here looking for something else, but came across this and FWIW a project I did a while ago might help? gilknocker