Skip to main content

telepath_wire/
metrics.rs

1use postcard_schema::Schema;
2use serde::{Deserialize, Serialize};
3
4/// Per-direction framing metrics accumulated since the last snapshot reset.
5///
6/// Returned by CmdID [`super::CMD_ID_METRICS`] (`0xFFFE`). The target
7/// atomically resets all counters when it replies.
8///
9/// Cycle counts are DWT cycle counter deltas (Cortex-M4F @ firmware clock
10/// frequency). Convert to wall-clock duration by dividing by the CPU
11/// frequency in Hz.
12#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, Schema)]
13pub struct MetricsSnapshot {
14    /// Total DWT cycles spent in `rzcobs_encode` (upstream, target→host).
15    pub encode_cycles: u64,
16    /// Total DWT cycles spent in `rzcobs_decode` (downstream, host→target).
17    pub decode_cycles: u64,
18    /// Total payload bytes input to `rzcobs_encode` (pre-framing size).
19    pub encoded_bytes: u32,
20    /// Total payload bytes output by `rzcobs_decode` (post-unframe size).
21    pub decoded_bytes: u32,
22    /// Number of complete request/response round trips counted.
23    pub sample_count: u32,
24}