Comments (5)
Good! #150 is working on separating multiple implementations on different platforms. It would be better to take *bsd into consideration https://doc.rust-lang.org/reference/conditional-compilation.html#target_os .
from pprof-rs.
This would be a start:
diff --git a/src/addr_validate.rs b/src/addr_validate.rs
index 9e9a34c..6094d6c 100644
--- a/src/addr_validate.rs
+++ b/src/addr_validate.rs
@@ -41,6 +41,29 @@ fn create_pipe() -> nix::Result<(i32, i32)> {
Ok((read_fd, write_fd))
}
+#[inline]
+#[cfg(target_os = "freebsd")]
+fn create_pipe() -> nix::Result<(i32, i32)> {
+ use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag};
+ use nix::unistd::pipe;
+ use std::os::unix::io::RawFd;
+
+ fn set_flags(fd: RawFd) -> nix::Result<()> {
+ let mut flags = FdFlag::from_bits(fcntl(fd, FcntlArg::F_GETFD)?).unwrap();
+ flags |= FdFlag::FD_CLOEXEC;
+ fcntl(fd, FcntlArg::F_SETFD(flags))?;
+ let mut flags = OFlag::from_bits(fcntl(fd, FcntlArg::F_GETFL)?).unwrap();
+ flags |= OFlag::O_NONBLOCK;
+ fcntl(fd, FcntlArg::F_SETFL(flags))?;
+ Ok(())
+ }
+
+ let (read_fd, write_fd) = pipe()?;
+ set_flags(read_fd)?;
+ set_flags(write_fd)?;
+ Ok((read_fd, write_fd))
+}
+
fn open_pipe() -> nix::Result<()> {
MEM_VALIDATE_PIPE.with(|pipes| {
let mut pipes = pipes.borrow_mut();
diff --git a/src/profiler.rs b/src/profiler.rs
index 4bc72ad..52fcb86 100644
--- a/src/profiler.rs
+++ b/src/profiler.rs
@@ -208,6 +208,11 @@ impl ErrnoProtector {
let errno = *libc::__errno_location();
Self(errno)
}
+ #[cfg(target_os = "freebsd")]
+ {
+ let errno = *libc::__error();
+ Self(errno)
+ }
#[cfg(target_os = "macos")]
{
let errno = *libc::__error();
from pprof-rs.
Or even better:
diff --git a/src/addr_validate.rs b/src/addr_validate.rs
index 9e9a34c..7ceafd0 100644
--- a/src/addr_validate.rs
+++ b/src/addr_validate.rs
@@ -19,7 +19,7 @@ fn create_pipe() -> nix::Result<(i32, i32)> {
}
#[inline]
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "freebsd"))]
fn create_pipe() -> nix::Result<(i32, i32)> {
use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag};
use nix::unistd::pipe;
diff --git a/src/profiler.rs b/src/profiler.rs
index 4bc72ad..d89c164 100644
--- a/src/profiler.rs
+++ b/src/profiler.rs
@@ -208,7 +208,7 @@ impl ErrnoProtector {
let errno = *libc::__errno_location();
Self(errno)
}
- #[cfg(target_os = "macos")]
+ #[cfg(any(target_os = "macos", target_os = "freebsd"))]
{
let errno = *libc::__error();
Self(errno)
from pprof-rs.
@YangKeao do you think it still makes sense to do this as part of #150 or should we consider doing something like my suggestion?
from pprof-rs.
Or even better:
diff --git a/src/addr_validate.rs b/src/addr_validate.rs index 9e9a34c..7ceafd0 100644 --- a/src/addr_validate.rs +++ b/src/addr_validate.rs @@ -19,7 +19,7 @@ fn create_pipe() -> nix::Result<(i32, i32)> { } #[inline] -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "freebsd"))] fn create_pipe() -> nix::Result<(i32, i32)> { use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag}; use nix::unistd::pipe; diff --git a/src/profiler.rs b/src/profiler.rs index 4bc72ad..d89c164 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -208,7 +208,7 @@ impl ErrnoProtector { let errno = *libc::__errno_location(); Self(errno) } - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "freebsd"))] { let errno = *libc::__error(); Self(errno)
Thank you. I'll test this patch (and add some other modification, if needed) on freebsd tonight. Let's make pprof-rs
compile on freebsd 🍻.
from pprof-rs.
Related Issues (20)
- Use another way to test malloc-free
- Add doc comment for ProfilerGuardBuilder::frequency
- pipe fd(s) opened in addr_validate::validate will not be closed for short-term threads
- Getting a seg fault with no error or line number HOT 2
- SIGBUS: access to undefined memory
- trace is trying to dereferencing misaligned pointer HOT 3
- SIGABORT when profiling with pyroscope-rs HOT 1
- Unable to compile pprof with MSRV 1.64.0 HOT 5
- Update to use prost 0.12 HOT 1
- [Unsound] Slice created from unaligned pointer HOT 8
- cannot out flamegraph
- SIGTRAP With Criterion and Flamegraph Features HOT 12
- Question: I want to pprof every 30s. should I put `ProfilerGuard` in loop? HOT 2
- Inconsistent code: the line is for FreeBSD in a function that excluded FreeBSD
- No 0.13.0 tag
- high memory usage HOT 3
- Documentation and error message for protobuf features should be made more clear
- UnresolvedFrames is undocumented HOT 1
- Compilation fails on OpenBSD
- Tests fail with latest rustc. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pprof-rs.