Consider hooking pthread_create (or another technique) so that we can profile threads launched by libraries
Categories
(Core :: Gecko Profiler, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox54 | --- | affected |
People
(Reporter: mstange, Unassigned)
References
(Depends on 1 open bug, Blocks 2 open bugs)
Details
Reporter | ||
Comment 1•7 years ago
|
||
Comment 2•6 years ago
|
||
Comment 3•6 years ago
|
||
For what it's worth:
- unnamed threads are now visible in about:processes;
- we can easily test that all threads are OS-level named in the unit tests for about:processes.
Unfortunately, as of today, there are still a few unnamed threads. I'm tracking them as blockers of bug 1630898.
Thank you David.
Obviously about:processes must have a way to get the list of threads (ids and names), I hope the profiler could use the same technique or even the same code, in which case it should be possible to record them.
I think this bug here should depend on bug 1630898 instead of blocking it (i.e., the profiler depends on threads being named before it can profile them) -- But please let me know if you disagree.
Oh, while it's great if we can get a list of threads, I'm guessing it may not be cheap to do that, so the profiler may not be able to do it at every sample point!
If my assumption is sadly correct we will still want to try and catch thread creations (by hooking pthread_create
or other means).
But in the meantime, it could still be valuable to have an option to regularly (1 Hz?) look at the list of threads, and profile new ones at they appear.
And on the flip side, we'll want to catch thread terminations; but that should (hopefully) be trivial as they'll just not be there anymore when we try to sample them. (Another assumption: Thread ids won't be reused in-between two samplings.)
Updated•4 years ago
|
Comment 7•4 years ago
|
||
Yoric (or whomever): where are threads in about:processes? Also, we're talking raw threads/pthreads, not nsThreads which we can already enumerate.
Comment 8•4 years ago
|
||
(In reply to Randell Jesup [:jesup] (needinfo me) from comment #7)
Yoric (or whomever): where are threads in about:processes?
They are shown if you set toolkit.aboutProcesses.showThreads
to true in about:config.
They are hidden by default. You need pref toolkit.aboutProcesses.showThreads
= true
to show them.
I've just filed bug 1742522, which will discover unregistered threads the same way about:processes does.
It should help with profiling library-controlled threads, but not as soon as threads are started, so I will keep this bug here open in case we can actually hook pthread_create
(or equivalent/better, and equivalent on other platforms).
Note that the thread discovery in about:processes is pretty slow.
(In reply to David Teller [:Yoric] - still alive but not very active from comment #11)
Note that the thread discovery in about:processes is pretty slow.
True, it's not be perfect but hopefully it will give some useful data on all platforms, until someone can get this bug here done!
Reporter | ||
Comment 13•6 months ago
|
||
The thread discovery implemented in bug 1742522 takes 4ms per check on my Samsung Galaxy S21 so this is not something we can realistically do on a per-sample basis.
(In reply to Mike Hommey [:glandium] from comment #2)
On linux, we can export a pthread_create wrapper from our executable, but
that won't catch all thread creations. Anything using the system call
directly (and there may be) won't be caught. I guess that's still better
than nothing?
It should be quite a bit better than nothing - do you know if this would catch Rust threads? Also, would this work on Android?
Also, we may want to hook pthread_setname_np
as well, so that if we have a thread name filter, we can start sampling a thread immediately when it gets renamed to a name that matches the filter.
Reporter | ||
Comment 14•6 months ago
|
||
Oh, also, do we have other executable-exported wrapper functions that I can look at for inspiration?
Comment 15•6 months ago
|
||
We're actually hooking pthread_create already, now, since bug 1678152. Bug 1752703 moved it out of the crash reporter and into mozglue and works to some extent on Android (it doesn't catch system libraries calling pthread_create).
It should be catching Rust threads, but it's android/linux only at the moment.
Description
•