thread_profiler icon indicating copy to clipboard operation
thread_profiler copied to clipboard

Add some docs

Open felixrabe opened this issue 7 years ago • 2 comments

Took a few funny looks at 2-byte [] profiles to figure this out 😅

felixrabe avatar Aug 05 '18 20:08 felixrabe

@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`
[]

azriel91 avatar Dec 13 '19 23:12 azriel91

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"]

azriel91 avatar Dec 14 '19 00:12 azriel91