diff --git a/CHANGELOG.md b/CHANGELOG.md index d19e379f..24369f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - `InteractionGroups` default value for `memberships` is now `GROUP_1` (#706) - `ImpulseJointSet::get_mut` has a new parameter `wake_up: bool`, to wake up connected bodies. -- Removed unmaintained `instant` in favor of `web-time`. +- Removed unmaintained `instant` in favor of `web-time`. This effectively removes the `wasm-bindgen` transitive dependency as it's no longer needed. ## v0.22.0 (20 July 2024) diff --git a/src/counters/mod.rs b/src/counters/mod.rs index 188f0785..43d4bd2b 100644 --- a/src/counters/mod.rs +++ b/src/counters/mod.rs @@ -1,5 +1,6 @@ //! Counters for benchmarking various parts of the physics engine. +use core::time::Duration; use std::fmt::{Display, Formatter, Result}; pub use self::ccd_counters::CCDCounters; @@ -76,11 +77,16 @@ impl Counters { } } - /// Total time spent for one of the physics engine. - pub fn step_time(&self) -> f64 { + /// Total time spent for one of the physics engine. + pub fn step_time(&self) -> Duration { self.step_time.time() } + /// Total time spent for one of the physics engine, in milliseconds. + pub fn step_time_ms(&self) -> f64 { + self.step_time.time_ms() + } + /// Notify that the custom operation has started. pub fn custom_started(&mut self) { if self.enabled { @@ -96,10 +102,15 @@ impl Counters { } /// Total time of a custom event. - pub fn custom_time(&self) -> f64 { + pub fn custom_time(&self) -> Duration { self.custom.time() } + /// Total time of a custom event, in milliseconds. + pub fn custom_time_ms(&self) -> f64 { + self.custom.time_ms() + } + /// Set the number of constraints generated. pub fn set_nconstraints(&mut self, n: usize) { self.solver.nconstraints = n; @@ -129,7 +140,7 @@ impl Counters { } macro_rules! measure_method { - ($started:ident, $stopped:ident, $time:ident, $info:ident. $timer:ident) => { + ($started:ident, $stopped:ident, $time_ms:ident, $info:ident. $timer:ident) => { impl Counters { /// Start this timer. pub fn $started(&mut self) { @@ -145,10 +156,10 @@ macro_rules! measure_method { } } - /// Gets the time elapsed for this timer. - pub fn $time(&self) -> f64 { + /// Gets the time elapsed for this timer, in milliseconds. + pub fn $time_ms(&self) -> f64 { if self.enabled { - self.$info.$timer.time() + self.$info.$timer.time_ms() } else { 0.0 } @@ -160,63 +171,63 @@ macro_rules! measure_method { measure_method!( update_started, update_completed, - update_time, + update_time_ms, stages.update_time ); measure_method!( collision_detection_started, collision_detection_completed, - collision_detection_time, + collision_detection_time_ms, stages.collision_detection_time ); measure_method!( island_construction_started, island_construction_completed, - island_construction_time, + island_construction_time_ms, stages.island_construction_time ); measure_method!( solver_started, solver_completed, - solver_time, + solver_time_ms, stages.solver_time ); -measure_method!(ccd_started, ccd_completed, ccd_time, stages.ccd_time); +measure_method!(ccd_started, ccd_completed, ccd_time_ms, stages.ccd_time); measure_method!( query_pipeline_update_started, query_pipeline_update_completed, - query_pipeline_update_time, + query_pipeline_update_time_ms, stages.query_pipeline_time ); measure_method!( assembly_started, assembly_completed, - assembly_time, + assembly_time_ms, solver.velocity_assembly_time ); measure_method!( velocity_resolution_started, velocity_resolution_completed, - velocity_resolution_time, + velocity_resolution_time_ms, solver.velocity_resolution_time ); measure_method!( velocity_update_started, velocity_update_completed, - velocity_update_time, + velocity_update_time_ms, solver.velocity_update_time ); measure_method!( broad_phase_started, broad_phase_completed, - broad_phase_time, + broad_phase_time_ms, cd.broad_phase_time ); measure_method!( narrow_phase_started, narrow_phase_completed, - narrow_phase_time, + narrow_phase_time_ms, cd.narrow_phase_time ); diff --git a/src/counters/timer.rs b/src/counters/timer.rs index 54bd0a3c..3ffef430 100644 --- a/src/counters/timer.rs +++ b/src/counters/timer.rs @@ -54,13 +54,18 @@ impl Timer { } /// The measured time between the last `.start()` and `.pause()` calls. - pub fn time(&self) -> f64 { + pub fn time(&self) -> Duration { + self.time + } + + /// The measured time in milliseconds between the last `.start()` and `.pause()` calls. + pub fn time_ms(&self) -> f64 { self.time.as_secs_f64() * 1000.0 } } impl Display for Timer { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{}s", self.time.as_secs_f32()) + write!(f, "{}ms", self.time_ms()) } } diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 9f1bf202..c4fa6880 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -393,7 +393,8 @@ impl TestbedApp { // Skip the first update. if k > 0 { - timings.push(self.harness.physics.pipeline.counters.step_time.time()); + timings + .push(self.harness.physics.pipeline.counters.step_time.time_ms()); } } results.push(timings); diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs index c568495c..1c0421a0 100644 --- a/src_testbed/ui.rs +++ b/src_testbed/ui.rs @@ -360,72 +360,78 @@ fn scene_infos_ui(ui: &mut Ui, physics: &PhysicsState) { fn profiling_ui(ui: &mut Ui, counters: &Counters) { egui::CollapsingHeader::new(format!( "Total: {:.2}ms - {} fps", - counters.step_time(), - (1000.0 / counters.step_time()).round() + counters.step_time_ms(), + (1000.0 / counters.step_time_ms()).round() )) .id_source("total") .show(ui, |ui| { egui::CollapsingHeader::new(format!( "Collision detection: {:.2}ms", - counters.collision_detection_time() + counters.collision_detection_time_ms() )) .id_source("collision detection") .show(ui, |ui| { - ui.label(format!("Broad-phase: {:.2}ms", counters.broad_phase_time())); + ui.label(format!( + "Broad-phase: {:.2}ms", + counters.broad_phase_time_ms() + )); ui.label(format!( "Narrow-phase: {:.2}ms", - counters.narrow_phase_time() + counters.narrow_phase_time_ms() )); }); - egui::CollapsingHeader::new(format!("Solver: {:.2}ms", counters.solver_time())) + egui::CollapsingHeader::new(format!("Solver: {:.2}ms", counters.solver_time_ms())) .id_source("solver") .show(ui, |ui| { ui.label(format!( "Velocity assembly: {:.2}ms", - counters.solver.velocity_assembly_time.time() + counters.solver.velocity_assembly_time.time_ms() )); ui.label(format!( "Velocity resolution: {:.2}ms", - counters.velocity_resolution_time() + counters.velocity_resolution_time_ms() )); ui.label(format!( "Velocity integration: {:.2}ms", - counters.solver.velocity_update_time.time() + counters.solver.velocity_update_time.time_ms() )); ui.label(format!( "Writeback: {:.2}ms", - counters.solver.velocity_writeback_time.time() + counters.solver.velocity_writeback_time.time_ms() )); }); - egui::CollapsingHeader::new(format!("CCD: {:.2}ms", counters.ccd_time())) + egui::CollapsingHeader::new(format!("CCD: {:.2}ms", counters.ccd_time_ms())) .id_source("ccd") .show(ui, |ui| { ui.label(format!("# of substeps: {}", counters.ccd.num_substeps)); ui.label(format!( "TOI computation: {:.2}ms", - counters.ccd.toi_computation_time.time(), + counters.ccd.toi_computation_time.time_ms(), )); ui.label(format!( "Broad-phase: {:.2}ms", - counters.ccd.broad_phase_time.time() + counters.ccd.broad_phase_time.time_ms() )); ui.label(format!( "Narrow-phase: {:.2}ms", - counters.ccd.narrow_phase_time.time(), + counters.ccd.narrow_phase_time.time_ms(), + )); + ui.label(format!( + "Solver: {:.2}ms", + counters.ccd.solver_time.time_ms() )); - ui.label(format!("Solver: {:.2}ms", counters.ccd.solver_time.time())); }); ui.label(format!( "Island computation: {:.2}ms", - counters.island_construction_time() + counters.island_construction_time_ms() )); ui.label(format!( "Query pipeline: {:.2}ms", - counters.query_pipeline_update_time() + counters.query_pipeline_update_time_ms() )); ui.label(format!( "User changes: {:.2}ms", - counters.stages.user_changes.time() + counters.stages.user_changes.time_ms() )); }); }