feat: span tracing!!!
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::scenegraph::Scenegraph;
|
||||
use crate::{
|
||||
core::registry::OwnedRegistry,
|
||||
core::{registry::OwnedRegistry, task},
|
||||
nodes::{
|
||||
data, drawable, fields, hmd, input, items,
|
||||
root::Root,
|
||||
@@ -119,12 +119,14 @@ impl Client {
|
||||
})
|
||||
.unwrap_or_else(|| "??".to_string());
|
||||
let _ = client.dispatch_join_handle.get_or_try_init(|| {
|
||||
tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"client dispatch pid={} exe={}",
|
||||
&pid_printable, &exe_printable,
|
||||
))
|
||||
.spawn({
|
||||
task::new(
|
||||
|| {
|
||||
format!(
|
||||
"client dispatch pid={} exe={}",
|
||||
&pid_printable, &exe_printable,
|
||||
)
|
||||
},
|
||||
{
|
||||
let client = client.clone();
|
||||
async move {
|
||||
loop {
|
||||
@@ -136,15 +138,13 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
});
|
||||
let _ = client.flush_join_handle.get_or_try_init(|| {
|
||||
tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"client flush pid={} exe={}",
|
||||
&pid_printable, &exe_printable,
|
||||
))
|
||||
.spawn({
|
||||
task::new(
|
||||
|| format!("client flush pid={} exe={}", &pid_printable, &exe_printable,),
|
||||
{
|
||||
let client = client.clone();
|
||||
async move {
|
||||
loop {
|
||||
@@ -156,7 +156,8 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
client
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::client::Client;
|
||||
use super::task;
|
||||
use color_eyre::eyre::Result;
|
||||
use once_cell::sync::OnceCell;
|
||||
use stardust_xr::server;
|
||||
@@ -26,14 +27,12 @@ impl EventLoop {
|
||||
join_handle: OnceCell::new(),
|
||||
});
|
||||
|
||||
let join_handle = tokio::task::Builder::new()
|
||||
.name("event loop")
|
||||
.spawn(async move {
|
||||
loop {
|
||||
let Ok((socket, _)) = socket.accept().await else { continue };
|
||||
Client::from_connection(socket);
|
||||
}
|
||||
})?;
|
||||
let join_handle = task::new(|| "event loop", async move {
|
||||
loop {
|
||||
let Ok((socket, _)) = socket.accept().await else { continue };
|
||||
Client::from_connection(socket);
|
||||
}
|
||||
})?;
|
||||
let _ = event_loop.join_handle.set(join_handle);
|
||||
|
||||
Ok(event_loop)
|
||||
|
||||
@@ -6,3 +6,4 @@ pub mod node_collections;
|
||||
pub mod registry;
|
||||
pub mod resource;
|
||||
pub mod scenegraph;
|
||||
pub mod task;
|
||||
|
||||
22
src/core/task.rs
Normal file
22
src/core/task.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use color_eyre::eyre::Result;
|
||||
use std::future::Future;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn new<
|
||||
F: FnOnce() -> S,
|
||||
S: AsRef<str>,
|
||||
A: Future<Output = O> + Send + 'static,
|
||||
O: Send + 'static,
|
||||
>(
|
||||
name_fn: F,
|
||||
async_future: A,
|
||||
) -> Result<JoinHandle<O>> {
|
||||
#[cfg(not(feature = "profile_tokio"))]
|
||||
let result = Ok(tokio::task::spawn(async_future));
|
||||
#[cfg(feature = "profile_tokio")]
|
||||
let result = tokio::task::Builder::new()
|
||||
.name(name_fn().as_ref())
|
||||
.spawn(async_future);
|
||||
result
|
||||
}
|
||||
Reference in New Issue
Block a user