`voelinctl stream bench [--res WxH] [--fps N] [--codec vp8|vp9|h264] [--layer SPEC ...] [--seconds N]` runs the streamer's real pipeline on the test pattern without a server, into a sink that counts frames, keyframes and bytes per layer, and prints frame and bit rates, CPU use and heap allocations per frame in the steady state. Allocations are counted by a global allocator in voelinctl only (one relaxed atomic add each). The flat test pattern costs an encoder next to nothing, so it cannot show how the pipeline copes with real screens. `Pattern::Desktop` looks like a desktop with a code editor (gradient title bar, side bar, coloured lines of text) whose document scrolls three pixels per frame; it is rendered once and copied per frame, so drawing it stays cheap. The bench uses it by default (`--pattern simple` for the old one); `StreamerConfig` gets `synthetic_pattern`. Drawing the pattern now reuses a buffer (`SyntheticScreen::render`) and fills rows by copying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
//! The process's global allocator: the system allocator, counting
|
|
//! allocations (for `voelinctl stream bench`, which reports heap
|
|
//! allocations per frame). The count is one relaxed atomic add per
|
|
//! allocation.
|
|
#![allow(unsafe_code)]
|
|
|
|
use std::alloc::{GlobalAlloc, Layout, System};
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
|
|
static ALLOCATIONS: AtomicU64 = AtomicU64::new(0);
|
|
static BYTES: AtomicU64 = AtomicU64::new(0);
|
|
|
|
/// Allocations (including reallocations) and bytes requested so far.
|
|
pub fn counts() -> (u64, u64) {
|
|
(ALLOCATIONS.load(Ordering::Relaxed), BYTES.load(Ordering::Relaxed))
|
|
}
|
|
|
|
pub struct Counting;
|
|
|
|
fn count(size: usize) {
|
|
ALLOCATIONS.fetch_add(1, Ordering::Relaxed);
|
|
BYTES.fetch_add(size as u64, Ordering::Relaxed);
|
|
}
|
|
|
|
// SAFETY: every method forwards to `System` with the caller's arguments
|
|
// unchanged, so `System`'s guarantees hold; counting touches only atomics
|
|
// and never allocates.
|
|
unsafe impl GlobalAlloc for Counting {
|
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
count(layout.size());
|
|
// SAFETY: forwarded unchanged (see above).
|
|
unsafe { System.alloc(layout) }
|
|
}
|
|
|
|
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
|
count(layout.size());
|
|
// SAFETY: forwarded unchanged.
|
|
unsafe { System.alloc_zeroed(layout) }
|
|
}
|
|
|
|
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
|
count(new_size);
|
|
// SAFETY: forwarded unchanged.
|
|
unsafe { System.realloc(ptr, layout, new_size) }
|
|
}
|
|
|
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
|
// SAFETY: forwarded unchanged.
|
|
unsafe { System.dealloc(ptr, layout) }
|
|
}
|
|
}
|