#[doc(hidden)]
pub use cfg_if::cfg_if;
pub use hotpath_macros::{future_fn, main, measure, measure_all, skip};
use std::sync::OnceLock;
use crate::instant::Instant;
pub(crate) static START_TIME: OnceLock<Instant> = OnceLock::new();
pub mod channels;
pub mod cpu_baseline;
pub mod data_flow;
pub mod debug;
pub mod futures;
pub mod streams;
#[cfg(feature = "threads")]
pub mod threads;
#[cfg(feature = "tokio")]
pub mod tokio_runtime;
pub mod functions;
pub use channels::{InstrumentChannel, InstrumentChannelLog};
pub use futures::{InstrumentFuture, InstrumentFutureLog};
pub use streams::{InstrumentStream, InstrumentStreamLog};
pub mod hotpath_guard;
pub(crate) mod report;
pub use functions::{
measure_async, measure_async_future, measure_async_future_log, measure_async_log,
measure_sync_log, MeasurementGuardAsync, MeasurementGuardSync,
};
pub use hotpath_guard::{HotpathGuard, HotpathGuardBuilder};
cfg_if::cfg_if! {
if #[cfg(feature = "hotpath-alloc")] {
#[global_allocator]
static GLOBAL: functions::alloc::allocator::CountingAllocator = functions::alloc::allocator::CountingAllocator {};
}
}
#[must_use = "guard is dropped immediately without suspending tracking"]
pub(crate) struct SuspendAllocTracking {
#[cfg(feature = "hotpath-alloc")]
previous_enabled: bool,
}
impl SuspendAllocTracking {
#[inline]
pub(crate) fn new() -> Self {
#[cfg(feature = "hotpath-alloc")]
{
let previous_enabled = functions::alloc::core::suspend_alloc_tracking();
Self { previous_enabled }
}
#[cfg(not(feature = "hotpath-alloc"))]
{
Self {}
}
}
}
impl Drop for SuspendAllocTracking {
#[inline]
fn drop(&mut self) {
#[cfg(feature = "hotpath-alloc")]
functions::alloc::core::resume_alloc_tracking(self.previous_enabled);
}
}
#[macro_export]
macro_rules! measure_block {
($label:expr, $expr:expr) => {{
let _guard = hotpath::functions::build_measurement_guard_sync($label, false);
$expr
}};
}
#[macro_export]
macro_rules! dbg {
($val:expr $(,)?) => {{
static DBG_ID: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
let id = *DBG_ID.get_or_init(|| {
$crate::debug::DEBUG_ID_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
});
const DBG_LOC: &'static str = concat!(file!(), ":", line!());
const DBG_EXPR: &'static str = stringify!($val);
match $val {
tmp => {
$crate::debug::dbg::log_dbg(id, DBG_LOC, DBG_EXPR, &tmp);
tmp
}
}
}};
($($val:expr),+ $(,)?) => {
($($crate::dbg!($val)),+,)
};
}
#[macro_export]
macro_rules! val {
($key:expr) => {{
const VAL_LOC: &'static str = concat!(file!(), ":", line!());
$crate::debug::val::ValHandle::new($key, VAL_LOC)
}};
}
#[macro_export]
macro_rules! gauge {
($key:expr) => {{
const GAUGE_LOC: &'static str = concat!(file!(), ":", line!());
$crate::debug::gauge::GaugeHandle::new($key, GAUGE_LOC)
}};
}
#[macro_export]
macro_rules! tokio_runtime {
() => {
hotpath::tokio_runtime::init_runtime_monitoring(&tokio::runtime::Handle::current());
};
($handle:expr) => {
hotpath::tokio_runtime::init_runtime_monitoring($handle);
};
}
#[cfg(test)]
mod tests {
use crate::lib_on::HotpathGuard;
fn is_send_sync<T: Send + Sync>() {}
#[test]
fn test_hotpath_is_send_sync() {
is_send_sync::<HotpathGuard>();
}
}