#tracing #inject #body #annotate

call-trace

Provides a way to annotate a function to inject tracing code before and after its body

4 releases (breaking)

0.4.0 May 14, 2019
0.3.0 May 14, 2019
0.2.0 May 10, 2019
0.1.0 May 10, 2019

#3 in #annotate


Used in call-trace-tls

MIT/Apache

7KB

Example

use call_trace::{trace_with, CallContext, Trace};

struct My;

impl My {
#[inline]
#[trace_with(self)]
/// test
fn foo(&mut self) {
self.bar();
}

#[trace_with(self)]
fn bar(&mut self) {
let x = self.baz();
let y = self.baz();
println!("x + y = {}", x + y);
}

#[trace_with(self)]
fn baz(&mut self) -> i32 {
15
}
}

impl Trace for My {
fn on_pre(&mut self, ctx: &CallContext) {
println!("> {:?}", ctx);
}
fn on_post(&mut self, ctx: &CallContext) {
println!("< {:?}", ctx);
}
}

fn main() {
My.foo();
}

Output

> CallContext { file: "main.rs", line: 13, fn_name: "bar" }
> CallContext { file: "main.rs", line: 20, fn_name: "baz" }
< CallContext { file: "main.rs", line: 20, fn_name: "baz" }
> CallContext { file: "main.rs", line: 20, fn_name: "baz" }
< CallContext { file: "main.rs", line: 20, fn_name: "baz" }
x + y = 30
< CallContext { file: "main.rs", line: 13, fn_name: "bar" }
< CallContext { file: "main.rs", line: 7, fn_name: "foo" }

Dependencies

~2MB
~48K SLoC