Skip to content

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

Closed
emeryberger wants to merge 2 commits intomasterfrom
filter-rust-stdlib-paths-v2
Closed

Filter Rust stdlib/dependency paths from profiling by default#274
emeryberger wants to merge 2 commits intomasterfrom
filter-rust-stdlib-paths-v2

Conversation

@emeryberger
Copy link
Copy Markdown
Member

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

Supersedes #272.

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

emeryberger and others added 2 commits March 2, 2026 19:52
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>
@emeryberger emeryberger closed this Mar 3, 2026
@emeryberger emeryberger deleted the filter-rust-stdlib-paths-v2 branch March 3, 2026 02:12
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.

1 participant