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