Skip to content

feat(wasm): support tracing-chrome in wasm#10246

Merged
h-a-n-a merged 7 commits intoweb-infra-dev:mainfrom
CPunisher:04-29-feat/wasm-tracing
May 7, 2025
Merged

feat(wasm): support tracing-chrome in wasm#10246
h-a-n-a merged 7 commits intoweb-infra-dev:mainfrom
CPunisher:04-29-feat/wasm-tracing

Conversation

@CPunisher
Copy link
Contributor

@CPunisher CPunisher commented Apr 29, 2025

Summary

Debugging wasm is very painful. So I hope this pr could help us find where the wasm crushes or get stuck. There are two things to do:

  • tracing-chrome send the writer to a isolated thread to write the traces. However, threads in wasm are actually node workers. They can't share file descriptors with each other Passing fd between threads causes VM to crash, or EBADF  nodejs/node#30507. The solution is passing a writer creator instead of a writer when building chrome tracer.
  • cleanup function is called by exit-hook and sends an flush message to the tracing thread. This means cleanup function is called when there's no active handlers (workers) running, which means the chrome tracing thread is not running. So we may choose another way to call cleanup. @hardfist @h-a-n-a Do you have any suggestion?

This pr can be holding on until there is a good solution.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@CPunisher CPunisher requested a review from h-a-n-a as a code owner April 29, 2025 10:32
@CPunisher CPunisher marked this pull request as draft April 29, 2025 10:33
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Apr 29, 2025
@netlify
Copy link

netlify bot commented Apr 29, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 8258e44
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/681b186c1cf7200008d27417

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 29, 2025

CodSpeed Performance Report

Merging #10246 will not alter performance

Comparing CPunisher:04-29-feat/wasm-tracing (8258e44) with main (972c005)

Summary

✅ 11 untouched benchmarks

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Apr 29, 2025

cleanup function is called by exit-hook and sends an flush message to the tracing thread. This means cleanup function is called when there's no active handlers (workers) running, which means the chrome tracing thread is not running. So we may choose another way to call cleanup.

I'm confused of what kind of problem you're resolving. What is wasm tracing cleanup related to? Does it mean that cleanup function should be invoked before workers are destroyed?

EDIT: I checked out the tracing_chrome code, it uses an separate thread to write buffers into files. Do you mean to find a way to write tracing into trace file before it was destroyed? I think we are on the same page now. If that is the case, is it possible for you to leverage rspack.experiments.globalTrace.cleanup to eagerly flush the tracer?

@CPunisher
Copy link
Contributor Author

CPunisher commented Apr 29, 2025

If that is the case, is it possible for you to leverage rspack.experiments.globalTrace.cleanup to eagerly flush the tracer?

I think so. Just now I realize that cleanupGlobalTrace actually flushes the writer rather than shutdowns everything. So we can call it anywhere.

@CPunisher CPunisher marked this pull request as ready for review April 29, 2025 13:49
@h-a-n-a h-a-n-a force-pushed the 04-29-feat/wasm-tracing branch from c97564e to 8258e44 Compare May 7, 2025 08:23
@h-a-n-a h-a-n-a merged commit 8a5dba1 into web-infra-dev:main May 7, 2025
35 checks passed
@h-a-n-a
Copy link
Contributor

h-a-n-a commented May 7, 2025

Thanks!

@CPunisher CPunisher deleted the 04-29-feat/wasm-tracing branch May 12, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants