py-spy icon indicating copy to clipboard operation
py-spy copied to clipboard

Option to get native thread ID with best effort

Open ErnestChan opened this issue 2 years ago • 2 comments

When running py-spy with --native sometimes I get failed to get os threadid. See related issue. I'm running this on bare-metal Ubuntu servers.

It would be great to have the option to not error out when py-spy fails to get the thread id. Maybe modify this line so when the option is set we log an exception, or add a fake stack trace that says py-spy failed to get the thread ID

ErnestChan avatar Oct 24 '23 23:10 ErnestChan

With the --native option, we need to be able to get a mapping between pthread_id and the OS thread_id - so that we can join the native stack (which we have the OS thread_id for) with the python stack (which we have the pthread_id for). If we fail to get the os threadid, there isn't enough information to do this -

What version of python and ubuntu are you running? This code should work to get the os threadid on ubuntu (aside from in cases like profiling from the host os into a docker container - which doesn't sound like it applies to you).

benfred avatar Oct 25 '23 00:10 benfred

Thanks for the quick reply! This is on Ubuntu 22.04.1 LTS profiling python3.8. If the code should work on Ubuntu do you have pointers on how to debug why it sometimes fails?

As for joining pthread_id and OS thread_id, for us we're ok with missing some native thread stack traces. We'd rather get some native traces than none, which is why a best effort option with --native would be nice.

ErnestChan avatar Oct 25 '23 17:10 ErnestChan