[PERF] Runtime Telemetry Hot Path

This commit is contained in:
2026-04-10 08:59:02 +01:00
parent 5e80ea46b8
commit 63892dcfb9
16 changed files with 537 additions and 141 deletions
@@ -5,11 +5,17 @@ pub struct LogService {
events: VecDeque<LogEvent>,
capacity: usize,
next_seq: u64,
pub logs_count: u32,
}
impl LogService {
pub fn new(capacity: usize) -> Self {
Self { events: VecDeque::with_capacity(capacity), capacity, next_seq: 0 }
Self {
events: VecDeque::with_capacity(capacity),
capacity,
next_seq: 0,
logs_count: 0,
}
}
pub fn log(
@@ -34,6 +40,11 @@ impl LogService {
msg,
});
self.next_seq += 1;
self.logs_count += 1;
}
pub fn reset_count(&mut self) {
self.logs_count = 0;
}
pub fn get_recent(&self, n: usize) -> Vec<LogEvent> {
+92 -2
View File
@@ -20,6 +20,13 @@ pub struct TelemetryFrame {
pub audio_used_bytes: usize,
pub audio_inflight_bytes: usize,
pub audio_slots_occupied: u32,
// RAM (Heap)
pub heap_used_bytes: usize,
pub heap_max_bytes: usize,
// Log Pressure
pub logs_count: u32,
}
#[derive(Debug, Clone, Copy, Default)]
@@ -28,6 +35,10 @@ pub struct CertificationConfig {
pub cycles_budget_per_frame: Option<u64>,
pub max_syscalls_per_frame: Option<u32>,
pub max_host_cpu_us_per_frame: Option<u64>,
pub max_gfx_bytes: Option<usize>,
pub max_audio_bytes: Option<usize>,
pub max_heap_bytes: Option<usize>,
pub max_logs_per_frame: Option<u32>,
}
pub struct Certifier {
@@ -51,6 +62,7 @@ impl Certifier {
let mut violations = 0;
// 1. Cycles
if let Some(budget) = self.config.cycles_budget_per_frame
&& telemetry.cycles_used > budget
{
@@ -68,6 +80,7 @@ impl Certifier {
violations += 1;
}
// 2. Syscalls
if let Some(limit) = self.config.max_syscalls_per_frame
&& telemetry.syscalls > limit
{
@@ -85,6 +98,7 @@ impl Certifier {
violations += 1;
}
// 3. CPU Time
if let Some(limit) = self.config.max_host_cpu_us_per_frame
&& telemetry.host_cpu_time_us > limit
{
@@ -102,6 +116,78 @@ impl Certifier {
violations += 1;
}
// 4. GFX Memory
if let Some(limit) = self.config.max_gfx_bytes
&& telemetry.gfx_used_bytes > limit
{
log_service.log(
ts_ms,
telemetry.frame_index,
LogLevel::Warn,
LogSource::Pos,
0xCA04,
format!(
"Cert: GFX bank exceeded memory limit ({} > {})",
telemetry.gfx_used_bytes, limit
),
);
violations += 1;
}
// 5. Audio Memory
if let Some(limit) = self.config.max_audio_bytes
&& telemetry.audio_used_bytes > limit
{
log_service.log(
ts_ms,
telemetry.frame_index,
LogLevel::Warn,
LogSource::Pos,
0xCA05,
format!(
"Cert: Audio bank exceeded memory limit ({} > {})",
telemetry.audio_used_bytes, limit
),
);
violations += 1;
}
// 6. Heap Memory
if let Some(limit) = self.config.max_heap_bytes
&& telemetry.heap_used_bytes > limit
{
log_service.log(
ts_ms,
telemetry.frame_index,
LogLevel::Warn,
LogSource::Pos,
0xCA06,
format!(
"Cert: Heap memory exceeded limit ({} > {})",
telemetry.heap_used_bytes, limit
),
);
violations += 1;
}
// 7. Log Pressure
if let Some(limit) = self.config.max_logs_per_frame
&& telemetry.logs_count > limit
{
log_service.log(
ts_ms,
telemetry.frame_index,
LogLevel::Warn,
LogSource::Pos,
0xCA07,
format!(
"Cert: Log pressure exceeded limit ({} > {})",
telemetry.logs_count, limit
),
);
violations += 1;
}
violations
}
}
@@ -118,6 +204,8 @@ mod tests {
cycles_budget_per_frame: Some(100),
max_syscalls_per_frame: Some(5),
max_host_cpu_us_per_frame: Some(1000),
max_gfx_bytes: Some(1024),
..Default::default()
};
let cert = Certifier::new(config);
let mut ls = LogService::new(10);
@@ -126,13 +214,15 @@ mod tests {
tel.cycles_used = 150;
tel.syscalls = 10;
tel.host_cpu_time_us = 500;
tel.gfx_used_bytes = 2048;
let violations = cert.evaluate(&tel, &mut ls, 1000);
assert_eq!(violations, 2);
assert_eq!(violations, 3);
let logs = ls.get_recent(10);
assert_eq!(logs.len(), 2);
assert_eq!(logs.len(), 3);
assert!(logs[0].msg.contains("cycles_used"));
assert!(logs[1].msg.contains("syscalls"));
assert!(logs[2].msg.contains("GFX bank"));
}
}