EmbarkStudios/puffin

Profile unit tests

Opened this issue · 1 comments

I want to use puffin to profile my tests but am having problems getting the viewer to catch the single frame it produces. It might be related to #85. I've had it somewhat working but that was a few versions of puffin ago.

My tests looks like this right now and I would be happy if something similar worked:

#[test]
fn test_ik_solver_neutral() -> hotham::anyhow::Result<()> {
    let _ = start_puffin_server();
    puffin::profile_function!();
    test_ik_solver(
        include_str!("../../test_data/inverse_kinematics_snapshot_2023-04-12_22.23.47.json"),
        None,
    )
}

The function start_puffin_server is something I wrote to create a puffin_http::Server and keep it alive until the test is done. It calls puffin::GlobalProfiler::lock().new_frame(); when created and dropped. I would like to use something like puffin::profile_unit_test!(); instead. Writing to disk is an option but I would prefer if I can keep the viewer running and update automatically as I change the code and run the test again.

We could add a helper to puffin_http for this, including the puffin_http::profile_unit_test macro.

Something similar to this: https://github.com/rerun-io/rerun/blob/main/crates/re_tracing/src/server.rs