Added a counter for the ms complete of reify loop
This commit is contained in:
@@ -19,9 +19,12 @@ use stardust_xr_fusion::{
|
|||||||
};
|
};
|
||||||
use std::f32::consts::{FRAC_PI_2, PI};
|
use std::f32::consts::{FRAC_PI_2, PI};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::sync::atomic::AtomicU64;
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
|
|
||||||
static REIFY_COUNT: AtomicUsize = AtomicUsize::new(0);
|
static REIFY_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
static REIFY_TOTAL_NS: AtomicU64 = AtomicU64::new(0);
|
||||||
|
static APP_REIFY_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
@@ -34,7 +37,15 @@ async fn main() {
|
|||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
let v = REIFY_COUNT.swap(0, Ordering::Relaxed);
|
let v = REIFY_COUNT.swap(0, Ordering::Relaxed);
|
||||||
tracing::info!(reify_per_sec = v, "hexagon reify rate");
|
let total_ns = REIFY_TOTAL_NS.swap(0, Ordering::Relaxed);
|
||||||
|
let app_hits = APP_REIFY_COUNT.swap(0, Ordering::Relaxed);
|
||||||
|
let avg_ns = if v > 0 { total_ns / (v as u64) } else { 0 };
|
||||||
|
tracing::info!(
|
||||||
|
reify_per_sec = v,
|
||||||
|
avg_reify_ms = (avg_ns as f64) / 1_000_000.0,
|
||||||
|
app_reify_hits = app_hits,
|
||||||
|
"hexagon reify stats"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,64 +114,82 @@ impl ClientState for HexagonLauncher {
|
|||||||
impl Reify for HexagonLauncher {
|
impl Reify for HexagonLauncher {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
fn reify(&self) -> impl Element<Self> {
|
fn reify(&self) -> impl Element<Self> {
|
||||||
// increment counter so we can observe how often reify is called
|
// measure reify latency and count
|
||||||
REIFY_COUNT.fetch_add(1, Ordering::Relaxed);
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
// Build UI based on current state
|
// Build UI based on current state
|
||||||
Grabbable::new(
|
let elem = Grabbable::new(
|
||||||
Shape::Cylinder(CylinderShape {
|
Shape::Cylinder(CylinderShape {
|
||||||
radius: APP_SIZE / 2.0,
|
radius: APP_SIZE / 2.0,
|
||||||
length: 0.01,
|
length: 0.01,
|
||||||
}),
|
}),
|
||||||
self.pos,
|
self.pos,
|
||||||
self.rot,
|
self.rot,
|
||||||
|state: &mut Self, pos, rot| {
|
|state: &mut Self, pos, rot| {
|
||||||
state.pos = pos;
|
// only update if changed enough to avoid constant reify
|
||||||
state.rot = rot;
|
let dx = (state.pos.x - pos.x).abs();
|
||||||
},
|
let dy = (state.pos.y - pos.y).abs();
|
||||||
)
|
let dz = (state.pos.z - pos.z).abs();
|
||||||
.field_transform(Transform::from_rotation(Quat::from_rotation_x(FRAC_PI_2)))
|
if dx > 0.0005 || dy > 0.0005 || dz > 0.0005 {
|
||||||
.pointer_mode(PointerMode::Align)
|
tracing::trace!(?pos, "updating grab position");
|
||||||
.reparentable(true)
|
state.pos = pos;
|
||||||
.build()
|
}
|
||||||
.child(
|
// rotation updates can also be debounced if noisy
|
||||||
Button::new(|state: &mut HexagonLauncher| {
|
state.rot = rot;
|
||||||
state.open = !state.open;
|
},
|
||||||
})
|
)
|
||||||
.pos([0.0, 0.0, 0.005])
|
.field_transform(Transform::from_rotation(Quat::from_rotation_x(FRAC_PI_2)))
|
||||||
.size([APP_SIZE / 2.0; 2])
|
.pointer_mode(PointerMode::Align)
|
||||||
.build(),
|
.reparentable(true)
|
||||||
)
|
.build()
|
||||||
.child(
|
.child(
|
||||||
Model::namespaced("protostar", "hexagon/hexagon")
|
Button::new(|state: &mut HexagonLauncher| {
|
||||||
.transform(Transform::from_rotation_scale(
|
state.open = !state.open;
|
||||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
tracing::debug!(open = state.open, "toggled hexagon open");
|
||||||
[MODEL_SCALE; 3],
|
})
|
||||||
))
|
.pos([0.0, 0.0, 0.005])
|
||||||
.part(ModelPart::new("Hex").mat_param(
|
.size([APP_SIZE / 2.0; 2])
|
||||||
"color",
|
.build(),
|
||||||
MaterialParameter::Color(if self.open {
|
)
|
||||||
BTN_SELECTED_COLOR
|
.child(
|
||||||
} else {
|
Model::namespaced("protostar", "hexagon/hexagon")
|
||||||
BTN_COLOR
|
.transform(Transform::from_rotation_scale(
|
||||||
}),
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
))
|
[MODEL_SCALE; 3],
|
||||||
.build(),
|
))
|
||||||
)
|
.part(ModelPart::new("Hex").mat_param(
|
||||||
.children(
|
"color",
|
||||||
self.open
|
MaterialParameter::Color(if self.open {
|
||||||
.then(|| {
|
BTN_SELECTED_COLOR
|
||||||
self.apps.iter().enumerate().map(|(i, app)| {
|
} else {
|
||||||
Spatial::default()
|
BTN_COLOR
|
||||||
.pos(Hex::spiral(i + 1).get_coords())
|
}),
|
||||||
.build()
|
))
|
||||||
.child(app.reify_substate(move |state: &mut HexagonLauncher| {
|
.build(),
|
||||||
state.apps.get_mut(i)
|
)
|
||||||
}))
|
.children(
|
||||||
})
|
self.open
|
||||||
})
|
.then(|| {
|
||||||
.into_iter()
|
self.apps.iter().enumerate().map(|(i, app)| {
|
||||||
.flatten(),
|
Spatial::default()
|
||||||
)
|
.pos(Hex::spiral(i + 1).get_coords())
|
||||||
|
.build()
|
||||||
|
.child(app.reify_substate(move |state: &mut HexagonLauncher| {
|
||||||
|
// log & count access to per-app substate
|
||||||
|
APP_REIFY_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
|
tracing::trace!(index = i, "accessing app substate");
|
||||||
|
state.apps.get_mut(i)
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.into_iter()
|
||||||
|
.flatten(),
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
let elapsed = start.elapsed().as_nanos() as u64;
|
||||||
|
REIFY_TOTAL_NS.fetch_add(elapsed, Ordering::Relaxed);
|
||||||
|
REIFY_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
|
elem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user