Skip to content

Filter Rust stdlib/dependency paths from profiling by default#272

Closed
emeryberger wants to merge 1 commit intomasterfrom
filter-rust-stdlib-paths
Closed

Filter Rust stdlib/dependency paths from profiling by default#272
emeryberger wants to merge 1 commit intomasterfrom
filter-rust-stdlib-paths

Conversation

@emeryberger
Copy link
Copy Markdown
Member

@emeryberger emeryberger commented Mar 2, 2026

Summary

When profiling Rust programs, coz was attributing results to lines in the Rust standard library and third-party dependencies. Their source paths (/rustc/<hash>/..., ~/.rustup/..., ~/.cargo/registry/...) were not recognized as system paths, so they passed through source filtering and appeared in profiling output.

  • Extract path filtering functions into libcoz/path_filter.h for reuse and testability
  • Add is_rust_path() to identify Rust toolchain/dependency paths:
    • /rustc/... — always filtered (synthetic paths embedded by rustc)
    • $HOME/.rustup/... — filtered only when under the user's actual $HOME
    • $HOME/.cargo/registry/... and $HOME/.cargo/git/... — same
  • Rust paths are filtered by default (with the default % source scope), but an explicit --source-scope overrides the filter
  • Remove #[cfg(target_os = "linux")] gate from the Rust crate's coz_get_counter function — dlsym is POSIX-standard, so coz::progress!() and other macros now work on macOS too
  • Add unit tests (65 assertions) covering path detection, $HOME scoping, scope override behavior
  • Add Rust integration test that builds a stdlib-heavy binary, confirms DWARF debug info contains /rustc/ paths, and validates they are excluded from profiling output

Test plan

  • Unit tests pass (65/65 assertions in tests/path_filter/path_filter_test.cpp)
  • Rust integration test passes (tests/run_rust_filter_test.sh)
    • Phase 1: Confirms 209 unique /rustc/ paths in DWARF debug info
    • Phase 2: Validates profiling output excludes Rust stdlib paths
  • CI build and existing tests pass
  • Verify --source-scope '/rustc/%' overrides the filter when explicitly requested

🤖 Generated with Claude Code

Comment on lines +47 to +52
if(path_contains(normalized, "/.rustup/"))
return true;
if(path_contains(normalized, "/.cargo/registry/"))
return true;
if(path_contains(normalized, "/.cargo/git/"))
return true;
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.

Probably would be good to check that it's $HOME/.rustup not any old .rustup.

@emeryberger emeryberger force-pushed the filter-rust-stdlib-paths branch 2 times, most recently from b553f51 to 015dd43 Compare March 3, 2026 00:49
@emeryberger emeryberger closed this Mar 3, 2026
@emeryberger emeryberger reopened this Mar 3, 2026
When profiling Rust programs, coz was attributing results to lines in
the Rust standard library and third-party dependencies because their
source paths (e.g. /rustc/<hash>/..., ~/.rustup/..., ~/.cargo/...)
were not recognized as system paths.

Changes:
- Extract path filtering functions into libcoz/path_filter.h for
  reuse and testability
- Add is_rust_path() to identify Rust toolchain and dependency paths:
  /rustc/... (always filtered), $HOME/.rustup/... and
  $HOME/.cargo/{registry,git}/... (filtered using actual $HOME)
- Rust paths are filtered by default but an explicit --source-scope
  overrides the filter
- Remove #[cfg(target_os = "linux")] gate from the Rust crate's
  coz_get_counter — dlsym is POSIX-standard, so progress macros now
  work on macOS too
- Add unit tests (65 assertions) and a Rust integration test that
  verifies DWARF debug info contains /rustc/ paths and confirms
  they are excluded from profiling output

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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