Skip to content

Commit

Permalink
feat(profiling): Use frame-pointer for stack unwinding and update to …
Browse files Browse the repository at this point in the history
…pprof 0.10.1 (#497)
  • Loading branch information
viglia committed Sep 1, 2022
1 parent a9f81cb commit bb81c88
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
8 changes: 3 additions & 5 deletions sentry-core/Cargo.toml
Expand Up @@ -27,6 +27,7 @@ client = ["rand"]
debug-logs = ["log_"]
test = ["client"]
profiling = ["pprof", "build_id", "uuid", "sys-info", "findshlibs"]
frame-pointer = ["pprof?/frame-pointer"]

[dependencies]
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }
Expand All @@ -40,11 +41,8 @@ sys-info = { version = "0.9.1", optional = true }
build_id = { version = "0.2.1", optional = true }
findshlibs = { version = "=0.10.2", optional = true }

[target.'cfg(all(not(target_os = "windows"), not(all(target_os = "macos", target_arch = "aarch64"))))'.dependencies]
pprof = { version = "0.10.0", optional = true, default-features = false }

[target.'cfg(all(target_os = "macos", target_arch = "aarch64"))'.dependencies]
pprof = { version = "0.10.0", optional = true, default-features = false, features = ["frame-pointer"]}
[target.'cfg(target_family = "unix")'.dependencies]
pprof = { version = "0.10.1", optional = true, default-features = false}

[dev-dependencies]
# Because we re-export all the public API in `sentry`, we actually run all the
Expand Down
14 changes: 7 additions & 7 deletions sentry-core/src/performance.rs
@@ -1,7 +1,7 @@
use std::sync::Arc;
use std::sync::Mutex;

#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
use crate::profiling;
use crate::{protocol, Hub};

Expand Down Expand Up @@ -273,7 +273,7 @@ pub(crate) struct TransactionInner {
sampled: bool,
pub(crate) context: protocol::TraceContext,
pub(crate) transaction: Option<protocol::Transaction<'static>>,
#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
pub(crate) profiler_guard: Option<profiling::ProfilerGuard>,
}

Expand Down Expand Up @@ -320,7 +320,7 @@ impl Transaction {
}
// if the transaction was sampled then a profile, linked to the transaction,
// might as well be sampled
#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
let profiler_guard = if sampled {
client.as_deref().and_then(profiling::start_profiling)
} else {
Expand All @@ -333,7 +333,7 @@ impl Transaction {
sampled,
context,
transaction,
#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
profiler_guard,
})),
}
Expand All @@ -354,7 +354,7 @@ impl Transaction {
sampled,
context,
transaction: None,
#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
profiler_guard: None,
})),
}
Expand Down Expand Up @@ -423,15 +423,15 @@ impl Transaction {

// if the profiler is running for the given transaction
// then call finish_profiling to return the profile
#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
let profile = inner.profiler_guard.take().and_then(|profiler_guard| {
profiling::finish_profiling(&transaction, profiler_guard, inner.context.trace_id)
});

let mut envelope = protocol::Envelope::new();
envelope.add_item(transaction);

#[cfg(all(feature = "profiling", not(target_os = "windows")))]
#[cfg(all(feature = "profiling", target_family = "unix"))]
if let Some(profile) = profile {
if !profile.sampled_profile.samples.is_empty(){
envelope.add_item(profile);
Expand Down
4 changes: 2 additions & 2 deletions sentry-core/src/profiling.rs
Expand Up @@ -183,9 +183,9 @@ fn get_profile_from_report(
.frames
.iter()
.map(|frame| RustFrame {
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[cfg(feature = "frame-pointer")]
instruction_addr: format!("{:p}", frame.ip as *mut core::ffi::c_void),
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
#[cfg(not(feature = "frame-pointer"))]
instruction_addr: format!("{:p}", frame.ip()),
})
.collect();
Expand Down
1 change: 1 addition & 0 deletions sentry/Cargo.toml
Expand Up @@ -36,6 +36,7 @@ tower = ["sentry-tower"]
tower-http = ["sentry-tower", "sentry-tower/http"]
tracing = ["sentry-tracing"]
profiling = ["sentry-core/profiling"]
frame-pointer = ["sentry-core/frame-pointer"]
# other features
test = ["sentry-core/test"]
debug-logs = ["log_", "sentry-core/debug-logs"]
Expand Down

0 comments on commit bb81c88

Please sign in to comment.