macro_rules! profile_begin_session {
($name:expr, $filepath:expr) => { ... };
}Expand description
§Timetrace
A lightweight Rust profiling library inspired by Hazel and Tracy-style instrumentation.
Generates JSON traces compatible with Chrome Tracing and Perfetto. and supports tracy.
§Features
- RAII profiling (scope-based)
- Function attribute macro:
#[profile_function] - Session management:
#[profile_session] - Frame indexing in trace (
args.frame) - Minimal overhead
- Thread-aware (thread id included)
§Example
use timetrace::{profile_function, profile_session};
#[profile_session("Example", "trace.json")]
fn main() {
work();
}
#[profile_function]
fn work() {
let mut sum = 0.0;
for i in 0..1_000_000 {
sum += (i as f64).cos();
}
println!("{sum}");
}§Run
cargo run -p timetrace_example§View Trace
Open in:
- https://ui.perfetto.dev
- Only in Google Chrome: chrome://tracing
§Output Example
{
"name": "work",
"cat": "function",
"ph": "X",
"ts": 123456789,
"dur": 23000,
"pid": 0,
"tid": 12345,
"args": {
"frame": 0
}
}(Actual output is written as a single line JSON)
§Cargo Features
Enable macros:
timetrace = { path = "...", features = ["json"] }(macros are enabled by default)
Disable macros:
timetrace = { path = "...", features = ["json"], default-features = false }