diff --git a/io-engine/src/core/env.rs b/io-engine/src/core/env.rs index e2aaa55d0..f87119a90 100644 --- a/io-engine/src/core/env.rs +++ b/io-engine/src/core/env.rs @@ -44,6 +44,9 @@ use spdk_rs::{ spdk_thread_lib_fini, spdk_thread_send_critical_msg, spdk_trace_cleanup, + spdk_trace_create_tpoint_group_mask, + spdk_trace_init, + spdk_trace_set_tpoints, SPDK_LOG_DEBUG, SPDK_LOG_INFO, SPDK_RPC_RUNTIME, @@ -1020,6 +1023,40 @@ impl MayastorEnvironment { None } + fn init_spdk_tracing(&self) { + const MAX_GROUP_IDS: u32 = 16; + const NUM_THREADS: u32 = 1; + let cshm_name = if self.shm_id >= 0 { + CString::new( + format!("/{}_trace.{}", self.name, self.shm_id).as_str(), + ) + .unwrap() + } else { + CString::new( + format!("/{}_trace.pid{}", self.name, std::process::id()) + .as_str(), + ) + .unwrap() + }; + unsafe { + if spdk_trace_init(cshm_name.as_ptr(), self.num_entries, NUM_THREADS) != 0 { + error!("SPDK tracing init error"); + } + } + let tpoint_group_name = CString::new("all").unwrap(); + let tpoint_group_mask = unsafe { + spdk_trace_create_tpoint_group_mask(tpoint_group_name.as_ptr()) + }; + + for group_id in 0..MAX_GROUP_IDS { + if (tpoint_group_mask & (1 << group_id) as u64) > 0 { + unsafe { + spdk_trace_set_tpoints(group_id, u64::MAX); + } + } + } + } + /// initialize the core, call this before all else pub fn init(mut self) -> Self { // setup the logger as soon as possible @@ -1088,6 +1125,11 @@ impl MayastorEnvironment { // ensure we are within the context of a spdk thread from here Mthread::primary().set_current(); + // To enable SPDK tracing set self.num_entries (eg. to 32768). + if self.num_entries > 0 { + self.init_spdk_tracing(); + } + Reactor::block_on(async { let (sender, receiver) = oneshot::channel::();