trace_closure

Function trace_closure 

Source
pub fn trace_closure<S, C, F, R>(name: S, categories: C, closure: F) -> R
where S: Into<StrCow>, C: Into<CategoriesT>, F: FnOnce() -> R,
Expand description

Creates a duration sample that measures how long the closure took to execute.

§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

The result of the closure.

§Examples

fn something_expensive() -> u32 {
    0
}

fn something_else_expensive(value: u32) {
}

let result = xi_trace::trace_closure("something_expensive", &["rpc", "request"], || {
    something_expensive()
});
xi_trace::trace_closure("something_else_expensive", &["rpc", "response"], || {
    something_else_expensive(result);
});