Skip to content

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

Merged
emeryberger merged 4 commits intomasterfrom
filter-rust-stdlib
Mar 3, 2026
Merged

Filter Rust stdlib/dependency paths from profiling by default#275
emeryberger merged 4 commits intomasterfrom
filter-rust-stdlib

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 and #274.

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 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>
emeryberger and others added 3 commits March 2, 2026 21:36
…tform gates

- Remove duplicate static is_coz_header() from inspect.cpp (already in path_filter.h)
- Remove #[cfg(target_os = "linux")] gates re-added during merge to rust/src/lib.rs
- Remove #[cfg(not(target_os = "linux"))] no-op stubs re-added during merge

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@emeryberger emeryberger merged commit 7a788b5 into master Mar 3, 2026
1 of 2 checks passed
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