From 400f3a23bfa9a9a3d79c3d0c2d49ca1ea1a90d84 Mon Sep 17 00:00:00 2001 From: Nova Date: Sat, 14 Jan 2023 22:59:00 -0500 Subject: [PATCH] feat: spatial tracing --- Cargo.toml | 1 + src/nodes/mod.rs | 14 ++++++++++---- src/nodes/spatial/mod.rs | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6876f36..9de18c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,7 @@ optional = true [dependencies.tracing-chrome] version = "0.7.0" optional = true + [features] default = ["wayland"] wayland = ["dep:smithay", "dep:xkbcommon"] diff --git a/src/nodes/mod.rs b/src/nodes/mod.rs index aa1630e..b4e51e5 100644 --- a/src/nodes/mod.rs +++ b/src/nodes/mod.rs @@ -19,6 +19,7 @@ use std::future::Future; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Weak}; use std::vec::Vec; +use tracing::debug_span; use core::hash::BuildHasherDefault; use dashmap::DashMap; @@ -188,8 +189,10 @@ impl Node { .local_signals .get(method) .ok_or(ScenegraphError::SignalNotFound)?; - signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError { - error: error.to_string(), + debug_span!("Handle signal").in_scope(|| { + signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError { + error: error.to_string(), + }) }) } } @@ -213,8 +216,11 @@ impl Node { .local_methods .get(method) .ok_or(ScenegraphError::MethodNotFound)?; - method(self, calling_client, data).map_err(|error| ScenegraphError::MethodError { - error: error.to_string(), + + debug_span!("Handle method").in_scope(|| { + method(self, calling_client, data).map_err(|error| ScenegraphError::MethodError { + error: error.to_string(), + }) }) } } diff --git a/src/nodes/spatial/mod.rs b/src/nodes/spatial/mod.rs index db4693c..4a073e8 100644 --- a/src/nodes/spatial/mod.rs +++ b/src/nodes/spatial/mod.rs @@ -12,8 +12,10 @@ use parking_lot::Mutex; use serde::Deserialize; use stardust_xr::schemas::flex::{deserialize, serialize}; use stardust_xr::values::Transform; +use std::fmt::Debug; use std::ptr; use std::sync::{Arc, Weak}; +use tracing::instrument; static ZONEABLE_REGISTRY: Registry = Registry::new(); @@ -71,12 +73,14 @@ impl Spatial { Ok(spatial_arc) } + #[instrument] pub fn space_to_space_matrix(from: Option<&Spatial>, to: Option<&Spatial>) -> Mat4 { let space_to_world_matrix = from.map_or(Mat4::IDENTITY, |from| from.global_transform()); let world_to_space_matrix = to.map_or(Mat4::IDENTITY, |to| to.global_transform().inverse()); world_to_space_matrix * space_to_world_matrix } + #[instrument] pub fn local_transform(&self) -> Mat4 { *self.transform.lock() } @@ -86,9 +90,11 @@ impl Spatial { None => *self.transform.lock(), } } + #[instrument] pub fn set_local_transform(&self, transform: Mat4) { *self.transform.lock() = transform; } + #[instrument] pub fn set_local_transform_components( &self, reference_space: Option<&Spatial>, @@ -126,6 +132,7 @@ impl Spatial { ); } + #[instrument] pub fn is_ancestor_of(&self, spatial: Arc) -> bool { let mut current_ancestor = spatial; loop { @@ -142,6 +149,7 @@ impl Spatial { } } + #[instrument] pub fn set_spatial_parent(&self, parent: Option<&Arc>) -> Result<()> { let is_ancestor = parent .map(|parent| self.is_ancestor_of(parent.clone())) @@ -155,6 +163,7 @@ impl Spatial { Ok(()) } + #[instrument] pub fn set_spatial_parent_in_place(&self, parent: Option<&Arc>) -> Result<()> { let is_ancestor = parent .map(|parent| self.is_ancestor_of(parent.clone())) @@ -249,6 +258,7 @@ impl Spatial { Ok(()) } + #[instrument] pub(self) fn zone_distance(&self) -> f32 { self.zone .lock() @@ -258,6 +268,16 @@ impl Spatial { .unwrap_or(f32::MAX) } } +impl Debug for Spatial { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Spatial") + .field("uid", &self.uid) + .field("parent", &self.parent) + .field("old_parent", &self.old_parent) + .field("transform", &self.transform) + .finish() + } +} impl Drop for Spatial { fn drop(&mut self) { ZONEABLE_REGISTRY.remove(self);