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

Include thread name in Memray live tracking view #561

Open
1 task done
gibsondan opened this issue Mar 7, 2024 · 4 comments · May be fixed by #562
Open
1 task done

Include thread name in Memray live tracking view #561

gibsondan opened this issue Mar 7, 2024 · 4 comments · May be fixed by #562
Assignees
Labels
enhancement New feature or request

Comments

@gibsondan
Copy link

gibsondan commented Mar 7, 2024

Is there an existing proposal for this?

  • I have searched the existing proposals

Is your feature request related to a problem?

memray attach is incredibly useful - but for multi-threaded applications, once you've determined that a particular thread is the source of a memory issue, figuring out which thread in the application corresponds to that "Thread X of Y" number displayed in the live view is challenging.

Describe the solution you'd like

Each thread has a string name - it would be very useful if the thread name was included alongside the "Thread X of Y" output in the live view.

Alternatives you considered

We can use py-spy to map thread numbers to thread names (I think?) but it would be much more convenient to have that information already available in memray

Thanks for building an amazing tool!

@gibsondan gibsondan added the enhancement New feature or request label Mar 7, 2024
@pablogsal
Copy link
Member

Thanks for opening an issue @gibsondan!

We do have the thread name already collected so it should be fairly simple to pass it through the layers and display it in the TUI

@pablogsal pablogsal linked a pull request Mar 7, 2024 that will close this issue
@godlygeek
Copy link
Contributor

Each thread has a string name

Can you clarify which string name you're referring to, @gibsondan ?

@gibsondan
Copy link
Author

@godlygeek when you create a thread in python, you can supply a name: https://docs.python.org/3/library/threading.html#thread-objects

(Or a threadpoolexecutor can specify a prefix which is applied to all threads created in that pool)

I don't know offhand how that is translated into the operating system internals but I suspect it's through something like this: https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html

py-spy, for example, includes these names in its output via commands like py-spy dump or the flamegraph produced by py-spy record:

Thread 41 (idle): "schedule_daemon_worker_7"

@godlygeek
Copy link
Contributor

We do have access to the name set through pthread_setname_np, but we don't have access to the name set using threading.Thread.name, and setting the name on a Python Thread object doesn't automatically cause pthread_setname_np to be called with the same name (or even a leading prefix of it).

That said, it would be interesting to try to collect the name attribute set on a threading.Thread... I wonder if we're able to...

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

Successfully merging a pull request may close this issue.

3 participants