Skip to main content

palladium_runtime/
introspection.rs

1use palladium_actor::ActorPath;
2
3// ── ActorState ────────────────────────────────────────────────────────────────
4
5/// Observed lifecycle state of an actor at snapshot time.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum ActorState {
8    /// Actor task is running and its mailbox is registered.
9    Running,
10    /// Actor task has exited (completed, stopped, or crashed).
11    Stopped,
12}
13
14// ── ActorInfo ─────────────────────────────────────────────────────────────────
15
16/// Point-in-time snapshot of a single actor's observable state.
17#[derive(Debug, Clone)]
18pub struct ActorInfo {
19    pub path: ActorPath,
20    pub state: ActorState,
21    /// Core index where this actor lives (always `0` for single-core engine).
22    pub core_id: usize,
23    /// Number of messages currently queued in the mailbox.
24    pub mailbox_depth: usize,
25    /// Maximum mailbox capacity (messages).
26    pub mailbox_capacity: usize,
27    /// Total times this actor path has been restarted by its supervisor.
28    pub restart_count: u32,
29    /// Total `on_message` calls that completed without error.
30    pub message_count: u64,
31    /// Total wall-clock time spent executing lifecycle hooks in nanoseconds.
32    pub total_compute_time_ns: u64,
33}
34
35// ── EngineSnapshot ────────────────────────────────────────────────────────────
36
37/// System-level snapshot returned by `Engine::snapshot()`.
38#[derive(Debug, Clone)]
39pub struct EngineSnapshot {
40    pub num_cores: usize,
41    pub uptime_secs: u64,
42    pub actors: Vec<ActorInfo>,
43}
44
45// ── ActorQuery ────────────────────────────────────────────────────────────────
46
47/// Filter for actor list / info queries.
48#[derive(Debug, Default, Clone)]
49pub struct ActorQuery {
50    /// Only include actors whose path starts with this prefix.
51    pub path_prefix: Option<String>,
52    /// Only include actors in this state.
53    pub state: Option<ActorState>,
54}
55
56impl ActorQuery {
57    pub fn matches(&self, info: &ActorInfo) -> bool {
58        if let Some(ref prefix) = self.path_prefix {
59            if !info.path.as_str().starts_with(prefix.as_str()) {
60                return false;
61            }
62        }
63        if let Some(state) = self.state {
64            if info.state != state {
65                return false;
66            }
67        }
68        true
69    }
70}