Skip to content

Add some docs#17

Open
felixrabe wants to merge 1 commit intoglennw:masterfrom
felixrabe:patch-2
Open

Add some docs#17
felixrabe wants to merge 1 commit intoglennw:masterfrom
felixrabe:patch-2

Conversation

@felixrabe
Copy link

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

Took a few funny looks at 2-byte `[]` profiles to figure this out 😅
@azriel91
Copy link

azriel91 commented Dec 13, 2019

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants