feat: even more tracing

This commit is contained in:
Nova
2023-01-15 01:13:22 -05:00
parent ba938dfaf9
commit 75359427c9
5 changed files with 75 additions and 43 deletions

View File

@@ -5,6 +5,7 @@ use once_cell::sync::OnceCell;
use stardust_xr::scenegraph;
use stardust_xr::scenegraph::ScenegraphError;
use std::sync::{Arc, Weak};
use tracing::{debug, debug_span, instrument};
use core::hash::BuildHasherDefault;
use dashmap::DashMap;
@@ -27,10 +28,12 @@ impl Scenegraph {
node_arc
}
pub fn add_node_raw(&self, node: Arc<Node>) {
debug!(node = ?&*node, "Add node");
let path = node.get_path().to_string();
self.nodes.insert(path, node);
}
#[instrument(level = "debug", skip(self))]
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
let mut node = self.nodes.get(path)?.clone();
if let Some(alias) = node.alias.get() {
@@ -40,6 +43,7 @@ impl Scenegraph {
}
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
debug!(path, "Remove node");
let (_, node) = self.nodes.remove(path)?;
Some(node)
}
@@ -47,9 +51,11 @@ impl Scenegraph {
impl scenegraph::Scenegraph for Scenegraph {
fn send_signal(&self, path: &str, method: &str, data: &[u8]) -> Result<(), ScenegraphError> {
self.get_node(path)
.ok_or(ScenegraphError::NodeNotFound)?
.send_local_signal(self.get_client(), method, data)
debug_span!("Handle signal", path, method).in_scope(|| {
self.get_node(path)
.ok_or(ScenegraphError::NodeNotFound)?
.send_local_signal(self.get_client(), method, data)
})
}
fn execute_method(
&self,
@@ -57,8 +63,10 @@ impl scenegraph::Scenegraph for Scenegraph {
method: &str,
data: &[u8],
) -> Result<Vec<u8>, ScenegraphError> {
self.get_node(path)
.ok_or(ScenegraphError::NodeNotFound)?
.execute_local_method(self.get_client(), method, data)
debug_span!("Handle method", path, method).in_scope(|| {
self.get_node(path)
.ok_or(ScenegraphError::NodeNotFound)?
.execute_local_method(self.get_client(), method, data)
})
}
}

View File

@@ -1,8 +1,10 @@
use color_eyre::eyre::Result;
use std::future::Future;
use tokio::task::JoinHandle;
use tracing::instrument;
#[allow(unused_variables)]
#[instrument(level = "debug", skip_all)]
pub fn new<
F: FnOnce() -> S,
S: AsRef<str>,

View File

@@ -25,6 +25,7 @@ use stardust_xr::values::Transform;
use std::ops::Deref;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Weak};
use tracing::{debug_span, instrument};
static INPUT_METHOD_REGISTRY: Registry<InputMethod> = Registry::new();
static INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Registry::new();
@@ -145,6 +146,7 @@ impl DistanceLink {
fn send_input(&self, frame: u64, datamap: Datamap) {
self.handler.send_input(frame, self, datamap);
}
#[instrument(level = "debug", skip(self))]
fn serialize(&self, datamap: Datamap) -> Vec<u8> {
let input = self.method.specialization.lock().serialize(
self,
@@ -185,6 +187,7 @@ impl InputHandler {
Ok(())
}
#[instrument(level = "debug", skip(self, distance_link))]
fn send_input(&self, frame: u64, distance_link: &DistanceLink, datamap: Datamap) {
let data = distance_link.serialize(datamap);
let node = self.node.upgrade().unwrap();
@@ -250,39 +253,49 @@ pub fn create_input_handler_flex(
#[tracing::instrument(level = "debug")]
pub fn process_input() {
// Iterate over all valid input methods
for method in INPUT_METHOD_REGISTRY
.get_valid_contents()
.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
let methods = debug_span!("Get valid methods").in_scope(|| {
INPUT_METHOD_REGISTRY
.get_valid_contents()
.into_iter()
.filter(|handler| handler.field.upgrade().is_some())
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
.collect();
.filter(|method| *method.enabled.lock())
.filter(|method| method.datamap.lock().is_some())
});
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
distance_links
.sort_unstable_by(|a, b| a.distance.abs().partial_cmp(&b.distance.abs()).unwrap());
// Sort the distance links by their distance in ascending order
debug_span!("Sort distance links").in_scope(|| {
distance_links.sort_unstable_by(|a, b| {
a.distance.abs().partial_cmp(&b.distance.abs()).unwrap()
});
});
// Get the current frame
let frame = FRAME.load(Ordering::Relaxed);
// Get the current frame
let frame = FRAME.load(Ordering::Relaxed);
// Iterate over the distance links and send input to them
for distance_link in distance_links {
distance_link.send_input(frame, method.datamap.lock().clone().unwrap());
// Iterate over the distance links and send input to them
for distance_link in distance_links {
distance_link.send_input(frame, method.datamap.lock().clone().unwrap());
// 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
if method.captures.contains(&distance_link.handler) {
break;
// 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
if method.captures.contains(&distance_link.handler) {
break;
}
}
}
// Clear the list of captured input handlers for this method
method.captures.clear();
// Clear the list of captured input handlers for this method
method.captures.clear();
});
}
}

View File

@@ -15,11 +15,12 @@ use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use stardust_xr::messenger::MessageSenderHandle;
use stardust_xr::scenegraph::ScenegraphError;
use std::fmt::Debug;
use std::future::Future;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Weak};
use std::vec::Vec;
use tracing::debug_span;
use tracing::{debug_span, instrument};
use core::hash::BuildHasherDefault;
use dashmap::DashMap;
@@ -189,10 +190,8 @@ impl Node {
.local_signals
.get(method)
.ok_or(ScenegraphError::SignalNotFound)?;
debug_span!("Handle signal").in_scope(|| {
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
error: error.to_string(),
})
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
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<()> {
self.aliases
.get_valid_contents()
@@ -242,6 +242,7 @@ impl Node {
.transpose()?;
Ok(())
}
#[instrument(level = "debug", skip_all)]
pub fn execute_remote_method(
&self,
method: &str,
@@ -257,3 +258,11 @@ impl Node {
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()
}
}

View File

@@ -73,14 +73,14 @@ impl Spatial {
Ok(spatial_arc)
}
#[instrument]
#[instrument(level = "debug", skip_all)]
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]
#[instrument(level = "debug", skip_all)]
pub fn local_transform(&self) -> Mat4 {
*self.transform.lock()
}
@@ -94,7 +94,7 @@ impl Spatial {
pub fn set_local_transform(&self, transform: Mat4) {
*self.transform.lock() = transform;
}
#[instrument]
#[instrument(level = "debug", skip(self, reference_space))]
pub fn set_local_transform_components(
&self,
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 {
let mut current_ancestor = spatial;
loop {
@@ -149,7 +149,7 @@ impl Spatial {
}
}
#[instrument]
#[instrument(level = "debug", skip_all)]
pub fn set_spatial_parent(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
let is_ancestor = parent
.map(|parent| self.is_ancestor_of(parent.clone()))
@@ -163,7 +163,7 @@ impl Spatial {
Ok(())
}
#[instrument]
#[instrument(level = "debug", skip_all)]
pub fn set_spatial_parent_in_place(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
let is_ancestor = parent
.map(|parent| self.is_ancestor_of(parent.clone()))