use std::{fmt, time};
use crate::util::DbgTypeId;
use crate::{scheduler, system};
#[dynec_codegen::tracer_def(
max_tuple_len = 32,
import = crate::util::DbgTypeId,
import = crate::scheduler,
import = crate::system,
)]
pub trait Tracer: Sync {
#[dynec(log_time)]
type CycleContext;
#[dynec(log_return_now)]
fn start_cycle(&self) -> Self::CycleContext;
fn end_cycle(&self, #[dynec(log_with = ElapsedFmt)] arg: Self::CycleContext);
#[dynec(log_time)]
type PrepareEallocShardsContext;
#[dynec(log_return_now)]
fn start_prepare_ealloc_shards(&self) -> Self::PrepareEallocShardsContext;
fn end_prepare_ealloc_shards(
&self,
#[dynec(log_with = ElapsedFmt)] arg: Self::PrepareEallocShardsContext,
);
#[dynec(log_time)]
type FlushEallocContext;
#[dynec(log_return_now)]
fn start_flush_ealloc(&self, archetype: DbgTypeId) -> Self::FlushEallocContext;
fn end_flush_ealloc(
&self,
#[dynec(log_with = ElapsedFmt)] arg: Self::FlushEallocContext,
archetype: DbgTypeId,
);
fn steal_return_complete(&self, thread: Thread);
fn steal_return_pending(&self, thread: Thread);
fn mark_runnable(&self, node: scheduler::Node);
fn unmark_runnable(&self, node: scheduler::Node);
fn complete_system(&self, node: scheduler::Node, remaining: usize);
#[dynec(log_time)]
type RunSendableContext;
#[dynec(log_return_now)]
fn start_run_sendable(
&self,
thread: Thread,
node: scheduler::Node,
debug_name: &str,
#[dynec(log_skip)] system: &mut dyn system::Sendable,
) -> Self::RunSendableContext;
fn end_run_sendable(
&self,
#[dynec(log_with = ElapsedFmt)] context: Self::RunSendableContext,
thread: Thread,
node: scheduler::Node,
debug_name: &str,
#[dynec(log_skip)] system: &mut dyn system::Sendable,
);
#[dynec(log_time)]
type RunUnsendableContext;
#[dynec(log_return_now)]
fn start_run_unsendable(
&self,
thread: Thread,
node: scheduler::Node,
debug_name: &str,
#[dynec(log_skip)] system: &mut dyn system::Unsendable,
) -> Self::RunUnsendableContext;
fn end_run_unsendable(
&self,
#[dynec(log_with = ElapsedFmt)] context: Self::RunUnsendableContext,
thread: Thread,
node: scheduler::Node,
debug_name: &str,
#[dynec(log_skip)] system: &mut dyn system::Unsendable,
);
fn partition(
&self,
node: scheduler::Node,
#[dynec(log_with = PartitionFmt)] partition: &dyn system::Partition,
);
}
struct PartitionFmt<'t>(&'t dyn system::Partition);
impl<'t> fmt::Display for PartitionFmt<'t> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.describe(f) }
}
struct ElapsedFmt(time::Instant);
impl fmt::Display for ElapsedFmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self.0.elapsed()) }
}
pub struct Noop;
pub struct Aggregate<T>(
pub T,
);
pub struct Log(
pub log::Level,
);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Thread {
Main,
Worker(usize),
}