-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
worker thread expose its tid #30061
Comments
cc @addaleax @nodejs/workers . I think an |
I think the issue description already gives a meaningful reason why this is tricky -- whatever we do in this direction is going to be platform-dependent and maybe a bit hacky. Using I wouldn't be against introducing something like a thread ID field that means something to the OS, but figuring out what this means outside of Linux and what one could do with that ID elsewhere would be a good start. |
Aside, this seems like a problematic concept if/when thread migration is introduced. Right now there's a 1-to-1 correspondence between workers and their OS threads but there doesn't have to be. |
Precisely that. That said it does sound genuinely useful for tooling authors to be able to do this regardless of whether the abstraction is "worker per thread" - I am just not sure if telling people "make a syscall" like in the OP is a bad solution. |
|
V8 does not prohibit that, and in fact provides APIs to allow it. It prohibits using an Isolate from multiple native threads concurrently or using multiple Isolates from one thread concurrently, though. This may never get implemented, but at the same time it’s not unthinkable to run e.g. multiple Workers on a shared native thread.
Fwiw, here’s what Chromium does: I don’t think the return value of that is meaningful outside of the process on non-Linux platforms (and maybe also Windows, I don’t know about that).
I don’t think there’s any reverse engineering involved in what OP is doing – doing a syscall to That being said, if you are actually talking about profiling Worker threads, that’s already possible through the standard profiling measures like |
thanks @addaleax . The only one point I want to clarify is profiling; I meant a wider scope for program analysis, not just CPU profiling. |
@addaleax from what I can tell Chromium calls GetCurrentThreadId here: https://chromium.googlesource.com/chromium/chromium/+/068885c2c5fda617e634bb73a107a0285af470ff/base/threading/platform_thread_win.cc#104 which seems to return a meaningful result on windows:
So it looks like this is doable in windows (and thus cross-platform) if we want to provide it in core - which I am not sure we do. |
@benjamingr If you’re focused on the unique-identifier aspect, To me it really seems more like OP is focused on using the thread id to gather meaningful information about the thread, and that is what I’m having a hard time seeing happening cross-platform. I think the closest we can get is something like the |
@abbshr Any further thoughts on this, given the discussion above? |
@addaleax For me, I really prefer this solution, but it seems not to be an universal approach (not kind to other platform users). So, I think maybe an addon is more flexible and suitable right now, unless the |
In the hope this helps, i.e., something new and useable - fyi - CPython had a discussion for adding OS support to get the "real" tid from it's "worker" concept - even if mono-threaded. This is the "multi-platform" code - in Python/thread_pthread.h
|
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Is your feature request related to a problem? Please describe.
I write program under linux, and I want to collect metrics (like cpu times, ctx switch, memory usage, ...) of the specified worker thread by the tid.
It seems impossible to get the statistics information provided by the os of the given thread by using a
worker.threadId
, and it is only make sense within the process.Maybe we could expose a new property to return the
tid
assigned by os, such asworker.tid
?Then, we could hold the tid to get more stats under
/proc
or do something else meaningful.Describe the solution you'd like
Make a system call (224) under linux is enough.
or
pthread_self()
(but this return a address, need some trick to pick the os level tid)The text was updated successfully, but these errors were encountered: