Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show current thread id and process id #29

Closed
vini-fda opened this issue Jun 11, 2023 · 0 comments
Closed

Show current thread id and process id #29

vini-fda opened this issue Jun 11, 2023 · 0 comments

Comments

@vini-fda
Copy link
Contributor

vini-fda commented Jun 11, 2023

Currently, PID and TID are hardcoded to show only the constant "1":

fn write_results_recursive(file: &mut File, result: &GpuTimerScopeResult, last: bool) -> std::io::Result<()> {
    write!(
        file,
        r#"{{ "pid":1, "tid":1, "ts":{}, "dur":{}, "ph":"X", "name":"{}" }}{}"#,
        result.time.start * 1000.0 * 1000.0,
        (result.time.end - result.time.start) * 1000.0 * 1000.0,
        result.label,
        if last && result.nested_scopes.is_empty() { "\n" } else { ",\n" }
    )?;
    if result.nested_scopes.is_empty() {
        return Ok(());
    }

    for child in result.nested_scopes.iter().take(result.nested_scopes.len() - 1) {
        write_results_recursive(file, child, false)?;
    }
    write_results_recursive(file, result.nested_scopes.last().unwrap(), last)?;

    Ok(())
    // { "pid":1, "tid":1, "ts":546867, "dur":121564, "ph":"X", "name":"DoThings"
}

They should be changed to output the proper process and thread id.

Suggestion: use std::process::id() for the PID and std::thread::current().id() for the TID. The only problem is that the ThreadId type in the standard library cannot be trivially converted to a primitive type (int/uint/usize), without using any hacks. Also, ThreadIds are under the control of Rust’s standard library and there may not be any relationship between ThreadId and the underlying platform’s notion of a thread identifier (see the official docs). There's a proposal for stabilizing a u64 conversion, though (see this tracking issue)

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

No branches or pull requests

2 participants