aclysma / profiling

Provides a very thin abstraction over instrumented profiling crates like puffin, optick, tracy, and superluminal-perf.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Valid usage with puffin

BeastLe9enD opened this issue · comments

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);
    }
}

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?

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

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

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.

@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)