feat: even more tracing
This commit is contained in:
@@ -5,6 +5,7 @@ use once_cell::sync::OnceCell;
|
|||||||
use stardust_xr::scenegraph;
|
use stardust_xr::scenegraph;
|
||||||
use stardust_xr::scenegraph::ScenegraphError;
|
use stardust_xr::scenegraph::ScenegraphError;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
use tracing::{debug, debug_span, instrument};
|
||||||
|
|
||||||
use core::hash::BuildHasherDefault;
|
use core::hash::BuildHasherDefault;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -27,10 +28,12 @@ impl Scenegraph {
|
|||||||
node_arc
|
node_arc
|
||||||
}
|
}
|
||||||
pub fn add_node_raw(&self, node: Arc<Node>) {
|
pub fn add_node_raw(&self, node: Arc<Node>) {
|
||||||
|
debug!(node = ?&*node, "Add node");
|
||||||
let path = node.get_path().to_string();
|
let path = node.get_path().to_string();
|
||||||
self.nodes.insert(path, node);
|
self.nodes.insert(path, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip(self))]
|
||||||
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||||
let mut node = self.nodes.get(path)?.clone();
|
let mut node = self.nodes.get(path)?.clone();
|
||||||
if let Some(alias) = node.alias.get() {
|
if let Some(alias) = node.alias.get() {
|
||||||
@@ -40,6 +43,7 @@ impl Scenegraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
|
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||||
|
debug!(path, "Remove node");
|
||||||
let (_, node) = self.nodes.remove(path)?;
|
let (_, node) = self.nodes.remove(path)?;
|
||||||
Some(node)
|
Some(node)
|
||||||
}
|
}
|
||||||
@@ -47,9 +51,11 @@ impl Scenegraph {
|
|||||||
|
|
||||||
impl scenegraph::Scenegraph for Scenegraph {
|
impl scenegraph::Scenegraph for Scenegraph {
|
||||||
fn send_signal(&self, path: &str, method: &str, data: &[u8]) -> Result<(), ScenegraphError> {
|
fn send_signal(&self, path: &str, method: &str, data: &[u8]) -> Result<(), ScenegraphError> {
|
||||||
self.get_node(path)
|
debug_span!("Handle signal", path, method).in_scope(|| {
|
||||||
.ok_or(ScenegraphError::NodeNotFound)?
|
self.get_node(path)
|
||||||
.send_local_signal(self.get_client(), method, data)
|
.ok_or(ScenegraphError::NodeNotFound)?
|
||||||
|
.send_local_signal(self.get_client(), method, data)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
fn execute_method(
|
fn execute_method(
|
||||||
&self,
|
&self,
|
||||||
@@ -57,8 +63,10 @@ impl scenegraph::Scenegraph for Scenegraph {
|
|||||||
method: &str,
|
method: &str,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<Vec<u8>, ScenegraphError> {
|
) -> Result<Vec<u8>, ScenegraphError> {
|
||||||
self.get_node(path)
|
debug_span!("Handle method", path, method).in_scope(|| {
|
||||||
.ok_or(ScenegraphError::NodeNotFound)?
|
self.get_node(path)
|
||||||
.execute_local_method(self.get_client(), method, data)
|
.ok_or(ScenegraphError::NodeNotFound)?
|
||||||
|
.execute_local_method(self.get_client(), method, data)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn new<
|
pub fn new<
|
||||||
F: FnOnce() -> S,
|
F: FnOnce() -> S,
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use stardust_xr::values::Transform;
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
use tracing::{debug_span, instrument};
|
||||||
|
|
||||||
static INPUT_METHOD_REGISTRY: Registry<InputMethod> = Registry::new();
|
static INPUT_METHOD_REGISTRY: Registry<InputMethod> = Registry::new();
|
||||||
static INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Registry::new();
|
static INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Registry::new();
|
||||||
@@ -145,6 +146,7 @@ impl DistanceLink {
|
|||||||
fn send_input(&self, frame: u64, datamap: Datamap) {
|
fn send_input(&self, frame: u64, datamap: Datamap) {
|
||||||
self.handler.send_input(frame, self, datamap);
|
self.handler.send_input(frame, self, datamap);
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn serialize(&self, datamap: Datamap) -> Vec<u8> {
|
fn serialize(&self, datamap: Datamap) -> Vec<u8> {
|
||||||
let input = self.method.specialization.lock().serialize(
|
let input = self.method.specialization.lock().serialize(
|
||||||
self,
|
self,
|
||||||
@@ -185,6 +187,7 @@ impl InputHandler {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip(self, distance_link))]
|
||||||
fn send_input(&self, frame: u64, distance_link: &DistanceLink, datamap: Datamap) {
|
fn send_input(&self, frame: u64, distance_link: &DistanceLink, datamap: Datamap) {
|
||||||
let data = distance_link.serialize(datamap);
|
let data = distance_link.serialize(datamap);
|
||||||
let node = self.node.upgrade().unwrap();
|
let node = self.node.upgrade().unwrap();
|
||||||
@@ -250,39 +253,49 @@ pub fn create_input_handler_flex(
|
|||||||
#[tracing::instrument(level = "debug")]
|
#[tracing::instrument(level = "debug")]
|
||||||
pub fn process_input() {
|
pub fn process_input() {
|
||||||
// Iterate over all valid input methods
|
// Iterate over all valid input methods
|
||||||
for method in INPUT_METHOD_REGISTRY
|
let methods = debug_span!("Get valid methods").in_scope(|| {
|
||||||
.get_valid_contents()
|
INPUT_METHOD_REGISTRY
|
||||||
.into_iter()
|
|
||||||
.filter(|method| *method.enabled.lock())
|
|
||||||
.filter(|method| method.datamap.lock().is_some())
|
|
||||||
{
|
|
||||||
// Get all valid input handlers and convert them to DistanceLink objects
|
|
||||||
let mut distance_links: Vec<DistanceLink> = INPUT_HANDLER_REGISTRY
|
|
||||||
.get_valid_contents()
|
.get_valid_contents()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|handler| handler.field.upgrade().is_some())
|
.filter(|method| *method.enabled.lock())
|
||||||
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
.filter(|method| method.datamap.lock().is_some())
|
||||||
.collect();
|
});
|
||||||
|
for method in methods {
|
||||||
|
debug_span!("Process input method").in_scope(|| {
|
||||||
|
// Get all valid input handlers and convert them to DistanceLink objects
|
||||||
|
let mut distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
||||||
|
.in_scope(|| {
|
||||||
|
INPUT_HANDLER_REGISTRY
|
||||||
|
.get_valid_contents()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|handler| handler.field.upgrade().is_some())
|
||||||
|
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
||||||
|
.collect()
|
||||||
|
});
|
||||||
|
|
||||||
// Sort the distance links by their distance in ascending order
|
// Sort the distance links by their distance in ascending order
|
||||||
distance_links
|
debug_span!("Sort distance links").in_scope(|| {
|
||||||
.sort_unstable_by(|a, b| a.distance.abs().partial_cmp(&b.distance.abs()).unwrap());
|
distance_links.sort_unstable_by(|a, b| {
|
||||||
|
a.distance.abs().partial_cmp(&b.distance.abs()).unwrap()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Get the current frame
|
// Get the current frame
|
||||||
let frame = FRAME.load(Ordering::Relaxed);
|
let frame = FRAME.load(Ordering::Relaxed);
|
||||||
|
|
||||||
// Iterate over the distance links and send input to them
|
// Iterate over the distance links and send input to them
|
||||||
for distance_link in distance_links {
|
for distance_link in distance_links {
|
||||||
distance_link.send_input(frame, method.datamap.lock().clone().unwrap());
|
distance_link.send_input(frame, method.datamap.lock().clone().unwrap());
|
||||||
|
|
||||||
// If the current distance link is in the list of captured input handlers,
|
// If the current distance link is in the list of captured input handlers,
|
||||||
// break out of the loop to avoid sending input to the remaining distance links
|
// break out of the loop to avoid sending input to the remaining distance links
|
||||||
if method.captures.contains(&distance_link.handler) {
|
if method.captures.contains(&distance_link.handler) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Clear the list of captured input handlers for this method
|
// Clear the list of captured input handlers for this method
|
||||||
method.captures.clear();
|
method.captures.clear();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,12 @@ use once_cell::sync::OnceCell;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use stardust_xr::messenger::MessageSenderHandle;
|
use stardust_xr::messenger::MessageSenderHandle;
|
||||||
use stardust_xr::scenegraph::ScenegraphError;
|
use stardust_xr::scenegraph::ScenegraphError;
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use tracing::debug_span;
|
use tracing::{debug_span, instrument};
|
||||||
|
|
||||||
use core::hash::BuildHasherDefault;
|
use core::hash::BuildHasherDefault;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -189,10 +190,8 @@ impl Node {
|
|||||||
.local_signals
|
.local_signals
|
||||||
.get(method)
|
.get(method)
|
||||||
.ok_or(ScenegraphError::SignalNotFound)?;
|
.ok_or(ScenegraphError::SignalNotFound)?;
|
||||||
debug_span!("Handle signal").in_scope(|| {
|
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
|
||||||
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
|
error: error.to_string(),
|
||||||
error: error.to_string(),
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,6 +223,7 @@ impl Node {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> {
|
pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> {
|
||||||
self.aliases
|
self.aliases
|
||||||
.get_valid_contents()
|
.get_valid_contents()
|
||||||
@@ -242,6 +242,7 @@ impl Node {
|
|||||||
.transpose()?;
|
.transpose()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn execute_remote_method(
|
pub fn execute_remote_method(
|
||||||
&self,
|
&self,
|
||||||
method: &str,
|
method: &str,
|
||||||
@@ -257,3 +258,11 @@ impl Node {
|
|||||||
Ok(async { future.await.map_err(|e| eyre!(e)) })
|
Ok(async { future.await.map_err(|e| eyre!(e)) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Debug for Node {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("Node")
|
||||||
|
.field("uid", &self.uid)
|
||||||
|
.field("path", &self.path)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,14 +73,14 @@ impl Spatial {
|
|||||||
Ok(spatial_arc)
|
Ok(spatial_arc)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn space_to_space_matrix(from: Option<&Spatial>, to: Option<&Spatial>) -> Mat4 {
|
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 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());
|
let world_to_space_matrix = to.map_or(Mat4::IDENTITY, |to| to.global_transform().inverse());
|
||||||
world_to_space_matrix * space_to_world_matrix
|
world_to_space_matrix * space_to_world_matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn local_transform(&self) -> Mat4 {
|
pub fn local_transform(&self) -> Mat4 {
|
||||||
*self.transform.lock()
|
*self.transform.lock()
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ impl Spatial {
|
|||||||
pub fn set_local_transform(&self, transform: Mat4) {
|
pub fn set_local_transform(&self, transform: Mat4) {
|
||||||
*self.transform.lock() = transform;
|
*self.transform.lock() = transform;
|
||||||
}
|
}
|
||||||
#[instrument]
|
#[instrument(level = "debug", skip(self, reference_space))]
|
||||||
pub fn set_local_transform_components(
|
pub fn set_local_transform_components(
|
||||||
&self,
|
&self,
|
||||||
reference_space: Option<&Spatial>,
|
reference_space: Option<&Spatial>,
|
||||||
@@ -132,7 +132,7 @@ impl Spatial {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn is_ancestor_of(&self, spatial: Arc<Spatial>) -> bool {
|
pub fn is_ancestor_of(&self, spatial: Arc<Spatial>) -> bool {
|
||||||
let mut current_ancestor = spatial;
|
let mut current_ancestor = spatial;
|
||||||
loop {
|
loop {
|
||||||
@@ -149,7 +149,7 @@ impl Spatial {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn set_spatial_parent(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
let is_ancestor = parent
|
||||||
.map(|parent| self.is_ancestor_of(parent.clone()))
|
.map(|parent| self.is_ancestor_of(parent.clone()))
|
||||||
@@ -163,7 +163,7 @@ impl Spatial {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn set_spatial_parent_in_place(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent_in_place(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
let is_ancestor = parent
|
||||||
.map(|parent| self.is_ancestor_of(parent.clone()))
|
.map(|parent| self.is_ancestor_of(parent.clone()))
|
||||||
|
|||||||
Reference in New Issue
Block a user