tikv / pprof-rs

A Rust CPU profiler implemented with the help of backtrace-rs
Apache License 2.0
1.29k stars 99 forks source link

add riscv arch #169

Closed victoryang00 closed 1 year ago

victoryang00 commented 1 year ago

I'm doing homework that runs tikv and risingwave riscv64 version and encountered compiling error when going through pprof.

Add support for riscv64 with pc support.

#[cfg(all(target_arch = "riscv64", target_os = "linux"))]
let addr = unsafe { (*ucontext).uc_mcontext.__gregs[libc::REG_PC] as usize };

There's no riscv64gc-unknown-linux-gnu CI machine. My proposal is to add a specific test that uses the following in .cargo/config.toml to run riscv64 benches and tests.

[build]
target = "riscv64gc-unknown-linux-gnu"

[target.riscv64gc-unknown-linux-gnu]
linker = "riscv64-linux-gnu-gcc"
runner = " qemu-riscv64 "
rustflags = ["-C", "link-arg=-s", "-C", "target-feature=+crt-static"]
YangKeao commented 1 year ago

Cool, please add sign-off through git commit -s --amend

victoryang00 commented 1 year ago

Cool, please add sign-off through git commit -s --amend

fixed

YangKeao commented 1 year ago

Would you mind rebase the master, as https://github.com/tikv/pprof-rs/pull/175 should have fixed the CI error :thinking: .

Another thing is that would you mind also support frame pointer for riscv? Like https://github.com/tikv/pprof-rs/pull/174/files#diff-8fa537005d71550f49aaa53c3d12aa6356b8a9f8699fee61ead4f83f93128e52R77 . (Though I know nothing about the RISC-V convention on frame pointer. If this suggestion is not realistic, just ignore it.)

victoryang00 commented 1 year ago
#[cfg(all(target_arch = "riscv64", target_os = "linux"))]
let frame_pointer = unsafe { (*ucontext).uc_mcontext.__gregs[libc::REG_S0] as usize };

added frame pointer support, in riscv ABI, s0 is fp.