1

I have been using the flamegraph profiler, rs-flamegraph, quite successfully over the past few days. When I run it from bash it works fine. No sudo or anything.

~/.cargo/bin/flamegraph -o "$f flamegraph.svg" ./binary 

When I invoke the binary from Rust using process::Command it fails saying that it cannot sample collapsed stack.

let svgfilename = format!("{} flamegraph.svg", path);
let execution = std::process::Command::new("/home/arkadiusz/.cargo/bin/flamegraph")
.arg("-o").arg(&svgfilename)
.arg("./binary").arg("solve").arg("real-data").arg("/dev/null")
.output().unwrap();

Full error:

WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,
check /proc/sys/kernel/kptr_restrict and /proc/sys/kernel/perf_event_paranoid.

Samples in kernel functions may not be resolved if a suitable vmlinux
file is not found in the buildid cache or in the vmlinux path.

Samples in kernel modules won't be resolved at all.

If some relocation was applied (e.g. kexec) symbols may be misresolved
even with a suitable vmlinux or kallsyms file.

Couldn't record kernel reference relocation symbol
Symbol resolution may be skewed if relocation was used (e.g. kexec).
Check /proc/kallsyms permission or run as root.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0,000 MB (null) ]
thread 'main' panicked at 'unable to generate a flamegraph from the collapsed stack data: Io(Custom { kind: InvalidData, error: "No stack counts found" })', /home/arkadiusz/.cargo/registry/src/github.com-1ecc6299db9ec823/flamegraph-0.4.0/src/lib.rs:315:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
ArekBulski
  • 4,520
  • 4
  • 39
  • 61
  • Is this still true when the Rust command is run from the same parent process? (I wonder if we could have different SELinux contexts or other restrictions, if the Rust command is running as a service). – Charles Duffy Apr 16 '21 at 18:56
  • The command line in bash and rust look different, i.e. there are additional arguments in the rust version. – Steffen Ullrich Apr 16 '21 at 19:38
  • Well, I managed to get it working although honestly not sure how. I think adding .stdout(inherit) solved it. – ArekBulski Apr 16 '21 at 22:28
  • Why not bring it up as an issue on the crate repo https://github.com/flamegraph-rs/flamegraph? Also, `rs-flamegraph` is not _the_ Rust profiler. It is _a_ profiling tool written in Rust and usable with binaries written in Rust (among others) – Cornelius Roemer Jan 15 '23 at 09:37

0 Answers0