flamegraph-rs / flamegraph

Easy flamegraphs for Rust projects and everything else, without Perl or pipes <3
Apache License 2.0
4.62k stars 141 forks source link

--root not equivalent to sudo on OSX? #246

Closed brainstorm closed 1 year ago

brainstorm commented 1 year ago

I expected --root to prepend the commandline with sudo? According to cargo flamegraph --help:

--root Run with root privileges (using sudo)

But in practice, it doesn't seem to work as expected whereas manually prepending sudo works fine? I'd propose to eliminate the flag to avoid confusion.

% uname -a
Darwin m1.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103 arm64 arm Darwin

% cargo flamegraph --root --deterministic --flamechart --bench search-benchmarks -- --bench
error: failed to open: /Users/rvalls/dev/umccr/htsget-rs/target/release/.cargo-lock

Caused by:
  Permission denied (os error 13)
Error: cargo build failed

% sudo cargo flamegraph --deterministic --flamechart --bench search-benchmarks -- --bench 
Password:
    Finished bench [optimized + debuginfo] target(s) in 0.29s
dtrace: description 'profile-997 ' matched 1 probe
Queries/[LIGHT] Bam query all
                        time:   [6.8563 µs 6.9011 µs 6.9560 µs]
                        change: [+0.2158% +0.9165% +1.6930%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 3 outliers among 50 measurements (6.00%)
  3 (6.00%) high mild
(...)

I'm questioning the docs in the README.md too, which state:

DTrace on macOS

On macOS, there is no alternative to running as superuser in order to enable dtrace. The simplest way is to use --root, this way rustc will be run normally but the binary will get run as superuser.

djc commented 1 year ago

I think the initial error you ran into is because flamegraph only tries to run the workload command with sudo -- that shouldn't need release/.cargo-lock, which likely gets permission denied because you compiled as root before running that command.

If you feel the documentation can be improved, please submit a well-argued change as a PR.