Checking in progress, though not fully working as expected
This commit is contained in:
+6
-37
@@ -61,53 +61,22 @@ pub fn dump_dhat_heap_profile() {
|
||||
let _ = HEAP_PROFILER.lock().take();
|
||||
}
|
||||
|
||||
/// Dumps a jemalloc heap profile and sends it to Sentry.
|
||||
/// Dumps a jemalloc heap profile for local diagnostics.
|
||||
///
|
||||
/// On Linux the profile is produced in-process via the `jemalloc_pprof` crate
|
||||
/// as a raw (unsymbolized) pprof -- sample addresses + mappings + GNU build-id
|
||||
/// -- and is symbolized offline against the debug-info file uploaded to Sentry
|
||||
/// by the release process (matched by build-id). On other platforms it spawns
|
||||
/// -- and is symbolized offline. On other platforms it spawns
|
||||
/// the bundled `pprof` binary to fetch and symbolicate the heap profile from
|
||||
/// the local HTTP server. Either way, the resulting profile is attached to a
|
||||
/// Sentry event.
|
||||
/// the local HTTP server. Either way, the resulting profile is logged locally.
|
||||
#[cfg(feature = "heap_usage_tracking")]
|
||||
pub async fn dump_jemalloc_heap_profile(memory_breakdown: serde_json::Value) {
|
||||
use sentry::protocol::{Attachment, AttachmentType};
|
||||
|
||||
let result = dump_jemalloc_heap_profile_inner().await;
|
||||
match result {
|
||||
Ok(profile_data) => {
|
||||
let attachment = Attachment {
|
||||
buffer: profile_data,
|
||||
filename: "heap-profile.pb".to_string(),
|
||||
ty: Some(AttachmentType::Attachment),
|
||||
..Default::default()
|
||||
};
|
||||
sentry::with_scope(
|
||||
|scope| {
|
||||
scope.add_attachment(attachment);
|
||||
|
||||
// Attach the memory breakdown as structured context so it
|
||||
// is visible directly in the Sentry event.
|
||||
if let serde_json::Value::Object(map) = memory_breakdown {
|
||||
let context_map: std::collections::BTreeMap<
|
||||
String,
|
||||
sentry::protocol::Value,
|
||||
> = map.into_iter().collect();
|
||||
scope.set_context(
|
||||
"memory_breakdown",
|
||||
sentry::protocol::Context::Other(context_map),
|
||||
);
|
||||
}
|
||||
},
|
||||
|| {
|
||||
sentry::capture_message(
|
||||
"Excessive memory usage detected",
|
||||
sentry::Level::Warning,
|
||||
)
|
||||
},
|
||||
log::warn!(
|
||||
"Excessive memory usage detected; heap profile generated ({} bytes): {memory_breakdown}",
|
||||
profile_data.len()
|
||||
);
|
||||
log::info!("Sent heap profile to Sentry");
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("Failed to dump heap profile: {err:#}");
|
||||
|
||||
Reference in New Issue
Block a user