Skip to content

Commit

Permalink
feat(spdk): allow SPDK tracing
Browse files Browse the repository at this point in the history
Init SPDK tracing when `MayastorEnvironment.num_enties` is set to a
positive integer. This can be helpfull when developing new features.
Traces can be found in `/dev/shm` and have the pid or if not negative
the `MayastorEnvironment.shm_id` as a suffix.

Further information about traces and how to read the captured traces can
be found here: https://spdk.io/doc/nvmf_tgt_tracepoints.html

Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
  • Loading branch information
MaisenbacherD committed Nov 22, 2024
1 parent ec5c904 commit 1dac4b4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions io-engine/src/core/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::<bool>();

Expand Down

0 comments on commit 1dac4b4

Please sign in to comment.