[PERF] Host Debug Overlay Isolation
This commit is contained in:
@@ -272,6 +272,16 @@ impl HostDebugger {
|
||||
tel.host_cpu_time_us,
|
||||
cert_config.max_host_cpu_us_per_frame.unwrap_or(0),
|
||||
),
|
||||
0xCA04 => (
|
||||
"max_glyph_slots_used".to_string(),
|
||||
tel.glyph_slots_used as u64,
|
||||
cert_config.max_glyph_slots_used.unwrap_or(0) as u64,
|
||||
),
|
||||
0xCA05 => (
|
||||
"max_sound_slots_used".to_string(),
|
||||
tel.sound_slots_used as u64,
|
||||
cert_config.max_sound_slots_used.unwrap_or(0) as u64,
|
||||
),
|
||||
_ => ("unknown".to_string(), 0, 0),
|
||||
};
|
||||
|
||||
@@ -302,12 +312,10 @@ impl HostDebugger {
|
||||
cycles_budget: tel.cycles_budget,
|
||||
host_cpu_time_us: tel.host_cpu_time_us,
|
||||
violations: tel.violations,
|
||||
gfx_used_bytes: tel.gfx_used_bytes,
|
||||
gfx_inflight_bytes: tel.gfx_inflight_bytes,
|
||||
gfx_slots_occupied: tel.gfx_slots_occupied,
|
||||
audio_used_bytes: tel.audio_used_bytes,
|
||||
audio_inflight_bytes: tel.audio_inflight_bytes,
|
||||
audio_slots_occupied: tel.audio_slots_occupied,
|
||||
glyph_slots_used: tel.glyph_slots_used,
|
||||
glyph_slots_total: tel.glyph_slots_total,
|
||||
sound_slots_used: tel.sound_slots_used,
|
||||
sound_slots_total: tel.sound_slots_total,
|
||||
});
|
||||
self.last_telemetry_frame = current_frame;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,30 @@ pub(crate) struct OverlaySnapshot {
|
||||
footer: Vec<OverlayMetric>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Rect {
|
||||
x: usize,
|
||||
y: usize,
|
||||
width: usize,
|
||||
height: usize,
|
||||
}
|
||||
|
||||
struct FrameCanvas<'a> {
|
||||
frame: &'a mut [u8],
|
||||
width: usize,
|
||||
height: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> OverlaySnapshot {
|
||||
let tel = firmware.os.atomic_telemetry.snapshot();
|
||||
let recent_logs = firmware.os.log_service.get_recent(10);
|
||||
let violations_count = recent_logs.iter().filter(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07).count();
|
||||
let violations_count =
|
||||
recent_logs.iter().filter(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07).count();
|
||||
|
||||
let mut footer = Vec::new();
|
||||
if violations_count > 0
|
||||
&& let Some(event) = recent_logs.into_iter().rev().find(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07)
|
||||
&& let Some(event) =
|
||||
recent_logs.into_iter().rev().find(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07)
|
||||
{
|
||||
footer.push(OverlayMetric {
|
||||
label: "CERT",
|
||||
@@ -75,8 +91,8 @@ pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> Overla
|
||||
.or(if tel.heap_max_bytes > 0 { Some(tel.heap_max_bytes) } else { None })
|
||||
.unwrap_or(OVERLAY_HEAP_FALLBACK_BYTES);
|
||||
let heap_ratio = ratio(tel.heap_used_bytes as u64, heap_total_bytes as u64);
|
||||
let gfx_ratio = ratio(tel.gfx_slots_occupied as u64, 16);
|
||||
let audio_ratio = ratio(tel.audio_slots_occupied as u64, 16);
|
||||
let glyph_ratio = ratio(tel.glyph_slots_used as u64, tel.glyph_slots_total as u64);
|
||||
let sound_ratio = ratio(tel.sound_slots_used as u64, tel.sound_slots_total as u64);
|
||||
|
||||
OverlaySnapshot {
|
||||
rows: vec![
|
||||
@@ -98,23 +114,11 @@ pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> Overla
|
||||
value: format!("{:.2}ms", stats.average_host_cpu_ms()),
|
||||
warn: false,
|
||||
},
|
||||
OverlayMetric {
|
||||
label: "STEPS",
|
||||
value: tel.vm_steps.to_string(),
|
||||
warn: false,
|
||||
},
|
||||
OverlayMetric { label: "STEPS", value: tel.vm_steps.to_string(), warn: false },
|
||||
),
|
||||
(
|
||||
OverlayMetric {
|
||||
label: "SYSC",
|
||||
value: tel.syscalls.to_string(),
|
||||
warn: false,
|
||||
},
|
||||
OverlayMetric {
|
||||
label: "LOGS",
|
||||
value: tel.logs_count.to_string(),
|
||||
warn: false,
|
||||
},
|
||||
OverlayMetric { label: "SYSC", value: tel.syscalls.to_string(), warn: false },
|
||||
OverlayMetric { label: "LOGS", value: tel.logs_count.to_string(), warn: false },
|
||||
),
|
||||
],
|
||||
bars: vec![
|
||||
@@ -136,36 +140,27 @@ pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> Overla
|
||||
label: "BUDGET",
|
||||
value: if tel.cycles_budget > 0 {
|
||||
format!(
|
||||
"{:.1}K/{:.1}K {:.1}%",
|
||||
"{:.1}K/{:.1}K",
|
||||
tel.cycles_used as f64 / 1000.0,
|
||||
tel.cycles_budget as f64 / 1000.0,
|
||||
cycles_ratio * 100.0
|
||||
tel.cycles_budget as f64 / 1000.0
|
||||
)
|
||||
} else {
|
||||
"0.0K/0.0K 0.0%".to_string()
|
||||
"0.0K/0.0K".to_string()
|
||||
},
|
||||
ratio: cycles_ratio,
|
||||
warn: cycles_ratio >= 0.9,
|
||||
},
|
||||
OverlayBar {
|
||||
label: "GFX",
|
||||
value: format!(
|
||||
"{} / 16 slots {}K",
|
||||
tel.gfx_slots_occupied,
|
||||
tel.gfx_used_bytes.div_ceil(1024)
|
||||
),
|
||||
ratio: gfx_ratio,
|
||||
warn: tel.gfx_inflight_bytes > 0,
|
||||
label: "GLYPH",
|
||||
value: format!("{} / {} slots", tel.glyph_slots_used, tel.glyph_slots_total),
|
||||
ratio: glyph_ratio,
|
||||
warn: tel.glyph_slots_total > 0 && tel.glyph_slots_used >= tel.glyph_slots_total,
|
||||
},
|
||||
OverlayBar {
|
||||
label: "AUD",
|
||||
value: format!(
|
||||
"{} / 16 slots {}K",
|
||||
tel.audio_slots_occupied,
|
||||
tel.audio_used_bytes.div_ceil(1024)
|
||||
),
|
||||
ratio: audio_ratio,
|
||||
warn: tel.audio_inflight_bytes > 0,
|
||||
label: "SOUNDS",
|
||||
value: format!("{} / {} slots", tel.sound_slots_used, tel.sound_slots_total),
|
||||
ratio: sound_ratio,
|
||||
warn: tel.sound_slots_total > 0 && tel.sound_slots_used >= tel.sound_slots_total,
|
||||
},
|
||||
],
|
||||
footer,
|
||||
@@ -178,44 +173,58 @@ pub(crate) fn draw_overlay(
|
||||
frame_height: usize,
|
||||
snapshot: &OverlaySnapshot,
|
||||
) {
|
||||
let mut canvas = FrameCanvas { frame, width: frame_width, height: frame_height };
|
||||
let panel_height = frame_height.saturating_sub(PANEL_Y * 2);
|
||||
let panel_rect = Rect { x: PANEL_X, y: PANEL_Y, width: PANEL_WIDTH, height: panel_height };
|
||||
|
||||
fill_rect_alpha(frame, frame_width, frame_height, PANEL_X, PANEL_Y, PANEL_WIDTH, panel_height, BG);
|
||||
stroke_rect(frame, frame_width, frame_height, PANEL_X, PANEL_Y, PANEL_WIDTH, panel_height, BORDER);
|
||||
fill_rect_alpha(&mut canvas, panel_rect, BG);
|
||||
stroke_rect(&mut canvas, panel_rect, BORDER);
|
||||
|
||||
let mut y = PANEL_Y + PANEL_PADDING;
|
||||
for (left, right) in &snapshot.rows {
|
||||
draw_metric_pair(frame, frame_width, frame_height, y, left, right);
|
||||
draw_metric_pair(canvas.frame, canvas.width, canvas.height, y, left, right);
|
||||
y += LINE_HEIGHT;
|
||||
}
|
||||
|
||||
for bar in &snapshot.bars {
|
||||
let color = if bar.warn { WARN } else { TEXT };
|
||||
draw_text(frame, frame_width, frame_height, PANEL_X + PANEL_PADDING, y, bar.label, DIM);
|
||||
draw_text(frame, frame_width, frame_height, PANEL_X + 48, y, &bar.value, color);
|
||||
draw_text(
|
||||
canvas.frame,
|
||||
canvas.width,
|
||||
canvas.height,
|
||||
PANEL_X + PANEL_PADDING,
|
||||
y,
|
||||
bar.label,
|
||||
DIM,
|
||||
);
|
||||
draw_text(canvas.frame, canvas.width, canvas.height, PANEL_X + 48, y, &bar.value, color);
|
||||
y += LINE_HEIGHT - 2;
|
||||
|
||||
let bar_x = PANEL_X + PANEL_PADDING;
|
||||
fill_rect(frame, frame_width, frame_height, bar_x, y, BAR_WIDTH, BAR_HEIGHT, BAR_BG);
|
||||
let bar_rect = Rect { x: bar_x, y, width: BAR_WIDTH, height: BAR_HEIGHT };
|
||||
fill_rect(&mut canvas, bar_rect, BAR_BG);
|
||||
let fill_width = ((BAR_WIDTH as f32) * bar.ratio.clamp(0.0, 1.0)).round() as usize;
|
||||
fill_rect(
|
||||
frame,
|
||||
frame_width,
|
||||
frame_height,
|
||||
bar_x,
|
||||
y,
|
||||
fill_width,
|
||||
BAR_HEIGHT,
|
||||
&mut canvas,
|
||||
Rect { x: bar_x, y, width: fill_width, height: BAR_HEIGHT },
|
||||
if bar.warn { BAR_WARN } else { BAR_FILL },
|
||||
);
|
||||
stroke_rect(frame, frame_width, frame_height, bar_x, y, BAR_WIDTH, BAR_HEIGHT, BORDER);
|
||||
stroke_rect(&mut canvas, bar_rect, BORDER);
|
||||
y += BAR_HEIGHT + 6;
|
||||
}
|
||||
|
||||
for line in &snapshot.footer {
|
||||
let color = if line.warn { WARN } else { TEXT };
|
||||
draw_text(frame, frame_width, frame_height, PANEL_X + PANEL_PADDING, y, line.label, DIM);
|
||||
draw_text(frame, frame_width, frame_height, PANEL_X + 48, y, &line.value, color);
|
||||
draw_text(
|
||||
canvas.frame,
|
||||
canvas.width,
|
||||
canvas.height,
|
||||
PANEL_X + PANEL_PADDING,
|
||||
y,
|
||||
line.label,
|
||||
DIM,
|
||||
);
|
||||
draw_text(canvas.frame, canvas.width, canvas.height, PANEL_X + 48, y, &line.value, color);
|
||||
y += LINE_HEIGHT;
|
||||
}
|
||||
}
|
||||
@@ -260,7 +269,15 @@ fn truncate_value(value: &str, max_len: usize) -> String {
|
||||
upper
|
||||
}
|
||||
|
||||
fn draw_text(frame: &mut [u8], frame_width: usize, frame_height: usize, x: usize, y: usize, text: &str, color: [u8; 4]) {
|
||||
fn draw_text(
|
||||
frame: &mut [u8],
|
||||
frame_width: usize,
|
||||
frame_height: usize,
|
||||
x: usize,
|
||||
y: usize,
|
||||
text: &str,
|
||||
color: [u8; 4],
|
||||
) {
|
||||
let mut cursor_x = x;
|
||||
for ch in text.chars() {
|
||||
if ch == '\n' {
|
||||
@@ -271,72 +288,71 @@ fn draw_text(frame: &mut [u8], frame_width: usize, frame_height: usize, x: usize
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_char(frame: &mut [u8], frame_width: usize, frame_height: usize, x: usize, y: usize, ch: char, color: [u8; 4]) {
|
||||
fn draw_char(
|
||||
frame: &mut [u8],
|
||||
frame_width: usize,
|
||||
frame_height: usize,
|
||||
x: usize,
|
||||
y: usize,
|
||||
ch: char,
|
||||
color: [u8; 4],
|
||||
) {
|
||||
let glyph = glyph_bits(ch);
|
||||
for (row, bits) in glyph.iter().enumerate() {
|
||||
for col in 0..5 {
|
||||
if bits & (1 << (4 - col)) != 0 {
|
||||
fill_rect(frame, frame_width, frame_height, x + col * CHAR_SCALE, y + row * CHAR_SCALE, CHAR_SCALE, CHAR_SCALE, color);
|
||||
let mut canvas = FrameCanvas { frame, width: frame_width, height: frame_height };
|
||||
fill_rect(
|
||||
&mut canvas,
|
||||
Rect {
|
||||
x: x + col * CHAR_SCALE,
|
||||
y: y + row * CHAR_SCALE,
|
||||
width: CHAR_SCALE,
|
||||
height: CHAR_SCALE,
|
||||
},
|
||||
color,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_rect_alpha(
|
||||
frame: &mut [u8],
|
||||
frame_width: usize,
|
||||
frame_height: usize,
|
||||
x: usize,
|
||||
y: usize,
|
||||
width: usize,
|
||||
height: usize,
|
||||
color: [u8; 4],
|
||||
) {
|
||||
let max_x = (x + width).min(frame_width);
|
||||
let max_y = (y + height).min(frame_height);
|
||||
for py in y..max_y {
|
||||
for px in x..max_x {
|
||||
blend_pixel(frame, frame_width, px, py, color);
|
||||
fn fill_rect_alpha(canvas: &mut FrameCanvas<'_>, rect: Rect, color: [u8; 4]) {
|
||||
let max_x = (rect.x + rect.width).min(canvas.width);
|
||||
let max_y = (rect.y + rect.height).min(canvas.height);
|
||||
for py in rect.y..max_y {
|
||||
for px in rect.x..max_x {
|
||||
blend_pixel(canvas.frame, canvas.width, px, py, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_rect(
|
||||
frame: &mut [u8],
|
||||
frame_width: usize,
|
||||
frame_height: usize,
|
||||
x: usize,
|
||||
y: usize,
|
||||
width: usize,
|
||||
height: usize,
|
||||
color: [u8; 4],
|
||||
) {
|
||||
let max_x = (x + width).min(frame_width);
|
||||
let max_y = (y + height).min(frame_height);
|
||||
for py in y..max_y {
|
||||
for px in x..max_x {
|
||||
write_pixel(frame, frame_width, px, py, color);
|
||||
fn fill_rect(canvas: &mut FrameCanvas<'_>, rect: Rect, color: [u8; 4]) {
|
||||
let max_x = (rect.x + rect.width).min(canvas.width);
|
||||
let max_y = (rect.y + rect.height).min(canvas.height);
|
||||
for py in rect.y..max_y {
|
||||
for px in rect.x..max_x {
|
||||
write_pixel(canvas.frame, canvas.width, px, py, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn stroke_rect(
|
||||
frame: &mut [u8],
|
||||
frame_width: usize,
|
||||
frame_height: usize,
|
||||
x: usize,
|
||||
y: usize,
|
||||
width: usize,
|
||||
height: usize,
|
||||
color: [u8; 4],
|
||||
) {
|
||||
if width == 0 || height == 0 {
|
||||
fn stroke_rect(canvas: &mut FrameCanvas<'_>, rect: Rect, color: [u8; 4]) {
|
||||
if rect.width == 0 || rect.height == 0 {
|
||||
return;
|
||||
}
|
||||
fill_rect(frame, frame_width, frame_height, x, y, width, 1, color);
|
||||
fill_rect(frame, frame_width, frame_height, x, y + height.saturating_sub(1), width, 1, color);
|
||||
fill_rect(frame, frame_width, frame_height, x, y, 1, height, color);
|
||||
fill_rect(frame, frame_width, frame_height, x + width.saturating_sub(1), y, 1, height, color);
|
||||
fill_rect(canvas, Rect { x: rect.x, y: rect.y, width: rect.width, height: 1 }, color);
|
||||
fill_rect(
|
||||
canvas,
|
||||
Rect { x: rect.x, y: rect.y + rect.height.saturating_sub(1), width: rect.width, height: 1 },
|
||||
color,
|
||||
);
|
||||
fill_rect(canvas, Rect { x: rect.x, y: rect.y, width: 1, height: rect.height }, color);
|
||||
fill_rect(
|
||||
canvas,
|
||||
Rect { x: rect.x + rect.width.saturating_sub(1), y: rect.y, width: 1, height: rect.height },
|
||||
color,
|
||||
);
|
||||
}
|
||||
|
||||
fn blend_pixel(frame: &mut [u8], frame_width: usize, x: usize, y: usize, color: [u8; 4]) {
|
||||
@@ -426,18 +442,20 @@ mod tests {
|
||||
OverlayMetric { label: "STEPS", value: "420".to_string(), warn: false },
|
||||
),
|
||||
],
|
||||
bars: vec![OverlayBar {
|
||||
label: "HEAP",
|
||||
value: "1024K / 8192K".to_string(),
|
||||
ratio: 0.125,
|
||||
warn: false,
|
||||
},
|
||||
OverlayBar {
|
||||
label: "BUDGET",
|
||||
value: "9.0K/10.0K 90.0%".to_string(),
|
||||
ratio: 0.9,
|
||||
warn: true,
|
||||
}],
|
||||
bars: vec![
|
||||
OverlayBar {
|
||||
label: "HEAP",
|
||||
value: "1024K / 8192K".to_string(),
|
||||
ratio: 0.125,
|
||||
warn: false,
|
||||
},
|
||||
OverlayBar {
|
||||
label: "BUDGET",
|
||||
value: "9.0K/10.0K".to_string(),
|
||||
ratio: 0.9,
|
||||
warn: true,
|
||||
},
|
||||
],
|
||||
footer: vec![OverlayMetric {
|
||||
label: "CRASH",
|
||||
value: "VM PANIC".to_string(),
|
||||
|
||||
@@ -122,7 +122,6 @@ impl HostRunner {
|
||||
w.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl ApplicationHandler for HostRunner {
|
||||
|
||||
@@ -45,8 +45,10 @@ impl HostStats {
|
||||
|
||||
pub fn record_host_cpu_time(&mut self, us: u64) {
|
||||
self.recent_host_cpu_us[self.recent_host_cpu_cursor] = us;
|
||||
self.recent_host_cpu_cursor = (self.recent_host_cpu_cursor + 1) % self.recent_host_cpu_us.len();
|
||||
self.recent_host_cpu_count = self.recent_host_cpu_count.saturating_add(1).min(self.recent_host_cpu_us.len());
|
||||
self.recent_host_cpu_cursor =
|
||||
(self.recent_host_cpu_cursor + 1) % self.recent_host_cpu_us.len();
|
||||
self.recent_host_cpu_count =
|
||||
self.recent_host_cpu_count.saturating_add(1).min(self.recent_host_cpu_us.len());
|
||||
}
|
||||
|
||||
pub fn average_host_cpu_ms(&self) -> f64 {
|
||||
|
||||
Reference in New Issue
Block a user