Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace/BPT trap on Mac #131

Open
DavidBJaffe opened this issue May 30, 2022 · 6 comments
Open

Trace/BPT trap on Mac #131

DavidBJaffe opened this issue May 30, 2022 · 6 comments

Comments

@DavidBJaffe
Copy link

DavidBJaffe commented May 30, 2022

This code:

use pprof::ProfilerGuard;
static mut GUARD: Option<ProfilerGuard<'static>> = None;
static mut BLACKLIST: Vec<String> = Vec::new();
pub fn start_profilingx(blacklist: &[String]) {
    let frequency = 1000;
    unsafe {
        BLACKLIST = blacklist.to_vec();
        GUARD = Some(pprof::ProfilerGuard::new(frequency).unwrap());
    }
}
pub fn profiling_blacklistx() -> Vec<String> {
    vec!["woof".to_string()]
}
fn main() {
    start_profilingx(&profiling_blacklistx());
    let mut mc = 0;
    for i in 0..10_000 {
        for j in 0..10_000 {
            let n = i * j;
            mc = (mc + n) % 999;
        }
    }
    eprintln!("mc = {}", mc);
}

yields Trace/BPT trap when I run it, at least most of the time. Other similar code does this most of the time.

It is exceptionally finicky. For example, changing vec!["woof".to_string()] to vec![] eliminates the problem.

This is using master on pprof, but also occurs in 0.6.

I believe that the problem may be restricted to particular Mac versions. I have:

rustc 1.60.0
OSX 12.4
chip = apple M1 Pro

[profile.dev]
debug = 1
opt-level = 3
split-debuginfo = "unpacked"

@DavidBJaffe
Copy link
Author

I have now encountered the same error when not using pprof at all.

@DavidBJaffe
Copy link
Author

DavidBJaffe commented May 30, 2022

Reopening. The problem is presumably with libunwind, but it makes pprof unusable on a Mac, or more precisely on my Mac. Another person reproduced the problem on a non-M1 Mac. Maybe the problem occurs on all Macs.

@ricardopieper
Copy link

ricardopieper commented Jun 2, 2022

I'm having this problem as well, on a Mac M1 pro, same thing as yours, no profile.dev settings. Throws somewhere on libunwind when calling .pprof() at this part:

libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm64>::step() (@libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm64>::step():162)

@DavidBJaffe
Copy link
Author

I've actually been unable to get any form of profiling to work on my Mac, so for me at least, getting this to work would be phenomenally helpful.

@YangKeao
Copy link
Member

YangKeao commented Jun 6, 2022

For mac user, the frame-pointer is a more suggested way to get the backtrace, as the mac os has established an ecosystem of using the frame pointer, which is much more efficient and simpler than dwarf. More information can be found in #75 (comment) .

In the latest nightly of pprof-rs, enabling the frame-pointer feature will use the frame-pointer to get the backtrace. For the 0.9 release, you could disable the backtrace-rs feature (which is the default) and enable the frame-pointer feature.

If you insist on using the dwarf way, you could try to add more things to the blacklist (according to the fault backtrace). It seems that some parts of mac os (context.pc) don't deliver with understandable dwarf information. We have experience the same situation on tikv/tikv#9957 (comment) .

@DavidBJaffe
Copy link
Author

Yes, that works really well, thank you!

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

No branches or pull requests

3 participants