#[cfg(feature = "profiling")]
mod enabled {
use std::sync::OnceLock;
pub use puffin::{GlobalProfiler, profile_function, profile_scope};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProfilingBackend {
PuffinHttp,
}
static PROFILING_SERVER: OnceLock<puffin_http::Server> = OnceLock::new();
pub fn init_profiling(backend: ProfilingBackend) {
match backend {
ProfilingBackend::PuffinHttp => {
puffin::set_scopes_on(true);
match puffin_http::Server::new("0.0.0.0:8585") {
Ok(server) => {
tracing::info!("Puffin profiler server started on http://0.0.0.0:8585");
tracing::info!(
"Connect puffin_viewer or open browser to view profiling data"
);
let _ = PROFILING_SERVER.set(server);
}
Err(e) => {
tracing::error!("Failed to start puffin server: {}", e);
}
}
}
}
}
#[inline]
pub fn new_frame() {
puffin::GlobalProfiler::lock().new_frame();
}
#[inline]
pub fn finish_frame() {
puffin::GlobalProfiler::lock().new_frame();
}
}
#[cfg(feature = "profiling")]
pub use enabled::*;
#[cfg(not(feature = "profiling"))]
mod disabled {
#[macro_export]
macro_rules! profile_function {
() => {};
($data:expr) => {};
}
#[macro_export]
macro_rules! profile_scope {
($name:expr) => {};
($name:expr, $data:expr) => {};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProfilingBackend {
PuffinHttp,
}
#[inline]
pub fn init_profiling(_backend: ProfilingBackend) {}
#[inline]
pub fn new_frame() {}
#[inline]
pub fn finish_frame() {}
pub use profile_function;
pub use profile_scope;
}
#[cfg(not(feature = "profiling"))]
pub use disabled::*;