Implement fetching JS sources from the JS engine at the profile gathering phase and use webchannel to return them to the frontend
Categories
(Core :: Gecko Profiler, enhancement, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox146 | --- | fixed |
People
(Reporter: canova, Assigned: canova)
References
(Blocks 1 open bug)
Details
Attachments
(11 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review |
Bug 1959977 mentions about adding sourceIds to the JS frames so we can match the sourceIds with their sources and retrieve the sources from the profiler frontend.
This bug is about doing this retrieval of the source code from the frontend. Since we have souceIds in the frotend, we can send webchannel requests with these IDs to Firefox to fetch the sources.
It's important to note that sourceId itself is not enough to fetch the source because these IDs are incremented locally per processs. So we need to send pid+sourceId to Firefox to be able to fetch it.
So the retrieval of the source code needs to happen during the profile collection time because in the future they might be destroyed. We will:
- Keep a set of
RefPtr<ScriptSource>in the gecko profiler side of the JS engine so we can make sure that the sources live until the profile collection. - (Bug 1959977) Collect sourceIds for every JS frames.
- At the end of the profiling session, while we are gathering the profiles, each process will ask the JS engine to retrieve the
sourceId -> source datamap and send it through the IPC to the parent process. (note that some sources are not possible to fetch from the child process, see step 5) - We will accumulate every map inside
pid -> (sourceId -> source data)map in the parent process. - For the sources that were not possible to fetch inside the content process, we will request them from the parent process.
- Keep this extra data in the
tab id -> profile with extra dataweakmap that we have.
And we need to implement the webchannel request that returns this information:
- (bug 1916785) When we get a webchannel request with pid+sourceId data, find the source in the weakmap and return it.
| Assignee | ||
Comment 1•9 months ago
|
||
Previously, we were generating the SharedLibraries inside the
profiler_get_profile_json and then we were trying to generate it again
inside the caller instead of using the Result value from it. Now, this
patch changes this to use the additional information we generate inside
the caller instead of generating it multiple times.
That way:
- We don't generate the same information multiple times.
- The information that we generated in the profiler calls inside
platform.cpp file is not going to be lost.
| Assignee | ||
Comment 2•9 months ago
|
||
This patch adds a new JS API for fetching the JS source data of the
JS frames that was captured during that profiling run.
We have a few constraints from the profiler:
- We have to be able to call it from a non-main thread. So we shouldn't
rely on any MainThread only data. - We shouldn't rely on a realm. We should directly return the source
string if available. - If the string is not available and if it's not possible to fetch it
in a non-main thread, we should return the necessary information for
that source, so the profiler can request it later, inside the parent
process main thread.
Because of these constrains, lots of things had to be reimplemented to
fit inside these constraints.
ScriptSource::loadSource, ScriptSource::substring, and
ScriptSource::functionBodyString requires them be run on the main
thread, that's why we couldn't use them. I implemented
loadSourceOffMainThread, substringChars, and
functionBodyStringChars respectively that can be run outside of the
main thread.
Also I crated a struct to pass this to the profiler codebase. This will
be used to send the everything to the parent process.
For Retrievable<Unit> cases, we don't have the source code available
for them in this process. We can request them, but it requires calling
sourceHook, which also needs to be run on the main thread. It also sends
an IPC to the parent processs to request the data. Since we are
returning these sources to the parent process, we can delay fetching
them until we are on there. So we record all the necessary information
(filename) to fetch this data later, and sending that to the parent
process.
| Assignee | ||
Comment 3•9 months ago
|
||
Since we would like to send the JS source information directly to the
parent process through IPC, we need a serialization and deserialization
code to transfer this data.
| Assignee | ||
Comment 4•9 months ago
|
||
This patch adds the JS sources inside the profile additional information
so we can send them through IPC.
| Assignee | ||
Comment 5•9 months ago
|
||
I add this feature now, so I can use it in the following patch when we
are retrieving the JS sources from the JS engine.
This feature is currently not on by default until we iron out all the
issues and defails.
| Assignee | ||
Comment 6•9 months ago
|
||
Finally, we implement the place where we actually request the JS sources
from the JS engine to the profiler land. We are iterating over all the
known JSContext that we recorded and request all information we have.
Then this will be send to the parent process, and the maps will be
merged.
| Assignee | ||
Comment 7•9 months ago
|
||
We convert the JS sources into an object of objects that can hold
pid -> sourceId -> source text map. That way we can keep this object
inside the devtools JS codebase.
| Assignee | ||
Comment 8•9 months ago
|
||
There were some ScriptSources with the Retrievable source type, that
we couldn't retrieve in the child process. Now that we are in the parent
process, we can actually request them in here from the JS engine.
JS engine uses the sourceHook to fetch this data and return it to us.
Then we put it inside this JS object
| Assignee | ||
Comment 9•9 months ago
|
||
| Assignee | ||
Comment 10•9 months ago
|
||
| Assignee | ||
Comment 11•7 months ago
|
||
This table keeps [uuid, filename] mapping for each source, and each
location string will include the index into source table for the
individual source for the JS frames.
Comment 12•6 months ago
|
||
Comment 13•6 months ago
|
||
Revert for causing Spidermonkey build bustages due to assertions on Interpreter.cpp.
task 2025-10-21T21:44:26.829+00:00] TEST-PASS | js/src/jit-test/tests/gc/bug-1215678.js | Success (code 3, args "--ion-eager --ion-offthread-compile=off --ion-check-range-analysis --ion-extra-checks --no-sse3 --no-threads") [11.4 s]
[task 2025-10-21T21:44:26.829+00:00] [1659] Assertion failure: cx->isExceptionPending() || cx->isPropagatingForcedReturn() || cx->hadUncatchableException(), at /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:391
[task 2025-10-21T21:44:26.829+00:00] #01: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19636ee]
[task 2025-10-21T21:44:26.829+00:00] #02: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1962d78]
[task 2025-10-21T21:44:26.829+00:00] #03: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19639c0]
[task 2025-10-21T21:44:26.829+00:00] #04: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964aee]
[task 2025-10-21T21:44:26.829+00:00] #05: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964ceb]
[task 2025-10-21T21:44:26.829+00:00] #06: JS_CallFunction(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSFunction*>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>)[/builds/worker/workspace/obj-spider/dist/bin/js +0x1aa0a0d]
[task 2025-10-21T21:44:26.829+00:00] #07: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1e7b858]
[task 2025-10-21T21:44:26.829+00:00] #08: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1e7b56b]
[task 2025-10-21T21:44:26.829+00:00] #09: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1e7ac1c]
[task 2025-10-21T21:44:26.829+00:00] #10: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1ec73f6]
[task 2025-10-21T21:44:26.829+00:00] #11: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964169]
[task 2025-10-21T21:44:26.829+00:00] #12: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19639a1]
[task 2025-10-21T21:44:26.829+00:00] #13: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964aee]
[task 2025-10-21T21:44:26.829+00:00] #14: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1973ee3]
[task 2025-10-21T21:44:26.829+00:00] #15: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x196337c]
[task 2025-10-21T21:44:26.829+00:00] #16: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1962d6b]
[task 2025-10-21T21:44:26.829+00:00] #17: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19661e3]
[task 2025-10-21T21:44:26.829+00:00] #18: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1966799]
[task 2025-10-21T21:44:26.829+00:00] #19: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1ab4b6b]
[task 2025-10-21T21:44:26.829+00:00] #20: JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>)[/builds/worker/workspace/obj-spider/dist/bin/js +0x1ab4d18]
[task 2025-10-21T21:44:26.829+00:00] #21: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x18f85d0]
[task 2025-10-21T21:44:26.829+00:00] #22: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x18f7d51]
[task 2025-10-21T21:44:26.829+00:00] #23: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1891015]
[task 2025-10-21T21:44:26.829+00:00] #24: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1888332]
[task 2025-10-21T21:44:26.829+00:00] Exit code: -11
[task 2025-10-21T21:44:26.829+00:00] FAIL - gc/bug-1234410.js
[task 2025-10-21T21:44:26.829+00:00] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/gc/bug-1234410.js | [1659] Assertion failure: cx->isExceptionPending() || cx->isPropagatingForcedReturn() || cx->hadUncatchableException(), at /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:391 (code -11, args "") [0.1 s]
[task 2025-10-21T21:44:26.829+00:00] INFO exit-status : -11
[task 2025-10-21T21:44:26.829+00:00] INFO timed-out : False
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> [1659] Assertion failure: cx->isExceptionPending() || cx->isPropagatingForcedReturn() || cx->hadUncatchableException(), at /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:391
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #01: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19636ee]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #02: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1962d78]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #03: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19639c0]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #04: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964aee]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #05: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964ceb]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #06: JS_CallFunction(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSFunction*>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>)[/builds/worker/workspace/obj-spider/dist/bin/js +0x1aa0a0d]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #07: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1e7b858]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #08: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1e7b56b]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #09: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1e7ac1c]
[task 2025-10-21T21:44:26.829+00:00] INFO stderr 2> #10: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1ec73f6]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #11: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964169]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #12: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19639a1]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #13: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1964aee]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #14: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1973ee3]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #15: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x196337c]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #16: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1962d6b]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #17: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x19661e3]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #18: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1966799]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #19: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1ab4b6b]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #20: JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>)[/builds/worker/workspace/obj-spider/dist/bin/js +0x1ab4d18]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #21: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x18f85d0]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #22: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x18f7d51]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #23: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1891015]
[task 2025-10-21T21:44:26.830+00:00] INFO stderr 2> #24: ???[/builds/worker/workspace/obj-spider/dist/bin/js +0x1888332]
[task 2025-10-21T21:44:26.830+00:00] TEST-PASS | js/src/jit-test/tests/gc/bug-1215678.js | Success (code 3, args "") [11.5 s]
Comment 14•6 months ago
|
||
Comment 15•6 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/7399eca697f8
https://hg.mozilla.org/mozilla-central/rev/de3e72a0b85d
https://hg.mozilla.org/mozilla-central/rev/d2b130ae8b0f
https://hg.mozilla.org/mozilla-central/rev/61a61d2f62ae
https://hg.mozilla.org/mozilla-central/rev/bc7646f5c0ba
https://hg.mozilla.org/mozilla-central/rev/bd1508c678f5
https://hg.mozilla.org/mozilla-central/rev/1074755101ce
https://hg.mozilla.org/mozilla-central/rev/4f67c422ee46
https://hg.mozilla.org/mozilla-central/rev/74884dc48361
https://hg.mozilla.org/mozilla-central/rev/cddbe6345bf9
https://hg.mozilla.org/mozilla-central/rev/4915afa07907
| Assignee | ||
Updated•6 months ago
|
Updated•6 months ago
|
Description
•