jimblandy / perf-event

perf-event: a Rust interface to Linux performance monitoring
Apache License 2.0
111 stars 19 forks source link

Make calls to `perf_event_open` read errors from errno #19

Closed Phantomical closed 2 years ago

Phantomical commented 2 years ago

It looks like in the past this was not valid (see issue #4) but since this was last changed things seem to have changed and now the sys bindings for perf_event_open use libc::syscall which returns the error in errno.

This commit replaces the check_raw_syscall calls around perf_event_open with check_errno_syscall. This means that check_raw_syscall is no longer used so it has been deleted. I have also includes a test case to verify that the correct error code is returned in at least one case.

Fixes #18

jimblandy commented 2 years ago

This looks good - thank you! I fixed the docs, too.

Phantomical commented 2 years ago

Just as an aside - I noticed that the simple_build test fails when run under a VM since hardware events are not available. You could probably get cargo test --tests to work in CI by changing it to use a software event.

jimblandy commented 2 years ago

I have some plans to add a mock testing framework so we should be able to exercise everything in GitHub CI. That's what the "hooks" feature is for. With that we should be able to get very thorough coverage, including weird cases, despite being a very system-interaction-heavy crate.

Although - mocking doesn't help when the bug was that you misunderstood what the platform is doing, so that wouldn't help in this particular case