Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show thread names in --dump #47

Closed
mgedmin opened this issue Sep 26, 2018 · 3 comments
Closed

Show thread names in --dump #47

mgedmin opened this issue Sep 26, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@mgedmin
Copy link

mgedmin commented Sep 26, 2018

Python threads have names:

>>> import threading
>>> threading.current_thread().name
'MainThread'

It would be very nice if py-spy --dump could print those names.

@benfred benfred added the enhancement New feature or request label Sep 27, 2018
@benfred
Copy link
Owner

benfred commented Sep 27, 2018

I agree that this would be nice - but unfortunately getting this would be slightly involved, and I doubt I'll get to it anytime soon =(.

From what I can tell, the names live on the Thread object in threading.py. To read these from another process we'd have to implement the equivalent code in rust:

for threadid, thread in sys.modules['threading']._active.items():
    print(threadid, thread._name))

while it doesn't look all that bad, it does mean we'd have to add logic to read python dict objects from another process in rust (for getting the threading module from the interpreter modules, getting the _active variable from the threading module globals dict, getting the items from the _active and finally getting the _name member from the Thread class __dict__).

It's not hard exactly, but would be a little time consuming to implement =(

benfred added a commit that referenced this issue Oct 6, 2019
This adds the ability to show the local variables for each frame when showing
the stack trace with the dump command. Currently we only support str/float/int
/bool/nonetype/list/tuple/dict objects - everything else will just show the
type and address.  (#77).
Dictionary processing also currently only works for python 3.6+, everything else
will show a 'dict' object instead.

This also adds the ability to show the thead names for each thread during dump.
Since this relies on a bunch of dictionary lookups, this also only works for
python 3.6+ (#47)
@benfred
Copy link
Owner

benfred commented Oct 6, 2019

First draft of this is in #176. I added the ability to show the local variables in that PR, and once that was done getting the thread names was pretty easy.

Note this is limited to python 3.6+ right now - older versions of python will still just show the threadid without the namee.

benfred added a commit that referenced this issue Oct 7, 2019
This adds the ability to show the local variables for each frame when showing
the stack trace with the dump command. Currently we only support str/float/int
/bool/nonetype/list/tuple/dict objects - everything else will just show the
type and address.  (#77).
Dictionary processing also currently only works for python 3.6+, everything else
will show a 'dict' object instead.

This also adds the ability to show the thead names for each thread during dump.
Since this relies on a bunch of dictionary lookups, this also only works for
python 3.6+ (#47)
benfred added a commit that referenced this issue Oct 7, 2019
This adds the ability to show the local variables for each frame when showing
the stack trace with the dump command. Currently we only support str/float/int
/bool/nonetype/list/tuple/dict objects - everything else will just show the
type and address.  (#77).
Dictionary processing also currently only works for python 3.6+, everything else
will show a 'dict' object instead.

This also adds the ability to show the thead names for each thread during dump.
Since this relies on a bunch of dictionary lookups, this also only works for
python 3.6+ (#47)
@benfred benfred closed this as completed Oct 7, 2019
@benfred
Copy link
Owner

benfred commented Oct 8, 2019

change is in v0.2.2 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants