trace_block

Function trace_block 

Source
pub fn trace_block<'a, S, C>(name: S, categories: C) -> SampleGuard<'a>
where S: Into<StrCow>, C: Into<CategoriesT>,
Expand description

Creates a duration sample. The sample is finalized (end_ns set) when the returned value is dropped. trace_closure may be prettier to read.

§Performance

See trace_payload for a more complete discussion.

§Arguments

  • name - A string that provides some meaningful name to this sample. Usage of static strings is encouraged for best performance to avoid copies. However, anything that can be converted into a Cow string can be passed as an argument.

  • categories - A static array of static strings that tags the samples in some way.

§Returns

A guard that when dropped will update the Sample with the timestamp & then record it.

§Examples

fn something_expensive() {
}

fn something_else_expensive() {
}

let trace_guard = xi_trace::trace_block("something_expensive", &["rpc", "request"]);
something_expensive();
std::mem::drop(trace_guard); // finalize explicitly if

{
    let _guard = xi_trace::trace_block("something_else_expensive", &["rpc", "response"]);
    something_else_expensive();
}