Skip to content

Add a --symbolicate-wasm arg to profiler-edit.#6008

Merged
mstange merged 2 commits into
firefox-devtools:mainfrom
mstange:symbolicate-wasm-script
May 11, 2026
Merged

Add a --symbolicate-wasm arg to profiler-edit.#6008
mstange merged 2 commits into
firefox-devtools:mainfrom
mstange:symbolicate-wasm-script

Conversation

@mstange

@mstange mstange commented May 7, 2026

Copy link
Copy Markdown
Contributor

This allows applying wasm symbols to existing profiles that were captured with a stripped wasm bundle.

The script looks for functions with names of the shape wasm-function[123], which is what Firefox uses when the wasm file doesn't have a names section.

Usage:

yarn build-node-tools && \
node node-tools-dist/profiler-edit.js -i input.json.gz \
--symbolicate-wasm http://host/a.wasm=./a-unstripped.wasm \
--symbolicate-wasm http://host/b.wasm=./b-unstripped.wasm \
-o out.json.gz

I've successfully used it to turn https://share.firefox.dev/4f9O7oh into https://share.firefox.dev/4nd6GKk .

@mstange mstange force-pushed the symbolicate-wasm-script branch from 52ba22e to ab1e4b6 Compare May 7, 2026 19:31
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.14286% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.79%. Comparing base (642c1fd) to head (b4054d5).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/profile-logic/wasm-symbolication.ts 84.74% 17 Missing and 1 partial ⚠️
src/node-tools/profiler-edit.ts 36.36% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6008      +/-   ##
==========================================
- Coverage   83.82%   83.79%   -0.03%     
==========================================
  Files         328      329       +1     
  Lines       34255    34395     +140     
  Branches     9572     9618      +46     
==========================================
+ Hits        28713    28821     +108     
- Misses       5114     5145      +31     
- Partials      428      429       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mstange mstange force-pushed the symbolicate-wasm-script branch 3 times, most recently from 0202adf to be15b28 Compare May 7, 2026 19:49
@mstange mstange requested a review from canova May 7, 2026 19:49
@mstange mstange force-pushed the symbolicate-wasm-script branch 2 times, most recently from a70577c to a8608c4 Compare May 7, 2026 21:54

@canova canova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for adding some tests! I added a bunch of nits to make things a bit clearer, but otherwise I don't see any issues.

This also made me look into the wasm spec a bit and learn more about it, so I think it was a good use of time 😄

This also made me think more about the source map support that I've been working on. These 2 things seem like solving it for 2 different use cases, so it seems very interesting. I didn't know about the name section in the wasm spec. I wonder how devtools handles it (or if it does). It looks like it's mostly looking at the dwarf info for now, but need to look deeper.

Comment thread .github/workflows/ci.yml
Comment thread src/node-tools/profiler-edit.ts Outdated
Comment on lines +229 to +256
const symbolicateWasm: WasmSymbolicationCliSpec[] = [];
const rawWasmArg = argv['symbolicate-wasm'];
let wasmArgs: unknown[];
if (rawWasmArg === undefined) {
wasmArgs = [];
} else if (Array.isArray(rawWasmArg)) {
wasmArgs = rawWasmArg;
} else {
wasmArgs = [rawWasmArg];
}
for (const arg of wasmArgs) {
if (typeof arg !== 'string' || arg === '') {
throw new Error('--symbolicate-wasm requires a value');
}
// Accept "<url>=<path>" if the LHS looks like a URL, otherwise treat the
// whole string as a path and infer the URL from the profile. Split on
// the last `=` so URLs containing `=` (e.g. in query strings) survive
// intact; this assumes file paths don't contain `=`.
const eqIndex = arg.lastIndexOf('=');
if (eqIndex !== -1 && /^[a-z]+:\/\//i.test(arg.slice(0, eqIndex))) {
symbolicateWasm.push({
url: arg.slice(0, eqIndex),
path: arg.slice(eqIndex + 1),
});
} else {
symbolicateWasm.push({ path: arg });
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but now that we have commander in the package.json, we can possibly simplify these things by using it.

Comment thread src/node-tools/profiler-edit.ts
Comment thread src/node-tools/profiler-edit.ts Outdated
Comment thread src/profile-logic/wasm-symbolication.ts Outdated
// Parses the function-name subsection of a wasm "name" custom section and
// returns a map from function index to name. Returns an empty map if the
// module has no name section. The function index space includes imports
// (imports come first) — same numbering used in `wasm-function[N]` strings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh can we add a link to the Firefox source code where we generate this N number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/profile-logic/wasm-symbolication.ts Outdated
Comment thread src/profile-logic/wasm-symbolication.ts
Comment thread src/profile-logic/wasm-symbolication.ts Outdated
Comment thread src/profile-logic/wasm-symbolication.ts Outdated
@mstange mstange force-pushed the symbolicate-wasm-script branch from a8608c4 to f845b5b Compare May 11, 2026 21:48
mstange added 2 commits May 11, 2026 17:52
This allows applying wasm symbols to existing profiles that were captured
with a stripped wasm bundle.

The script looks for functions with names of the shape `wasm-function[123]`,
which is what Firefox uses when the wasm file doesn't have a names section.

Usage:

```
yarn build-node-tools && \
node node-tools-dist/profiler-edit.js -i input.json.gz \
--symbolicate-wasm http://host/a.wasm=./a-unstripped.wasm \
--symbolicate-wasm http://host/b.wasm=./b-unstripped.wasm \
-o out.json.gz
```
@mstange mstange force-pushed the symbolicate-wasm-script branch from f845b5b to b4054d5 Compare May 11, 2026 21:53
@mstange mstange enabled auto-merge May 11, 2026 21:53
@mstange mstange merged commit d03a0cf into firefox-devtools:main May 11, 2026
21 checks passed
@canova canova mentioned this pull request May 26, 2026
canova added a commit that referenced this pull request May 26, 2026
Changes:

[fatadel] Remove unused dependencies from package.json (#6010)
[Nazım Can Altınova] Make profiler-cli work in sandboxed environments
(#6003)
[Markus Stange] Make profiler-edit run profile compacting before writing
out the file (#6015)
[Markus Stange] Migrate from prettier to oxfmt (#5986)
[Markus Stange] Add a --symbolicate-wasm arg to profiler-edit. (#6008)
[Markus Stange] Build and upload the cli artifact in PRs (#6020)
[Markus Stange] Use @streamparser/json if the input is too large to fit
in a V8 string (#6016)
[Nazım Can Altınova] Print also the status output right after cli `load`
command (#6019)
[Nicolas Chevobbe] Update devtools-reps to 0.27.7 (#6030)
[Nazım Can Altınova] Include `--search` option in `pq filter push`
(#6026)
[Nazım Can Altınova] Update all Yarn dependencies (2026-05-20) (#6033)
[fatadel] Translate URL track-index state through profile sanitization
(#6000)
[Markus Stange] Make withSize use a wrapper element so that it can stop
calling findDOMNode (#5988)
[Markus Stange] Fix dhat importer (#6036)
[Nazım Can Altınova] Annotate inlined frames in CLI call trees and
stacks (#6041)
[Nazım Can Altınova] Use proper types in cli tests instead of custom
inline types (#6038)
[Nazım Can Altınova] Fix text truncation for frames named after
Object.prototype methods (#6044)
[Nazım Can Altınova] Add missing key props to CodeErrorOverlay error
list items (#6047)
[depfu[bot]] ⬆️ Update oxfmt to version 0.51.0 (#6054)
[Nazım Can Altınova] 🔃 Sync: l10n -> main (May 26, 2026) (#6058)
[Nazım Can Altınova] Use URL-state symbol server for `profiler-cli
function annotate` (#6051)
[Nazım Can Altınova] Bump profiler-cli version to 0.2.0 (#6059)

And special thanks to our localizers:

fr: YD
sr: Марко Костић (Marko Kostić)
tr: Ali Demirtaş
zh-CN: Olvcpr423
zh-CN: wxie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants