performance meter

This commit is contained in:
🪞👃🪞 2024-11-23 22:10:17 +01:00
parent a509db7215
commit 398f676ae3
12 changed files with 123 additions and 32 deletions

View file

@ -57,7 +57,6 @@ impl<F: HasFocus + HasEnter + FocusGrid + FocusOrder> Command<F> for FocusComman
Right => { state.focus_right(); },
Enter => { state.focus_enter(); },
Exit => { state.focus_exit(); },
_ => {}
}
Ok(None)
}
@ -92,7 +91,7 @@ pub trait HasEnter: HasFocus {
}
/// Exit the currently entered component
fn focus_exit (&mut self) {
self.set_entered(true);
self.set_entered(false);
self.focus_updated();
}
}

View file

@ -359,6 +359,59 @@ pub fn pulses_to_name (pulses: usize) -> &'static str {
for (length, name) in &NOTE_DURATIONS { if *length == pulses { return name } }
""
}
pub struct PerfModel {
pub enabled: bool,
clock: quanta::Clock,
// In nanoseconds
used: AtomicF64,
// In microseconds
period: AtomicF64,
}
impl Default for PerfModel {
fn default () -> Self {
Self {
enabled: true,
clock: quanta::Clock::new(),
used: Default::default(),
period: Default::default(),
}
}
}
impl PerfModel {
pub fn get_t0 (&self) -> Option<u64> {
if self.enabled {
Some(self.clock.raw())
} else {
None
}
}
pub fn update (&self, t0: Option<u64>, scope: &jack::ProcessScope) {
if let Some(t0) = t0 {
let t1 = self.clock.raw();
self.used.store(
self.clock.delta_as_nanos(t0, t1) as f64,
Ordering::Relaxed,
);
self.period.store(
scope.cycle_times().unwrap().period_usecs as f64,
Ordering::Relaxed,
);
}
}
pub fn percentage (&self) -> Option<f64> {
let period = self.period.load(Ordering::Relaxed) * 1000.0;
if period > 0.0 {
let used = self.used.load(Ordering::Relaxed);
Some(100.0 * used / period)
} else {
None
}
}
}
#[cfg(test)]
mod test {
use super::*;