rapier3d/counters/
solver_counters.rs1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4#[derive(Default, Clone, Copy)]
6pub struct SolverCounters {
7 pub nconstraints: usize,
9 pub ncontacts: usize,
11 pub velocity_resolution_time: Timer,
13 pub velocity_assembly_time: Timer,
15 pub velocity_update_time: Timer,
17 pub velocity_writeback_time: Timer,
19}
20
21impl SolverCounters {
22 pub fn new() -> Self {
24 SolverCounters {
25 nconstraints: 0,
26 ncontacts: 0,
27 velocity_assembly_time: Timer::new(),
28 velocity_resolution_time: Timer::new(),
29 velocity_update_time: Timer::new(),
30 velocity_writeback_time: Timer::new(),
31 }
32 }
33
34 pub fn reset(&mut self) {
36 self.nconstraints = 0;
37 self.ncontacts = 0;
38 self.velocity_resolution_time.reset();
39 self.velocity_assembly_time.reset();
40 self.velocity_update_time.reset();
41 self.velocity_writeback_time.reset();
42 }
43}
44
45impl Display for SolverCounters {
46 fn fmt(&self, f: &mut Formatter) -> Result {
47 writeln!(f, "Number of contacts: {}", self.ncontacts)?;
48 writeln!(f, "Number of constraints: {}", self.nconstraints)?;
49 writeln!(f, "Velocity assembly time: {}", self.velocity_assembly_time)?;
50 writeln!(
51 f,
52 "Velocity resolution time: {}",
53 self.velocity_resolution_time
54 )?;
55 writeln!(f, "Velocity update time: {}", self.velocity_update_time)?;
56 writeln!(
57 f,
58 "Velocity writeback time: {}",
59 self.velocity_writeback_time
60 )
61 }
62}