aboutsummaryrefslogtreecommitdiff
path: root/src_testbed
diff options
context:
space:
mode:
authorThierry Berger <contact@thierryberger.com>2024-11-19 16:33:26 +0100
committerGitHub <noreply@github.com>2024-11-19 16:33:26 +0100
commit510237cc29ebc667a8c158ef0340b7d1aa669a72 (patch)
tree772daf3fac2e463eba254900001fce5a659f2f92 /src_testbed
parentff79f4c67478f8c8045464cac22f9e57388cd4a0 (diff)
downloadrapier-510237cc29ebc667a8c158ef0340b7d1aa669a72.tar.gz
rapier-510237cc29ebc667a8c158ef0340b7d1aa669a72.tar.bz2
rapier-510237cc29ebc667a8c158ef0340b7d1aa669a72.zip
Profiling support (#743)
Diffstat (limited to 'src_testbed')
-rw-r--r--src_testbed/box2d_backend.rs3
-rw-r--r--src_testbed/graphics.rs2
-rw-r--r--src_testbed/harness/mod.rs1
-rw-r--r--src_testbed/objects/node.rs4
-rw-r--r--src_testbed/physics/mod.rs1
-rw-r--r--src_testbed/physx_backend.rs1
-rw-r--r--src_testbed/testbed.rs13
-rw-r--r--src_testbed/ui.rs35
8 files changed, 56 insertions, 4 deletions
diff --git a/src_testbed/box2d_backend.rs b/src_testbed/box2d_backend.rs
index b9bc97e..bd6aa13 100644
--- a/src_testbed/box2d_backend.rs
+++ b/src_testbed/box2d_backend.rs
@@ -28,6 +28,7 @@ pub struct Box2dWorld {
}
impl Box2dWorld {
+ #[profiling::function]
pub fn from_rapier(
gravity: Vector2<f32>,
bodies: &RigidBodySet,
@@ -221,6 +222,7 @@ impl Box2dWorld {
}
}
+ #[profiling::function]
pub fn step(&mut self, counters: &mut Counters, params: &IntegrationParameters) {
counters.step_started();
self.world
@@ -228,6 +230,7 @@ impl Box2dWorld {
counters.step_completed();
}
+ #[profiling::function]
pub fn sync(&self, bodies: &mut RigidBodySet, colliders: &mut ColliderSet) {
for (handle, body) in bodies.iter_mut() {
if let Some(pb2_handle) = self.rapier2box2d.get(&handle) {
diff --git a/src_testbed/graphics.rs b/src_testbed/graphics.rs
index 226be4d..c09c971 100644
--- a/src_testbed/graphics.rs
+++ b/src_testbed/graphics.rs
@@ -18,7 +18,7 @@ use rand_pcg::Pcg32;
use std::collections::HashMap;
#[cfg(feature = "dim2")]
-pub type BevyMaterial = ColorMaterial;
+pub type BevyMaterial = bevy_sprite::ColorMaterial;
#[cfg(feature = "dim3")]
pub type BevyMaterial = StandardMaterial;
diff --git a/src_testbed/harness/mod.rs b/src_testbed/harness/mod.rs
index 9c41472..734625b 100644
--- a/src_testbed/harness/mod.rs
+++ b/src_testbed/harness/mod.rs
@@ -206,6 +206,7 @@ impl Harness {
self.step_with_graphics(None);
}
+ #[profiling::function]
pub fn step_with_graphics(&mut self, mut graphics: Option<&mut TestbedGraphics>) {
#[cfg(feature = "parallel")]
{
diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs
index a5f7d51..5926eb7 100644
--- a/src_testbed/objects/node.rs
+++ b/src_testbed/objects/node.rs
@@ -43,7 +43,7 @@ impl EntityWithGraphics {
}
#[cfg(feature = "dim2")]
- let selection_material = ColorMaterial {
+ let selection_material = bevy_sprite::ColorMaterial {
color: Color::from(Srgba::rgb(1.0, 0.0, 0.0)),
texture: None,
};
@@ -109,7 +109,7 @@ impl EntityWithGraphics {
}
#[cfg(feature = "dim2")]
- let material = ColorMaterial {
+ let material = bevy_sprite::ColorMaterial {
color: bevy_color,
texture: None,
};
diff --git a/src_testbed/physics/mod.rs b/src_testbed/physics/mod.rs
index 3c69f6e..b08d7f5 100644
--- a/src_testbed/physics/mod.rs
+++ b/src_testbed/physics/mod.rs
@@ -54,6 +54,7 @@ impl PhysicsSnapshot {
})
}
+ #[profiling::function]
pub fn restore(&self) -> bincode::Result<DeserializedPhysicsSnapshot> {
Ok(DeserializedPhysicsSnapshot {
timestep_id: self.timestep_id,
diff --git a/src_testbed/physx_backend.rs b/src_testbed/physx_backend.rs
index 71f8f9d..ae77615 100644
--- a/src_testbed/physx_backend.rs
+++ b/src_testbed/physx_backend.rs
@@ -147,6 +147,7 @@ impl Drop for PhysxWorld {
}
impl PhysxWorld {
+ #[profiling::function]
pub fn from_rapier(
gravity: Vector3<f32>,
integration_parameters: &IntegrationParameters,
diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs
index 7b2f0fd..fa7f731 100644
--- a/src_testbed/testbed.rs
+++ b/src_testbed/testbed.rs
@@ -249,6 +249,9 @@ impl TestbedApp {
}
pub fn run_with_init(mut self, mut init: impl FnMut(&mut App)) {
+ #[cfg(feature = "profiling")]
+ puffin_egui::puffin::set_scopes_on(true);
+
let mut args = env::args();
let mut benchmark_mode = false;
@@ -885,6 +888,10 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> {
}
fn handle_common_events(&mut self, events: &ButtonInput<KeyCode>) {
+ // C can be used to write within profiling filter.
+ if events.pressed(KeyCode::ControlLeft) || events.pressed(KeyCode::ControlRight) {
+ return;
+ }
for key in events.get_just_released() {
match *key {
KeyCode::KeyT => {
@@ -1184,6 +1191,8 @@ fn update_testbed(
),
keys: Res<ButtonInput<KeyCode>>,
) {
+ profiling::finish_frame!();
+
let meshes = &mut *meshes;
let materials = &mut *materials;
@@ -1210,7 +1219,9 @@ fn update_testbed(
plugins: &mut plugins,
};
- testbed.handle_common_events(&keys);
+ if !ui_context.ctx_mut().wants_keyboard_input() {
+ testbed.handle_common_events(&keys);
+ }
testbed.update_character_controller(&keys);
#[cfg(feature = "dim3")]
{
diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs
index b27ea7a..8e543af 100644
--- a/src_testbed/ui.rs
+++ b/src_testbed/ui.rs
@@ -21,6 +21,41 @@ pub fn update_ui(
harness: &mut Harness,
debug_render: &mut DebugRenderPipelineResource,
) {
+ #[cfg(feature = "profiling")]
+ {
+ let window = egui::Window::new("Profiling");
+ let window = window.default_open(false);
+
+ #[cfg(feature = "unstable-puffin-pr-235")]
+ {
+ use std::sync::Once;
+ static START: Once = Once::new();
+
+ fn set_default_rapier_filter() {
+ let mut profile_ui = puffin_egui::PROFILE_UI.lock();
+ profile_ui
+ .profiler_ui
+ .flamegraph_options
+ .scope_name_filter
+ .set_filter("Harness::step_with_graphics".to_string());
+ }
+ START.call_once(|| {
+ set_default_rapier_filter();
+ });
+ window.show(ui_context.ctx_mut(), |ui| {
+ if ui.button("🔍 Rapier filter").clicked() {
+ set_default_rapier_filter();
+ }
+ puffin_egui::profiler_ui(ui);
+ });
+ }
+
+ #[cfg(not(feature = "unstable-puffin-pr-235"))]
+ window.show(ui_context.ctx_mut(), |ui| {
+ puffin_egui::profiler_ui(ui);
+ });
+ }
+
egui::Window::new("Parameters").show(ui_context.ctx_mut(), |ui| {
if state.backend_names.len() > 1 && !state.example_names.is_empty() {
let mut changed = false;