pub struct CpuUsage { /* private fields */ }Expand description
A reading of the CPU monitoring counters.
percentage is the figure to look at; the
rest describes the acquisition cycle it came from and how far along
the next one is.
Implementations§
Source§impl CpuUsage
impl CpuUsage
Sourcepub const fn percentage(&self) -> f32
pub const fn percentage(&self) -> f32
Percentage of the measured period spent busy, averaged over the last completed acquisition cycle.
Zero until the first cycle completes, which takes
measurements_per_cycle
tics — for the audio thread, that many blocks.
Examples found in repository?
examples/cpu.rs (line 237)
221 fn render_post(&mut self, states: &mut [Bank], context: &mut BlockContext) {
222 #[allow(
223 clippy::cast_precision_loss,
224 reason = "a block's frame count is far below f32's exact integer range"
225 )]
226 let frames = context.audio_frames() as f32;
227 for (phase, increment) in self.phases.iter_mut().zip(&self.phase_increments) {
228 *phase = (*phase + frames * increment) % TAU;
229 }
230
231 self.blocks += 1;
232 if self.blocks % self.blocks_per_report != 0 {
233 return;
234 }
235 // Read here, on the main audio thread, and handed to the task
236 // as plain numbers.
237 let thread = context.cpu_usage().map_or(0.0, |usage| usage.percentage());
238 let section = states
239 .first()
240 .map_or(0.0, |bank| bank.timer.usage().percentage());
241 self.published
242 .thread
243 .store(thread.to_bits(), Ordering::Relaxed);
244 self.published
245 .section
246 .store(section.to_bits(), Ordering::Relaxed);
247 if let Some(task) = &self.task {
248 task.schedule(context);
249 }
250 }More examples
examples/parallel.rs (line 320)
308 fn cleanup(&mut self, states: &mut [Voice], context: &CleanupContext) {
309 let mut rendered = 0;
310 for state in states.iter() {
311 rt_println!(
312 "parallel: thread={} tid={} cpu={} range={}..{} calls={} frames={} section={:.1}%",
313 state.thread,
314 state.thread_id,
315 state.cpu,
316 state.first_frame,
317 state.last_frame,
318 state.calls,
319 state.frames,
320 state.timer.usage().percentage()
321 );
322 rendered += state.frames;
323 }
324 let frames = context.audio_frames() as u64;
325 let expected = self.started * frames;
326 rt_println!(
327 "parallel: blocks={} frames={frames} rendered={rendered} expected={expected}",
328 self.started
329 );
330 rt_println!(
331 "parallel: uncovered={} abandoned={} unfinished={}",
332 self.uncovered,
333 self.abandoned,
334 self.started - self.finished
335 );
336 let busy = context.cpu_usage().map_or(0.0, |usage| usage.percentage());
337 rt_println!("parallel: audio-thread={busy:.1}%");
338 }Sourcepub const fn busy(&self) -> Duration
pub const fn busy(&self) -> Duration
Busy time accumulated so far in the current, incomplete cycle.
Sourcepub const fn total(&self) -> Duration
pub const fn total(&self) -> Duration
Total time accumulated so far in the current, incomplete cycle — busy and idle together.
Sourcepub const fn measurements_per_cycle(&self) -> u32
pub const fn measurements_per_cycle(&self) -> u32
How many tics make up an acquisition cycle (Bela’s count).
Sourcepub const fn measurements_taken(&self) -> u32
pub const fn measurements_taken(&self) -> u32
How many tics have happened in the current cycle (Bela’s
currentCount).
Trait Implementations§
impl Copy for CpuUsage
impl StructuralPartialEq for CpuUsage
Auto Trait Implementations§
impl Freeze for CpuUsage
impl RefUnwindSafe for CpuUsage
impl Send for CpuUsage
impl Sync for CpuUsage
impl Unpin for CpuUsage
impl UnsafeUnpin for CpuUsage
impl UnwindSafe for CpuUsage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more