Open Bug 1341811 Opened 3 years ago Updated 1 year ago

Consider hooking pthread_create so that we can profile threads launched by libraries

Categories

(Core :: Gecko Profiler, defect)

defect
Not set

Tracking

()

Tracking Status
firefox54 --- affected

People

(Reporter: mstange, Unassigned)

References

(Blocks 1 open bug)

Details

Threads launched by media libraries or WebRTC don't go through NS_NewNamedThread, so we don't automatically register them to the profiler.

We should investigate whether we can hook pthread_create (and the Windows equivalent) in order to automatically register all threads with the profiler.
Glandium had some ideas about this in Austin.
Flags: needinfo?(mh+mozilla)
Oh, my, this has been ni? for way too long. Sorry about that.

Windows is, interestingly, the easiest to handle. You just need a DllMain in one of our dlls (xul.dll), and have it handle the DLL_THREAD_ATTACH event. We have that in toolkit/library/nsDllMain.cpp.

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?

On mac, we can wrap pthread_create, but that won't catch any threads created by system libraries, and there are. OTOH, OSX has APIs to enumerate all threads: http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_threads.html
Flags: needinfo?(mh+mozilla)
Also note threads can be enumerated on linux by reading the directory entries in /proc/self/task. Arguably, on OSes where we can enumerate threads, we don't need to have them registered to the profiler.
You need to log in before you can comment on or make changes to this bug.