thread_profiler
thread_profiler copied to clipboard
Add some docs
Took a few funny looks at 2-byte [] profiles to figure this out 😅
@felixrabe Hiya, thank you for opening this, but for some reason I still can't get it to work:
fn main() {
thread_profiler::register_thread_with_profiler();
// Attempt 1: main thread:
{
thread_profiler::profile_scope!("Sleepy");
std::thread::sleep(std::time::Duration::from_millis(200));
}
// Attempt 2: sub thread:
let thread_handle = std::thread::spawn(|| {
thread_profiler::register_thread_with_profiler();
// scope
{
thread_profiler::profile_scope!("Sub sleepy");
std::thread::sleep(std::time::Duration::from_millis(200));
}
});
thread_handle.join().expect("Failed to join thread");
thread_profiler::write_profile("profile.json");
}
$ cargo run && cat profile.json
Compiling abc v0.1.0 (/tmp/abc)
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/abc`
[]
Figured it out, thread_profiler 0.3 does not work unless it is declared as an optional dependency:
[dependencies]
thread_profiler = { version = "0.3", optional = true }
[features]
default = ["thread_profiler"]