Closed Bug 1369222 Opened 7 years ago Closed 2 years ago

Allow deregistration of threads whose lifetimes we do not control

Categories

(Core :: Gecko Profiler, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1773286

People

(Reporter: bugzilla, Unassigned)

References

(Blocks 1 open bug)

Details

I have a bit of a unique situation: I need to profile some threads that are launched by the OS as part of the system thread pool. Registering those threads is easy enough; I just lazily call profiler_register_thread the first time our code sees an unregistered thread pool thread.

Unfortunately, the system is controlling the lifetime of the threads in its pool and there is no mechanism for a finishing thread to call back into our code before it terminates.

Can we add a profiler_unregister_thread(tid) call, or some other mechanism so that we can unregister a thread other than the calling thread?
Markus, thoughts?
Flags: needinfo?(mstange)
(In reply to Aaron Klotz [:aklotz] (a11y work receiving priority right now, please send interceptor reviews to dmajor or handyman) from comment #0)
> Can we add a profiler_unregister_thread(tid) call, or some other mechanism
> so that we can unregister a thread other than the calling thread?

Sure, that seems reasonable. When and where would you call it? I think you still have to call it before the thread actually disappears, otherwise we'll attempt to sample a non-existent thread and I don't know how well that would go over.
Flags: needinfo?(mstange) → needinfo?(nfroyd)
(In reply to Markus Stange [:mstange] from comment #2)
> Sure, that seems reasonable. When and where would you call it? I think you
> still have to call it before the thread actually disappears, otherwise we'll
> attempt to sample a non-existent thread and I don't know how well that would
> go over.

That's a good point... Unfortunately, the best that I can probably do is wait on the pool thread's handle which wouldn't be signalled until the thread was already gone, which brings us right back to the original problem. :(
Though from what I see of the profiler sampling code, the sampler would safely recover on Windows and Mac. It looks like the linux/android sampler would need to be changed to fail gracefully from tgkill(2).
(In reply to Aaron Klotz [:aklotz] (a11y work receiving priority right now, please send interceptor reviews to dmajor or handyman) from comment #4)
> Though from what I see of the profiler sampling code, the sampler would
> safely recover on Windows and Mac. It looks like the linux/android sampler
> would need to be changed to fail gracefully from tgkill(2).

That doesn't seem too bad then. Maybe we could even unregister a thread automatically if the sampler detects that it has gone away? We'd only do that for threads that are explicitly marked as "not under our control".
Flags: needinfo?(nfroyd)
(In reply to Markus Stange [:mstange] from comment #5)
> That doesn't seem too bad then. Maybe we could even unregister a thread
> automatically if the sampler detects that it has gone away? We'd only do
> that for threads that are explicitly marked as "not under our control".

That thought crossed my mind as well. I think that might make for a cleaner API with no potential for footguns.

I'll try to throw together a patch.

Coincidentally (as I'm reviewing unprioritized bugs), bug 1773286 was just filed with the same request.
Since this bug here is 5 years old, and thread registration has changed a bit since then, I'll mark it as duplicate. I'll mention Aaron's prototype there.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.