[PERF] Runtime Telemetry Hot Path
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user