From e37a01be9d79971a2cfbb52bf47acae1e4ad2437 Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 26 Aug 2020 04:11:31 -0400 Subject: [PATCH] Sprinkle instrumentation in common crate,in particular in the ecs systems --- common/src/path.rs | 2 ++ common/src/ray.rs | 6 +++++- common/src/region.rs | 6 +++++- common/src/sys/agent.rs | 2 ++ common/src/sys/character_behavior.rs | 2 ++ common/src/sys/combat.rs | 2 ++ common/src/sys/controller.rs | 2 ++ common/src/sys/mount.rs | 2 ++ common/src/sys/phys.rs | 9 ++++++++- common/src/sys/projectile.rs | 2 ++ common/src/sys/stats.rs | 2 ++ voxygen/src/mesh/terrain.rs | 2 +- 12 files changed, 35 insertions(+), 4 deletions(-) diff --git a/common/src/path.rs b/common/src/path.rs index cf02e684ae..cdad9bdbc9 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -1,5 +1,6 @@ use crate::{ astar::{Astar, PathResult}, + span, terrain::Block, vol::{BaseVol, ReadVol}, }; @@ -327,6 +328,7 @@ impl Chaser { where V: BaseVol + ReadVol, { + span!(_guard, "Chaser::chase"); let pos_to_tgt = pos.distance(tgt); // If we're already close to the target then there's nothing to do diff --git a/common/src/ray.rs b/common/src/ray.rs index f0e412975e..91588e8d1f 100644 --- a/common/src/ray.rs +++ b/common/src/ray.rs @@ -1,4 +1,7 @@ -use crate::vol::{ReadVol, Vox}; +use crate::{ + span, + vol::{ReadVol, Vox}, +}; use vek::*; pub trait RayUntil = FnMut(&V) -> bool; @@ -52,6 +55,7 @@ impl<'a, V: ReadVol, F: RayUntil, G: RayForEach> Ray<'a, V, F, G } pub fn cast(mut self) -> (f32, Result, V::Error>) { + span!(_guard, "Ray::cast"); // TODO: Fully test this! const PLANCK: f32 = 0.001; diff --git a/common/src/region.rs b/common/src/region.rs index 4a36a49179..34ca7e2130 100644 --- a/common/src/region.rs +++ b/common/src/region.rs @@ -1,4 +1,7 @@ -use crate::comp::{Pos, Vel}; +use crate::{ + comp::{Pos, Vel}, + span, +}; use hashbrown::{hash_map::DefaultHashBuilder, HashSet}; use indexmap::IndexMap; use specs::{hibitset::BitSetLike, BitSet, Entities, Join, ReadStorage}; @@ -104,6 +107,7 @@ impl RegionMap { // TODO maintain within a system? // TODO special case large entities pub fn tick(&mut self, pos: ReadStorage, vel: ReadStorage, entities: Entities) { + span!(_guard, "Region::tick"); self.tick += 1; // Clear events within each region for i in 0..self.regions.len() { diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 6078121477..48cdfd66c1 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -11,6 +11,7 @@ use crate::{ }, event::{EventBus, ServerEvent}, path::{Chaser, TraversalConfig}, + span, state::{DeltaTime, Time}, sync::{Uid, UidAllocator}, terrain::TerrainGrid, @@ -116,6 +117,7 @@ impl<'a> System<'a> for Sys { ) .join() { + span!(_guard, "agent::Sys::run"); // Hack, replace with better system when groups are more sophisticated // Override alignment if in a group unless entity is owned already let alignment = if !matches!(alignment, Some(Alignment::Owned(_))) { diff --git a/common/src/sys/character_behavior.rs b/common/src/sys/character_behavior.rs index 591a46e227..d8865b2b89 100644 --- a/common/src/sys/character_behavior.rs +++ b/common/src/sys/character_behavior.rs @@ -4,6 +4,7 @@ use crate::{ Loadout, Mounting, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel, }, event::{EventBus, LocalEvent, ServerEvent}, + span, state::DeltaTime, states, sync::{Uid, UidAllocator}, @@ -183,6 +184,7 @@ impl<'a> System<'a> for Sys { mountings, ): Self::SystemData, ) { + span!(_guard, "character_behavior::Sys::run"); let mut server_emitter = server_bus.emitter(); let mut local_emitter = local_bus.emitter(); diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index e8d83e9847..770051ae02 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -4,6 +4,7 @@ use crate::{ Loadout, Ori, Pos, Scale, Stats, }, event::{EventBus, LocalEvent, ServerEvent}, + span, sync::Uid, util::Dir, }; @@ -52,6 +53,7 @@ impl<'a> System<'a> for Sys { character_states, ): Self::SystemData, ) { + span!(_guard, "combat::Sys::run"); let mut server_emitter = server_bus.emitter(); let mut local_emitter = local_bus.emitter(); // Attacks diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index 055f7e8dd4..d24f5f0912 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -4,6 +4,7 @@ use crate::{ CharacterState, ControlEvent, Controller, InventoryManip, }, event::{EventBus, LocalEvent, ServerEvent}, + span, state::DeltaTime, sync::{Uid, UidAllocator}, }; @@ -43,6 +44,7 @@ impl<'a> System<'a> for Sys { uids, ): Self::SystemData, ) { + span!(_guard, "controller::Sys::run"); let mut server_emitter = server_bus.emitter(); for (entity, _uid, controller, character_state) in diff --git a/common/src/sys/mount.rs b/common/src/sys/mount.rs index e40a77be0b..9133743bac 100644 --- a/common/src/sys/mount.rs +++ b/common/src/sys/mount.rs @@ -1,5 +1,6 @@ use crate::{ comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, + span, sync::UidAllocator, }; use specs::{ @@ -36,6 +37,7 @@ impl<'a> System<'a> for Sys { mut orientations, ): Self::SystemData, ) { + span!(_guard, "mount::Sys::run"); // Mounted entities. for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() { match mount_states.get_unchecked() { diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index dd2f99af4e..4083c74514 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -95,10 +95,11 @@ impl<'a> System<'a> for Sys { projectiles, ): Self::SystemData, ) { - span!(_guard, "::run"); + span!(_guard, "phys::Sys::run"); let mut event_emitter = event_bus.emitter(); // Add/reset physics state components + span!(guard, "Add/reset physics state components"); for (entity, _, _, _, _) in ( &entities, &colliders, @@ -112,6 +113,7 @@ impl<'a> System<'a> for Sys { .entry(entity) .map(|e| e.or_insert_with(Default::default)); } + drop(guard); // Apply pushback // @@ -126,6 +128,7 @@ impl<'a> System<'a> for Sys { // terrain collision code below, although that's not trivial to do since // it means the step needs to take into account the speeds of both // entities. + span!(guard, "Apply pushback"); for (entity, pos, scale, mass, collider, _, _, physics, projectile) in ( &entities, &positions, @@ -246,8 +249,10 @@ impl<'a> System<'a> for Sys { .get_mut(entity) .map(|vel| vel.0 += vel_delta * dt.0); } + drop(guard); // Apply movement inputs + span!(guard, "Apply movement and terrain collision"); let land_on_grounds = ( &entities, scales.maybe(), @@ -349,6 +354,7 @@ impl<'a> System<'a> for Sys { radius: f32, z_range: Range, ) -> impl Iterator> + 'a { + span!(_guard, "collision_iter"); near_iter.filter_map(move |(i, j, k)| { let block_pos = pos.map(|e| e.floor() as i32) + Vec3::new(i, j, k); @@ -648,6 +654,7 @@ impl<'a> System<'a> for Sys { land_on_grounds_a.append(&mut land_on_grounds_b); land_on_grounds_a }); + drop(guard); land_on_grounds.into_iter().for_each(|(entity, vel)| { event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 }); diff --git a/common/src/sys/projectile.rs b/common/src/sys/projectile.rs index 3d70aa18fc..35425df8a0 100644 --- a/common/src/sys/projectile.rs +++ b/common/src/sys/projectile.rs @@ -4,6 +4,7 @@ use crate::{ Loadout, Ori, PhysicsState, Pos, Projectile, Vel, }, event::{EventBus, LocalEvent, ServerEvent}, + span, state::DeltaTime, sync::UidAllocator, util::Dir, @@ -48,6 +49,7 @@ impl<'a> System<'a> for Sys { loadouts, ): Self::SystemData, ) { + span!(_guard, "projectile::Sys::run"); let mut local_emitter = local_bus.emitter(); let mut server_emitter = server_bus.emitter(); diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 8576754f59..d262d0fc04 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -1,6 +1,7 @@ use crate::{ comp::{CharacterState, Energy, EnergySource, HealthSource, Stats}, event::{EventBus, ServerEvent}, + span, state::DeltaTime, }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; @@ -24,6 +25,7 @@ impl<'a> System<'a> for Sys { &mut self, (entities, dt, server_event_bus, character_states, mut stats, mut energies): Self::SystemData, ) { + span!(_guard, "stats::Sys::run"); let mut server_event_emitter = server_event_bus.emitter(); // Increment last change timer diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 7abcb15e0b..c9242df5a1 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -242,7 +242,7 @@ impl<'a, V: RectRasterableVol + ReadVol + Debug> self, (range, max_texture_size): Self::Supplement, ) -> MeshGen { - span!(_guard, "<&VolGrid2d as Meshable<_, _>::generate_mesh"); + span!(_guard, "<&VolGrid2d as Meshable<_, _>>::generate_mesh"); // Find blocks that should glow // FIXME: Replace with real lit blocks when we actually have blocks that glow. let lit_blocks = core::iter::empty();