1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//! Consolidated diagnostics snapshots for feeds and the runtime.
//!
//! The library exposes several independent observability surfaces:
//! `FeedMetrics`, `QueueTelemetry`, `DecodeStatus`, health events,
//! `BatchMetrics`, and per-frame `Provenance`. Each serves a specific
//! purpose, but downstream systems that want a comprehensive view of
//! runtime state must stitch them together manually.
//!
//! This module provides **composite snapshot types** that unify the most
//! commonly needed diagnostics into single, coherent reads:
//!
//! - [`FeedDiagnostics`] — everything about one feed in one call.
//! - [`RuntimeDiagnostics`] — every feed, batch coordinator, and output
//! channel status in one call.
//!
//! # Recommended consumption pattern
//!
//! ```text
//! ┌──────────────────┐
//! │ Dashboard / OPS │
//! └──────┬───────────┘
//! │ poll every 1–5 s
//! ▼
//! runtime.diagnostics()
//! │
//! ├─▶ RuntimeDiagnostics
//! │ .uptime
//! │ .feed_count / .max_feeds
//! │ .output_lag (in_lag, pending_lost)
//! │ .batches: Vec<BatchDiagnostics>
//! │ .processor_id, .metrics
//! │ .feeds: Vec<FeedDiagnostics> (sorted by FeedId)
//! │ .alive / .paused / .uptime
//! │ .metrics (frames counters, restarts)
//! │ .queues (source/sink depth + capacity)
//! │ .decode (hw/sw codec status)
//! │ .view (stability score, context status)
//! │ .batch_processor_id (links to .batches)
//! │
//! │ (complement with event-driven streams:)
//! │
//! runtime.health_subscribe() ← state transitions, errors, degradation
//! runtime.output_subscribe() ← per-frame provenance, admission, detections
//! ```
//!
//! The snapshot approach is intentionally poll-oriented. Snapshots are
//! cheap (atomic loads plus small allocations for the `Vec` and decode
//! detail `String`), idempotent, and do not perturb the pipeline.
//! Event-driven details (individual health events, per-frame provenance)
//! remain on their respective broadcast channels.
use Duration;
use ;
use FeedMetrics;
use crateBatchMetrics;
use crate;
// ---------------------------------------------------------------------------
// Per-feed diagnostics
// ---------------------------------------------------------------------------
/// Consolidated per-feed diagnostics snapshot.
///
/// Combines lifecycle state, throughput metrics, queue depths, decode
/// status, and view-system health into a single best-effort coherent
/// snapshot. Each field is read from independent atomics/mutexes, so
/// the snapshot is approximately — not transactionally — consistent.
///
/// Obtained via [`FeedHandle::diagnostics()`](crate::FeedHandle::diagnostics).
/// Summary of the camera view-system's current health.
///
/// Fixed cameras report `status: ViewStatus::Stable` and `stability_score: 1.0`.
/// Observed (PTZ/moving) cameras reflect the live epoch policy output.
/// High-level camera view health.
///
/// This is a diagnostic summary of the underlying [`ContextValidity`]
/// (from `nv-view`) — intentionally simpler to avoid forcing downstream
/// consumers to depend on the view crate.
///
/// [`ContextValidity`]: nv_view::ContextValidity
// ---------------------------------------------------------------------------
// Runtime-wide diagnostics
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Batch diagnostics
// ---------------------------------------------------------------------------
/// Diagnostics snapshot for a batch coordinator.
///
/// One entry per coordinator created via `Runtime::create_batch()`.
/// Included in [`RuntimeDiagnostics::batches`].
// ---------------------------------------------------------------------------
// Output lag diagnostics
// ---------------------------------------------------------------------------
/// Snapshot of the output broadcast channel's saturation state.
///
/// Obtained from the runtime's internal sentinel-based lag detector.
/// A non-zero `pending_lost` during `in_lag == true` indicates the
/// channel is saturated and subscribers may be losing messages.
// ---------------------------------------------------------------------------
// Runtime-wide diagnostics
// ---------------------------------------------------------------------------
/// Consolidated runtime-wide diagnostics snapshot.
///
/// Provides a one-call overview of every feed, batch coordinator, and
/// output channel health. Fields are read from independent sources, so
/// the snapshot is best-effort coherent — not transactionally consistent.
///
/// Obtained via [`Runtime::diagnostics()`](crate::Runtime::diagnostics)
/// or [`RuntimeHandle::diagnostics()`](crate::RuntimeHandle::diagnostics).