pub mod userdata_dir;
pub use userdata_dir::userdata_dir;
#[macro_export]
macro_rules! dev_panic {
($msg:expr) => {
if cfg!(any(debug_assertions, test)) {
panic!("{}", $msg);
} else {
tracing::error!("{}", $msg);
}
};
($msg:expr, or return $result:expr) => {
if cfg!(any(debug_assertions, test)) {
panic!("{}", $msg);
} else {
tracing::warn!("{}", $msg);
return $result;
}
};
}
#[cfg(feature = "tracy")]
pub use profiling::tracy_client;
pub const TRACY_ENABLED: bool = cfg!(feature = "tracy");
#[cfg(not(feature = "tracy"))]
#[macro_export]
macro_rules! plot {
($name:expr, $value:expr) => {
let _: f64 = $value;
};
}
#[cfg(feature = "tracy")]
pub use tracy_client::plot;
#[cfg(not(feature = "tracy"))]
#[macro_export]
macro_rules! span {
($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => {
let span = tracing::span!(tracing::Level::$level, $name, $($fields)*);
let $guard_name = span.enter();
};
($guard_name:tt, $level:ident, $name:expr) => {
let span = tracing::span!(tracing::Level::$level, $name);
let $guard_name = span.enter();
};
($guard_name:tt, $name:expr) => {
let span = tracing::span!(tracing::Level::TRACE, $name);
let $guard_name = span.enter();
};
($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => {
$crate::span!($guard_name, $no_tracy_name);
};
}
#[cfg(feature = "tracy")]
#[macro_export]
macro_rules! span {
($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => {
let span = tracing::span!(tracing::Level::$level, $name, $($fields)*);
let $guard_name = span.enter();
};
($guard_name:tt, $level:ident, $name:expr) => {
let span = tracing::span!(tracing::Level::$level, $name);
let $guard_name = span.enter();
};
($guard_name:tt, $name:expr) => {
$crate::prof_span_alloc!($guard_name, $name);
};
($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => {
$crate::span!($guard_name, $tracy_name);
};
}
#[cfg(not(feature = "tracy"))]
pub struct ProfSpan;
#[cfg(not(feature = "tracy"))]
impl Drop for ProfSpan {
fn drop(&mut self) {}
}
#[cfg(feature = "tracy")]
pub struct ProfSpan(pub tracy_client::Span);
#[cfg(not(feature = "tracy"))]
#[macro_export]
macro_rules! prof_span {
($guard_name:tt, $name:expr) => {
let $guard_name = $crate::ProfSpan;
};
($name:expr) => {
$crate::prof_span!(_guard, $name);
};
}
#[cfg(feature = "tracy")]
#[macro_export]
macro_rules! prof_span {
($guard_name:tt, $name:expr) => {
let $guard_name = $crate::ProfSpan(
$crate::tracy_client::span!($name, 0),
);
};
($name:expr) => {
$crate::prof_span!(_guard, $name);
};
}
#[cfg(not(feature = "tracy"))]
#[macro_export]
macro_rules! prof_span_alloc {
($guard_name:tt, $name:expr) => {
let $guard_name = $crate::ProfSpan;
};
($name:expr) => {
$crate::prof_span!(_guard, $name);
};
}
#[cfg(feature = "tracy")]
#[macro_export]
macro_rules! prof_span_alloc {
($guard_name:tt, $name:expr) => {
let $guard_name = $crate::ProfSpan({
struct S;
let type_name = core::any::type_name::<S>();
let function_name = &type_name[..type_name.len() - 3];
$crate::tracy_client::Client::running()
.expect("prof_span_alloc! without a running tracy_client::Client")
.span_alloc(Some($name), function_name, file!(), line!(), 0)
});
};
($name:expr) => {
$crate::prof_span!(_guard, $name);
};
}