Skip to main content

euv_core/panic_forensics/
struct.rs

1use super::*;
2
3crate::euv_devtools_only_items! {
4    /// Internal fixed-size zero-allocation breadcrumb slot stored inside the global runtime ring buffer.
5    #[derive(Clone, Copy, Debug)]
6    pub(crate) struct InlineBreadcrumbSlot {
7        /// Monotonic event sequence number (`0` marks an empty slot).
8        pub(crate) seq: u64,
9        /// Frame index active when this event was recorded.
10        pub(crate) frame_seq: u64,
11        /// Valid UTF-8 byte length inside `kind_buf`.
12        pub(crate) kind_len: u8,
13        /// Fixed inline UTF-8 storage for the event kind label.
14        pub(crate) kind_buf: [u8; PANIC_MAX_KIND_BYTES],
15        /// Valid UTF-8 byte length inside `detail_buf`.
16        pub(crate) detail_len: u8,
17        /// Fixed inline UTF-8 storage for the event detail summary.
18        pub(crate) detail_buf: [u8; PANIC_MAX_DETAIL_BYTES],
19    }
20
21    /// Internal zero-allocation runtime context state updated on hot UI/router/frame paths.
22    #[derive(Debug)]
23    pub(crate) struct InlineRuntimeContextState {
24        /// Valid UTF-8 byte length inside `route_buf`.
25        pub(crate) route_len: usize,
26        /// Fixed inline UTF-8 storage for the active route path.
27        pub(crate) route_buf: [u8; PANIC_MAX_ROUTE_BYTES],
28        /// Valid UTF-8 byte length inside `theme_buf`.
29        pub(crate) theme_len: usize,
30        /// Fixed inline UTF-8 storage for the active theme descriptor.
31        pub(crate) theme_buf: [u8; PANIC_MAX_THEME_BYTES],
32        /// Valid UTF-8 byte length inside `overlays_buf` (comma-separated overlay names).
33        pub(crate) overlays_len: usize,
34        /// Fixed inline UTF-8 storage for active overlay identifiers.
35        pub(crate) overlays_buf: [u8; PANIC_MAX_OVERLAYS_BYTES],
36        /// Current logical viewport width in points.
37        pub(crate) viewport_width: f32,
38        /// Current logical viewport height in points.
39        pub(crate) viewport_height: f32,
40        /// Current physical display scale factor.
41        pub(crate) scale_factor: f32,
42        /// Latest rendered frame sequence number.
43        pub(crate) frame_seq: u64,
44        /// Whether the runtime is currently settled in idle state.
45        pub(crate) is_idle: bool,
46        /// Next monotonic sequence number for breadcrumb writes.
47        pub(crate) next_seq: u64,
48        /// Circular write cursor inside `breadcrumbs`.
49        pub(crate) write_cursor: usize,
50        /// Number of valid entries currently stored in `breadcrumbs`.
51        pub(crate) count: usize,
52        /// Fixed-capacity ring buffer of recent runtime events.
53        pub(crate) breadcrumbs: [InlineBreadcrumbSlot; PANIC_BREADCRUMB_RING_CAPACITY],
54    }
55}
56
57/// Owned chronological runtime event breadcrumb exported in panic forensics and event traces.
58#[derive(Clone, Data, Debug, Default, Deserialize, Eq, New, PartialEq, Serialize)]
59pub struct RuntimeEventBreadcrumb {
60    /// Monotonic breadcrumb sequence number.
61    #[get(type(copy))]
62    pub(crate) seq: u64,
63    /// Normalized event category (e.g. `"ui_event"`, `"route"`, `"overlay"`, `"idle"`).
64    pub(crate) kind: String,
65    /// Concise event payload summary.
66    pub(crate) detail: String,
67    /// Frame sequence index active when this breadcrumb was recorded.
68    #[get(type(copy))]
69    pub(crate) frame_seq: u64,
70}
71
72/// Live runtime scene, viewport, theme, overlay, and recent event context captured alongside a panic.
73#[derive(Clone, Data, Debug, Default, Deserialize, PartialEq, Serialize)]
74pub struct PanicRuntimeContext {
75    /// Active application route string.
76    pub(crate) active_route: String,
77    /// Logical viewport width in pixels.
78    #[get(type(copy))]
79    pub(crate) viewport_width: f32,
80    /// Logical viewport height in pixels.
81    #[get(type(copy))]
82    pub(crate) viewport_height: f32,
83    /// Physical display scale factor.
84    #[get(type(copy))]
85    pub(crate) scale_factor: f32,
86    /// Active theme descriptor (scheme and Light/Dark mode).
87    pub(crate) theme: String,
88    /// Active top-layer overlay identifiers.
89    pub(crate) active_overlays: Vec<String>,
90    /// Latest rendered frame index.
91    #[get(type(copy))]
92    pub(crate) frame_seq: u64,
93    /// Whether the runtime was settled in idle mode at capture time.
94    #[get(type(copy))]
95    pub(crate) is_idle: bool,
96    /// Bounded chronological ring of recent runtime events leading up to capture.
97    pub(crate) recent_breadcrumbs: Vec<RuntimeEventBreadcrumb>,
98}
99
100/// Complete structured panic forensics record preserving forced backtrace, error payload, source site, and runtime context.
101#[derive(Clone, Data, Debug, Default, Deserialize, PartialEq, Serialize)]
102pub struct PanicForensicsRecord {
103    /// UTC timestamp in RFC3339 format when the panic occurred.
104    pub(crate) timestamp_utc: String,
105    /// Exact panic error payload message.
106    pub(crate) message: String,
107    /// Source file path reported by `PanicHookInfo::location`.
108    pub(crate) location_file: String,
109    /// One-based source line number (`0` when unavailable).
110    #[get(type(copy))]
111    pub(crate) location_line: u32,
112    /// One-based source column number (`0` when unavailable).
113    #[get(type(copy))]
114    pub(crate) location_col: u32,
115    /// Thread name where the panic originated.
116    pub(crate) thread_name: String,
117    /// Parsed non-empty stack frames extracted from the forced backtrace.
118    pub(crate) backtrace_frames: Vec<String>,
119    /// Full verbatim forced backtrace string.
120    pub(crate) raw_backtrace: String,
121    /// Snapshot of live runtime route, viewport, theme, overlays, and event breadcrumbs.
122    pub(crate) runtime_context: PanicRuntimeContext,
123}