Closed Bug 2025245 Opened 5 days ago Closed 2 days ago

Testcase with audio worklets does not get proper stack unwinding on the Profiler

Categories

(Core :: Gecko Profiler, defect)

defect

Tracking

()

RESOLVED FIXED
151 Branch
Tracking Status
firefox151 --- fixed

People

(Reporter: mayankleoboy1, Assigned: canova, NeedInfo)

References

(Blocks 1 open bug)

Details

(Whiteboard: [fp])

Attachments

(2 files)

Attached file AudioWorklet.html
  1. Open testcase
  2. Enter 5000, 1
  3. Click Register
  4. Start profiler
  5. Click Run
  6. Let it run fir 30s
  7. Capture the profile

AR: parts of the profile on the GraphRunner thread dont seem to get stack unwinding.
ER: They should?

https://share.firefox.dev/4rQI9vr

Thanks for reporting! Indeed stack walking looks very broken.

Looking at the code, first I suspected that maybe we are calling an asm function without proc attributes for Windows stack walking (similar to bug 1981690) but I was wrong because I was having the same issue on macOS.

Looking at the code where we add the "Worklet Process" frame label, it looks like it's heavily JS engine related, so it's likely that some JS functions are calling and we are failing to stack walk there.

And looking at the WorkletThread.cpp around the place where we initialize the JS context, we are not actually registering that JS context with the profiler. We normally register the main thread and the worker threads. That's probably the reason why we are actually failing to stack walk here.

Validating my assumption now.

Assignee: nobody → canaltinova
Status: NEW → ASSIGNED
Whiteboard: [fp]

AudioWorklet's process() calls run on the GraphRunner thread (or DOM
Worklet thread), which creates a WorkletJSContext via
EnsureCycleCollectedJSContext(). But, unlike Workers and the main
thread, this context was never registered with the profiler via
PROFILER_SET_JS_CONTEXT. As a result, when the profiler sampled these
threads during JS execution, it could only unwind native frames up to
the JS entry point but not the JS frames within process() itself.

This patch fixes this by calling PROFILER_SET_JS_CONTEXT after context
initialization and PROFILER_CLEAR_JS_CONTEXT before teardown.

Status: ASSIGNED → RESOLVED
Closed: 2 days ago
Resolution: --- → FIXED
Target Milestone: --- → 151 Branch

On the latest Nightly, I still see incomplete stacks: https://share.firefox.dev/4dLRpgN

Flags: needinfo?(canaltinova)

Hmm, I tried on the latest Nightly again on macOS and it worked on my machine: https://share.firefox.dev/4bWcvH4 It might also be a Windows only issue. I'll check it on Windows later.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: