ESPectre SDK 2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
Loading...
Searching...
No Matches
runtime_diagnostics.h
Go to the documentation of this file.
1/*
2 * ESPectre - Runtime Diagnostics
3 *
4 * Runtime diagnostics snapshot helpers.
5 *
6 * Author: Francesco Pace <francesco.pace@gmail.com>
7 * SPDX-License-Identifier: GPL-3.0-only
8 * Commercial licensing available under separate agreement; see LICENSING.md.
9 */
10#pragma once
11
12#include <cstdint>
13#include <functional>
14
15#include "runtime_interface.h"
16#include "runtime_snapshot.h"
17
18namespace espectre {
19
20/**
21 * Rate and link diagnostics derived from cumulative runtime counters.
22 *
23 * Produced by `RuntimeDiagnosticsSampler`, never by the runtime directly: the
24 * runtime only exposes monotonic totals, and the rates here are what those
25 * totals moved by between two periodic sensing updates.
26 *
27 * A zero rate means the counter did not move over the interval, and the first
28 * sample after `RuntimeDiagnosticsSampler::reset()` reports zero rates because
29 * it establishes the baseline. The link fields are carried through either way.
30 */
32 /** Traffic packets per second sent or observed by the active traffic source. */
33 float traffic_tx_pps{0.0f};
34 /** Raw CSI callbacks per second, before any capture-level validation. */
35 float csi_callback_pps{0.0f};
36 /** CSI packets per second accepted by capture validation. */
37 float csi_accepted_pps{0.0f};
38 /** CSI packets per second admitted to the detector's temporal grid. */
39 float csi_admitted_pps{0.0f};
40 /** CSI packets per second rejected by capture-level validation. */
41 float csi_filtered_pps{0.0f};
42 /** Missing detector slots per second. */
44 /** Same-slot excess drops per second. */
45 float csi_excess_pps{0.0f};
46 /** Stale temporal drops per second. */
47 float csi_stale_pps{0.0f};
48 /** Out-of-order temporal drops per second. */
50 /** Valid-slot occupancy of the active temporal detector window. */
52 /** RSSI of the current association. `INT8_MIN` when unavailable. */
53 int8_t wifi_rssi_dbm{INT8_MIN};
54 /** Primary channel of the current association. Zero when unavailable. */
55 uint8_t wifi_channel{0U};
56};
57
58/**
59 * Converts cumulative diagnostics into rates over the interval between reads.
60 *
61 * Call `reset()` when the owning frontend starts. Counter resets are treated
62 * as a new epoch, so rearming a traffic source cannot underflow a rate.
63 *
64 * @code
65 * // once, at frontend startup:
66 * sampler.reset(controller.diagnostics(), now_ms);
67 * // whenever the owning frontend already produces a sensing update:
68 * latest = sampler.sample(controller.diagnostics(), now_ms);
69 * @endcode
70 *
71 * @par Threading
72 * Not synchronized, and it holds the previous read. Sample it from the task
73 * that owns the runtime.
74 */
76 public:
77 /**
78 * Establish the baseline the next `sample()` measures against.
79 *
80 * @param snapshot Current cumulative counters.
81 * @param now_ms Monotonic frontend clock, in milliseconds.
82 */
83 void reset(const RuntimeDiagnosticsSnapshot &snapshot, uint32_t now_ms);
84 /**
85 * Derive rates since the previous read and adopt this one as the baseline.
86 *
87 * The caller owns the window. Shipped frontends invoke this from their
88 * existing periodic sensing update, so diagnostics do not add a timer.
89 *
90 * @param snapshot Current cumulative counters.
91 * @param now_ms Monotonic frontend clock, in milliseconds.
92 * @return Rates over the elapsed interval. The link fields are always
93 * carried through; the rates are zero when there is no baseline yet
94 * or no time has elapsed.
95 */
97
98 private:
100 uint32_t previous_ms_{0U};
101 bool baseline_ready_{false};
102};
103
104using runtime_diagnostic_visitor_t = std::function<void(const char *key, const char *value)>;
105
107 const RuntimeSnapshot &snapshot,
109
110} // namespace espectre
Converts cumulative diagnostics into rates over the interval between reads.
void reset(const RuntimeDiagnosticsSnapshot &snapshot, uint32_t now_ms)
Establish the baseline the next sample() measures against.
RuntimeDiagnosticsSample sample(const RuntimeDiagnosticsSnapshot &snapshot, uint32_t now_ms)
Derive rates since the previous read and adopt this one as the baseline.
void visit_runtime_diagnostics(const RuntimeConfig &config, const RuntimeSnapshot &snapshot, runtime_diagnostic_visitor_t visitor)
std::function< void(const char *key, const char *value)> runtime_diagnostic_visitor_t
Runtime configuration and the backend contract behind it.
Everything the runtime needs to know before setup().
Rate and link diagnostics derived from cumulative runtime counters.
uint8_t wifi_channel
Primary channel of the current association.
float csi_accepted_pps
CSI packets per second accepted by capture validation.
float csi_stale_pps
Stale temporal drops per second.
float csi_missing_slots_pps
Missing detector slots per second.
float traffic_tx_pps
Traffic packets per second sent or observed by the active traffic source.
float csi_out_of_order_pps
Out-of-order temporal drops per second.
float csi_callback_pps
Raw CSI callbacks per second, before any capture-level validation.
float csi_admitted_pps
CSI packets per second admitted to the detector's temporal grid.
float csi_filtered_pps
CSI packets per second rejected by capture-level validation.
float csi_occupancy_ratio
Valid-slot occupancy of the active temporal detector window.
float csi_excess_pps
Same-slot excess drops per second.
int8_t wifi_rssi_dbm
RSSI of the current association.
Low-frequency counters and radio state used by optional diagnostic surfaces.
A consistent view of the sensing state at one instant.