Skip to content

docs: add sftrace skill for XRay performance tracing#179

Open
stormslowly wants to merge 3 commits intomainfrom
vk/e284-migrate-rspack-s
Open

docs: add sftrace skill for XRay performance tracing#179
stormslowly wants to merge 3 commits intomainfrom
vk/e284-migrate-rspack-s

Conversation

@stormslowly
Copy link
Collaborator

Summary

  • Migrate sftrace skill from rspack monorepo, adapted for rspack-resolver
  • Support tracing both Node.js binding (pnpm test) and cargo bench benchmark binary
  • Include polars analysis examples and perfetto visualization workflow

Test plan

  • Verify RUSTFLAGS="-Zinstrument-xray=always" pnpm build:binding:profiling builds correctly
  • Verify RUSTFLAGS="-Zinstrument-xray=always" cargo +nightly bench --profile profiling --no-run produces instrumented binary
  • Verify sftrace record captures traces from both binding and benchmark targets

Migrate sftrace skill from rspack monorepo, adapted for rspack-resolver:
- Use RUSTFLAGS for XRay instrumentation instead of SFTRACE=1 env
- Reference resolver binding path instead of rspack binding
- Use pnpm test as default traced command
Copilot AI review requested due to automatic review settings March 19, 2026 16:23
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new sftrace skill to enable detailed performance tracing for the rspack-resolver project. It provides comprehensive documentation and scripts for instrumenting Rust code with LLVM XRay, recording traces from both Node.js bindings and benchmark binaries, and subsequently analyzing the collected data using Polars or visualizing it with Perfetto. This enhancement aims to provide developers with powerful tools for performance analysis and troubleshooting within the Rust codebase.

Highlights

  • sftrace skill migration: The sftrace skill has been migrated from the rspack monorepo and adapted specifically for rspack-resolver.
  • Tracing support: Support has been added for tracing both the Node.js binding and the Rust cargo bench benchmark binary.
  • Analysis and Visualization: The skill now includes examples for Polars-based data analysis and a workflow for Perfetto visualization of trace data.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The new sftrace skill documentation is a valuable addition, providing clear steps for performance analysis. I've identified a couple of areas where the documentation could be improved for better maintainability and user experience. Specifically, the BENCH_BIN definition is repeated multiple times, and the TRACE_DIR variable in the optional analysis and visualization steps could be made more explicit to avoid manual replacement.

Comment on lines +47 to +48
BENCH_BIN="$(ls -t target/profiling/deps/resolver-* | grep -v '\.d$' | head -1)"
```

Choose a reason for hiding this comment

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

medium

The command to define BENCH_BIN is repeated several times throughout the document (e.g., lines 47-48, 58-59, 83-84). To improve maintainability and reduce redundancy, consider defining this variable once at the beginning of the 'Workflow' section or at least before its first use, and then referencing it. This ensures that if the naming convention or path changes, only one place needs to be updated.

Suggested change
BENCH_BIN="$(ls -t target/profiling/deps/resolver-* | grep -v '\.d$' | head -1)"
```
BENCH_BIN="$(ls -t target/profiling/deps/resolver-* | grep -v '\.d$' | head -1)"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new .agents skill document describing how to use sftrace (LLVM XRay instrumentation) to collect and analyze function-level traces for rspack-resolver, including Node binding and cargo bench workflows.

Changes:

  • Introduces an end-to-end sftrace tracing workflow (build, instrument, record) for both N-API tests and the Criterion benchmark binary.
  • Adds optional filtering guidance via symbol extraction and sftrace filter.
  • Documents post-processing workflows for analysis (polars) and visualization (perfetto protobuf output).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +110 to +114
| name | type | description |
| -------- | ----------- | -------------------------------------------------------------------------- |
| frame_id | uint64 | a unique id for each frame. a function's entry and exit have same frame id |
| parent | uint64 | point to previous frame id. zero means non-existent |
| tid | uint32 | thread id |
Comment on lines +19 to +24
git clone https://github.com/quininer/sftrace
cd sftrace
cargo build --release
mkdir "$(./target/release/sftrace record --print-solib-install-dir)"
cp ./target/release/libsftrace.so "$(./target/release/sftrace record --print-solib-install-dir)/"
```
Comment on lines +28 to +42
XRay instrumentation must be enabled via RUSTFLAGS. There are two targets: the Node.js binding and the Rust benchmark binary.

#### 2a) Node.js binding

```sh
RUSTFLAGS="-Zinstrument-xray=always" pnpm build:binding:profiling
```

The `.node` binding file will be output to the project root (e.g. `resolver.darwin-arm64.node`).

#### 2b) Benchmark binary

```sh
RUSTFLAGS="-Zinstrument-xray=always" cargo +nightly bench --profile profiling --no-run
```
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2bc192b3b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +86 to +87
# Full trace
sftrace record -o "$TRACE_DIR/sf.log" -- "$BENCH_BIN" --bench

Choose a reason for hiding this comment

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

P1 Badge Remove the unsupported --bench flag from direct bench runs

These commands execute the compiled benchmark binary directly, but this repo’s bench target is harness = false (Cargo.toml:23-25) and uses criterion_main!(resolver) (benches/resolver.rs:357-358). In codspeed-criterion-compat, that generated main only parses an optional positional FILTER and --exact, so passing libtest’s --bench flag makes the binary exit on an unknown argument instead of recording any trace.

Useful? React with 👍 / 👎.

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.

3 participants