aclysma / profiling

Provides a very thin abstraction over instrumented profiling crates like puffin, optick, tracy, and superluminal-perf.
Apache License 2.0
324 stars 41 forks source link

Valid usage with puffin #31

Closed BeastLe9enD closed 2 years ago

BeastLe9enD commented 2 years ago

Hey, I have some questions about the valid usage of profiling: I start a puffin_http server and after that I profile a scope that takes 3 milliseconds every frame. If I profile the scope directly over puffin, everything works. If I use profiling::scope!("main_loop") and profiling::finish_frame!(), nothing works. Is this a problem because the profiling macros expand to $crate::puffin instead of ::puffin? If this is the problem, how can I use puffin_http with profiling?

use std::time::Duration;

fn sleep_for(x: u64) {
    std::thread::sleep(Duration::from_millis(x));
}

fn start_puffin() -> puffin_http::Server {
    let addr = format!("0.0.0.0:{}", puffin_http::DEFAULT_PORT);
    let server = puffin_http::Server::new(&addr).unwrap();
    puffin::set_scopes_on(true);
    server
}

fn main() {
    let _server = start_puffin();

    loop {
        profiling::scope!("main_loop"); //THIS DOES NOT WORK
        profiling::finish_frame!();

        //puffin::profile_scope!("main_loop"); //THIS WORKS
        //puffin::GlobalProfiler::lock().new_frame();

        println!("just a random println");

        sleep_for(3);
    }
}
aclysma commented 2 years ago

Usually when puffin mysteriously doesn’t work, it’s because profiling and the project being profiled are using different versions of puffin. Could you use cargo tree to double check that you only have one version of puffin in your dependencies?

BeastLe9enD commented 2 years ago

Oh ok, I got it working with 1.0.4, now the puffin versions match and it works :) thanks!

cybersoulK commented 10 months ago

i got this issue too. took a while to find this solution. latest versions of both http_puffin and profiling crates

aclysma commented 10 months ago

Tip: When a profiling feature is turned on, profiling exposes the crates for that feature publicly. So you can do profiling::puffin::... and you will be sure to get exactly the same version of puffin as profiling is pulling in, and compile errors if profiling is turned off but you're still referencing it in any way.

cybersoulK commented 8 months ago

@aclysma this is what i do

let _server = puffin_http::Server::new(&server_addr).unwrap();
profiling::puffin::set_scopes_on(true);

the issue is with puffin_http, it just doesn't work at all if it's mismatched (but everything still compiles and no errors are seen)