mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
add detailed information on state tick timings
This commit is contained in:
@ -28,6 +28,7 @@ pub mod figure;
|
|||||||
pub mod generation;
|
pub mod generation;
|
||||||
pub mod loadout_builder;
|
pub mod loadout_builder;
|
||||||
pub mod lottery;
|
pub mod lottery;
|
||||||
|
pub mod metrics;
|
||||||
pub mod msg;
|
pub mod msg;
|
||||||
pub mod npc;
|
pub mod npc;
|
||||||
pub mod outcome;
|
pub mod outcome;
|
||||||
|
13
common/src/metrics.rs
Normal file
13
common/src/metrics.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use std::sync::atomic::AtomicI64;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct SysMetrics {
|
||||||
|
pub agent_ns: AtomicI64,
|
||||||
|
pub mount_ns: AtomicI64,
|
||||||
|
pub controller_ns: AtomicI64,
|
||||||
|
pub character_behavior_ns: AtomicI64,
|
||||||
|
pub stats_ns: AtomicI64,
|
||||||
|
pub phys_ns: AtomicI64,
|
||||||
|
pub projectile_ns: AtomicI64,
|
||||||
|
pub combat_ns: AtomicI64,
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp,
|
comp,
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
region::RegionMap,
|
region::RegionMap,
|
||||||
sync::WorldSyncExt,
|
sync::WorldSyncExt,
|
||||||
sys,
|
sys,
|
||||||
@ -176,6 +177,7 @@ impl State {
|
|||||||
ecs.insert(EventBus::<ServerEvent>::default());
|
ecs.insert(EventBus::<ServerEvent>::default());
|
||||||
ecs.insert(comp::group::GroupManager::default());
|
ecs.insert(comp::group::GroupManager::default());
|
||||||
ecs.insert(RegionMap::new());
|
ecs.insert(RegionMap::new());
|
||||||
|
ecs.insert(SysMetrics::default());
|
||||||
|
|
||||||
ecs
|
ecs
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ use crate::{
|
|||||||
Vel,
|
Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
path::{Chaser, TraversalConfig},
|
path::{Chaser, TraversalConfig},
|
||||||
span,
|
span,
|
||||||
state::{DeltaTime, Time},
|
state::{DeltaTime, Time},
|
||||||
@ -34,6 +35,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, Time>,
|
Read<'a, Time>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, group::GroupManager>,
|
Read<'a, group::GroupManager>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
Write<'a, EventBus<ServerEvent>>,
|
Write<'a, EventBus<ServerEvent>>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
ReadStorage<'a, Pos>,
|
ReadStorage<'a, Pos>,
|
||||||
@ -63,6 +65,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
time,
|
time,
|
||||||
dt,
|
dt,
|
||||||
group_manager,
|
group_manager,
|
||||||
|
sys_metrics,
|
||||||
event_bus,
|
event_bus,
|
||||||
entities,
|
entities,
|
||||||
positions,
|
positions,
|
||||||
@ -84,6 +87,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
invites,
|
invites,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "agent::Sys::run");
|
span!(_guard, "run", "agent::Sys::run");
|
||||||
for (
|
for (
|
||||||
entity,
|
entity,
|
||||||
@ -572,5 +576,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
.push(ControlEvent::GroupManip(GroupManip::Decline));
|
.push(ControlEvent::GroupManip(GroupManip::Decline));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sys_metrics.agent_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use crate::{
|
|||||||
Loadout, Mounting, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel,
|
Loadout, Mounting, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
states,
|
states,
|
||||||
@ -13,7 +14,8 @@ use crate::{
|
|||||||
use specs::{
|
use specs::{
|
||||||
hibitset,
|
hibitset,
|
||||||
storage::{PairedStorage, SequentialRestriction},
|
storage::{PairedStorage, SequentialRestriction},
|
||||||
Entities, Entity, FlaggedStorage, Join, LazyUpdate, Read, ReadStorage, System, WriteStorage,
|
Entities, Entity, FlaggedStorage, Join, LazyUpdate, Read, ReadExpect, ReadStorage, System,
|
||||||
|
WriteStorage,
|
||||||
};
|
};
|
||||||
use specs_idvs::IdvStorage;
|
use specs_idvs::IdvStorage;
|
||||||
|
|
||||||
@ -144,6 +146,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, EventBus<LocalEvent>>,
|
Read<'a, EventBus<LocalEvent>>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, LazyUpdate>,
|
Read<'a, LazyUpdate>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
WriteStorage<'a, CharacterState>,
|
WriteStorage<'a, CharacterState>,
|
||||||
WriteStorage<'a, Pos>,
|
WriteStorage<'a, Pos>,
|
||||||
WriteStorage<'a, Vel>,
|
WriteStorage<'a, Vel>,
|
||||||
@ -169,6 +172,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
local_bus,
|
local_bus,
|
||||||
dt,
|
dt,
|
||||||
updater,
|
updater,
|
||||||
|
sys_metrics,
|
||||||
mut character_states,
|
mut character_states,
|
||||||
mut positions,
|
mut positions,
|
||||||
mut velocities,
|
mut velocities,
|
||||||
@ -184,6 +188,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
mountings,
|
mountings,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "character_behavior::Sys::run");
|
span!(_guard, "run", "character_behavior::Sys::run");
|
||||||
let mut server_emitter = server_bus.emitter();
|
let mut server_emitter = server_bus.emitter();
|
||||||
let mut local_emitter = local_bus.emitter();
|
let mut local_emitter = local_bus.emitter();
|
||||||
@ -287,5 +292,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
server_emitter.append(&mut state_update.server_events);
|
server_emitter.append(&mut state_update.server_events);
|
||||||
incorporate_update(&mut tuple, state_update);
|
incorporate_update(&mut tuple, state_update);
|
||||||
}
|
}
|
||||||
|
sys_metrics.character_behavior_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,12 @@ use crate::{
|
|||||||
Loadout, Ori, Pos, Scale, Stats,
|
Loadout, Ori, Pos, Scale, Stats,
|
||||||
},
|
},
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
sync::Uid,
|
sync::Uid,
|
||||||
util::Dir,
|
util::Dir,
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
pub const BLOCK_EFFICIENCY: f32 = 0.9;
|
pub const BLOCK_EFFICIENCY: f32 = 0.9;
|
||||||
@ -23,6 +24,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
Read<'a, EventBus<LocalEvent>>,
|
Read<'a, EventBus<LocalEvent>>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
ReadStorage<'a, Uid>,
|
ReadStorage<'a, Uid>,
|
||||||
ReadStorage<'a, Pos>,
|
ReadStorage<'a, Pos>,
|
||||||
ReadStorage<'a, Ori>,
|
ReadStorage<'a, Ori>,
|
||||||
@ -41,6 +43,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
entities,
|
entities,
|
||||||
server_bus,
|
server_bus,
|
||||||
local_bus,
|
local_bus,
|
||||||
|
sys_metrics,
|
||||||
uids,
|
uids,
|
||||||
positions,
|
positions,
|
||||||
orientations,
|
orientations,
|
||||||
@ -53,6 +56,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
character_states,
|
character_states,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "combat::Sys::run");
|
span!(_guard, "run", "combat::Sys::run");
|
||||||
let mut server_emitter = server_bus.emitter();
|
let mut server_emitter = server_bus.emitter();
|
||||||
let mut local_emitter = local_bus.emitter();
|
let mut local_emitter = local_bus.emitter();
|
||||||
@ -160,5 +164,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sys_metrics.combat_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@ use crate::{
|
|||||||
CharacterState, ControlEvent, Controller, InventoryManip,
|
CharacterState, ControlEvent, Controller, InventoryManip,
|
||||||
},
|
},
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
sync::{Uid, UidAllocator},
|
sync::{Uid, UidAllocator},
|
||||||
};
|
};
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::{Marker, MarkerAllocator},
|
saveload::{Marker, MarkerAllocator},
|
||||||
Entities, Join, Read, ReadStorage, System, WriteStorage,
|
Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage,
|
||||||
};
|
};
|
||||||
|
|
||||||
// const CHARGE_COST: i32 = 200;
|
// const CHARGE_COST: i32 = 200;
|
||||||
@ -26,6 +27,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
Read<'a, EventBus<LocalEvent>>,
|
Read<'a, EventBus<LocalEvent>>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteStorage<'a, CharacterState>,
|
WriteStorage<'a, CharacterState>,
|
||||||
ReadStorage<'a, Uid>,
|
ReadStorage<'a, Uid>,
|
||||||
@ -39,11 +41,13 @@ impl<'a> System<'a> for Sys {
|
|||||||
server_bus,
|
server_bus,
|
||||||
_local_bus,
|
_local_bus,
|
||||||
_dt,
|
_dt,
|
||||||
|
sys_metrics,
|
||||||
mut controllers,
|
mut controllers,
|
||||||
mut character_states,
|
mut character_states,
|
||||||
uids,
|
uids,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "controller::Sys::run");
|
span!(_guard, "run", "controller::Sys::run");
|
||||||
let mut server_emitter = server_bus.emitter();
|
let mut server_emitter = server_bus.emitter();
|
||||||
|
|
||||||
@ -105,5 +109,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sys_metrics.controller_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{Controller, MountState, Mounting, Ori, Pos, Vel},
|
comp::{Controller, MountState, Mounting, Ori, Pos, Vel},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
sync::UidAllocator,
|
sync::UidAllocator,
|
||||||
};
|
};
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::{Marker, MarkerAllocator},
|
saveload::{Marker, MarkerAllocator},
|
||||||
Entities, Join, Read, System, WriteStorage,
|
Entities, Join, Read, ReadExpect, System, WriteStorage,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
Read<'a, UidAllocator>,
|
Read<'a, UidAllocator>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteStorage<'a, MountState>,
|
WriteStorage<'a, MountState>,
|
||||||
@ -28,6 +30,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
&mut self,
|
&mut self,
|
||||||
(
|
(
|
||||||
uid_allocator,
|
uid_allocator,
|
||||||
|
sys_metrics,
|
||||||
entities,
|
entities,
|
||||||
mut controllers,
|
mut controllers,
|
||||||
mut mount_state,
|
mut mount_state,
|
||||||
@ -37,6 +40,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut orientations,
|
mut orientations,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "mount::Sys::run");
|
span!(_guard, "run", "mount::Sys::run");
|
||||||
// Mounted entities.
|
// Mounted entities.
|
||||||
for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() {
|
for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() {
|
||||||
@ -88,5 +92,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
for entity in to_unmount {
|
for entity in to_unmount {
|
||||||
mountings.remove(entity);
|
mountings.remove(entity);
|
||||||
}
|
}
|
||||||
|
sys_metrics.mount_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use crate::{
|
|||||||
Sticky, Vel,
|
Sticky, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
sync::{Uid, UidAllocator},
|
sync::{Uid, UidAllocator},
|
||||||
@ -55,6 +56,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadExpect<'a, TerrainGrid>,
|
ReadExpect<'a, TerrainGrid>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, UidAllocator>,
|
Read<'a, UidAllocator>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
ReadStorage<'a, Scale>,
|
ReadStorage<'a, Scale>,
|
||||||
ReadStorage<'a, Sticky>,
|
ReadStorage<'a, Sticky>,
|
||||||
@ -80,6 +82,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
terrain,
|
terrain,
|
||||||
dt,
|
dt,
|
||||||
uid_allocator,
|
uid_allocator,
|
||||||
|
sys_metrics,
|
||||||
event_bus,
|
event_bus,
|
||||||
scales,
|
scales,
|
||||||
stickies,
|
stickies,
|
||||||
@ -95,6 +98,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
projectiles,
|
projectiles,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "phys::Sys::run");
|
span!(_guard, "run", "phys::Sys::run");
|
||||||
let mut event_emitter = event_bus.emitter();
|
let mut event_emitter = event_bus.emitter();
|
||||||
|
|
||||||
@ -658,5 +662,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
land_on_grounds.into_iter().for_each(|(entity, vel)| {
|
land_on_grounds.into_iter().for_each(|(entity, vel)| {
|
||||||
event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 });
|
event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 });
|
||||||
});
|
});
|
||||||
|
sys_metrics.phys_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,15 @@ use crate::{
|
|||||||
Loadout, Ori, PhysicsState, Pos, Projectile, Vel,
|
Loadout, Ori, PhysicsState, Pos, Projectile, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
sync::UidAllocator,
|
sync::UidAllocator,
|
||||||
util::Dir,
|
util::Dir,
|
||||||
};
|
};
|
||||||
use specs::{saveload::MarkerAllocator, Entities, Join, Read, ReadStorage, System, WriteStorage};
|
use specs::{
|
||||||
|
saveload::MarkerAllocator, Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage,
|
||||||
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -23,6 +26,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, UidAllocator>,
|
Read<'a, UidAllocator>,
|
||||||
Read<'a, EventBus<LocalEvent>>,
|
Read<'a, EventBus<LocalEvent>>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
ReadStorage<'a, Pos>,
|
ReadStorage<'a, Pos>,
|
||||||
ReadStorage<'a, PhysicsState>,
|
ReadStorage<'a, PhysicsState>,
|
||||||
ReadStorage<'a, Vel>,
|
ReadStorage<'a, Vel>,
|
||||||
@ -40,6 +44,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
uid_allocator,
|
uid_allocator,
|
||||||
local_bus,
|
local_bus,
|
||||||
server_bus,
|
server_bus,
|
||||||
|
sys_metrics,
|
||||||
positions,
|
positions,
|
||||||
physics_states,
|
physics_states,
|
||||||
velocities,
|
velocities,
|
||||||
@ -49,6 +54,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
loadouts,
|
loadouts,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "projectile::Sys::run");
|
span!(_guard, "run", "projectile::Sys::run");
|
||||||
let mut local_emitter = local_bus.emitter();
|
let mut local_emitter = local_bus.emitter();
|
||||||
let mut server_emitter = server_bus.emitter();
|
let mut server_emitter = server_bus.emitter();
|
||||||
@ -190,5 +196,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
.checked_sub(Duration::from_secs_f32(dt.0))
|
.checked_sub(Duration::from_secs_f32(dt.0))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
}
|
}
|
||||||
|
sys_metrics.projectile_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{CharacterState, Energy, EnergySource, HealthSource, Stats},
|
comp::{CharacterState, Energy, EnergySource, HealthSource, Stats},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
||||||
|
|
||||||
const ENERGY_REGEN_ACCEL: f32 = 10.0;
|
const ENERGY_REGEN_ACCEL: f32 = 10.0;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
|
ReadExpect<'a, SysMetrics>,
|
||||||
ReadStorage<'a, CharacterState>,
|
ReadStorage<'a, CharacterState>,
|
||||||
WriteStorage<'a, Stats>,
|
WriteStorage<'a, Stats>,
|
||||||
WriteStorage<'a, Energy>,
|
WriteStorage<'a, Energy>,
|
||||||
@ -23,8 +25,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&mut self,
|
&mut self,
|
||||||
(entities, dt, server_event_bus, character_states, mut stats, mut energies): Self::SystemData,
|
(entities, dt, server_event_bus, sys_metrics, character_states, mut stats, mut energies): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "stats::Sys::run");
|
span!(_guard, "run", "stats::Sys::run");
|
||||||
let mut server_event_emitter = server_event_bus.emitter();
|
let mut server_event_emitter = server_event_bus.emitter();
|
||||||
|
|
||||||
@ -133,5 +136,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
CharacterState::Roll { .. } | CharacterState::Climb { .. } => {},
|
CharacterState::Roll { .. } | CharacterState::Climb { .. } => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sys_metrics.stats_ns.store(
|
||||||
|
start_time.elapsed().as_nanos() as i64,
|
||||||
|
std::sync::atomic::Ordering::Relaxed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,14 +45,14 @@ use common::{
|
|||||||
use futures_executor::block_on;
|
use futures_executor::block_on;
|
||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use futures_util::{select, FutureExt};
|
use futures_util::{select, FutureExt};
|
||||||
use metrics::{ServerMetrics, TickMetrics};
|
use metrics::{ServerMetrics, StateTickMetrics, TickMetrics};
|
||||||
use network::{Network, Pid, ProtocolAddr};
|
use network::{Network, Pid, ProtocolAddr};
|
||||||
use persistence::character::{CharacterLoader, CharacterLoaderResponseType, CharacterUpdater};
|
use persistence::character::{CharacterLoader, CharacterLoaderResponseType, CharacterUpdater};
|
||||||
use specs::{join::Join, Builder, Entity as EcsEntity, RunNow, SystemData, WorldExt};
|
use specs::{join::Join, Builder, Entity as EcsEntity, RunNow, SystemData, WorldExt};
|
||||||
use std::{
|
use std::{
|
||||||
i32,
|
i32,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
sync::Arc,
|
sync::{atomic::Ordering, Arc},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
#[cfg(not(feature = "worldgen"))]
|
#[cfg(not(feature = "worldgen"))]
|
||||||
@ -90,6 +90,7 @@ pub struct Server {
|
|||||||
|
|
||||||
metrics: ServerMetrics,
|
metrics: ServerMetrics,
|
||||||
tick_metrics: TickMetrics,
|
tick_metrics: TickMetrics,
|
||||||
|
state_tick_metrics: StateTickMetrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
@ -286,10 +287,13 @@ impl Server {
|
|||||||
// register all metrics submodules here
|
// register all metrics submodules here
|
||||||
let (tick_metrics, registry_tick) = TickMetrics::new(metrics.tick_clone())
|
let (tick_metrics, registry_tick) = TickMetrics::new(metrics.tick_clone())
|
||||||
.expect("Failed to initialize server tick metrics submodule.");
|
.expect("Failed to initialize server tick metrics submodule.");
|
||||||
|
let (state_tick_metrics, registry_state) = StateTickMetrics::new().unwrap();
|
||||||
|
|
||||||
registry_chunk(&metrics.registry()).expect("failed to register chunk gen metrics");
|
registry_chunk(&metrics.registry()).expect("failed to register chunk gen metrics");
|
||||||
registry_network(&metrics.registry()).expect("failed to register network request metrics");
|
registry_network(&metrics.registry()).expect("failed to register network request metrics");
|
||||||
registry_player(&metrics.registry()).expect("failed to register player metrics");
|
registry_player(&metrics.registry()).expect("failed to register player metrics");
|
||||||
registry_tick(&metrics.registry()).expect("failed to register tick metrics");
|
registry_tick(&metrics.registry()).expect("failed to register tick metrics");
|
||||||
|
registry_state(&metrics.registry()).expect("failed to register state metrics");
|
||||||
|
|
||||||
let thread_pool = ThreadPoolBuilder::new()
|
let thread_pool = ThreadPoolBuilder::new()
|
||||||
.name("veloren-worker".to_string())
|
.name("veloren-worker".to_string())
|
||||||
@ -313,6 +317,7 @@ impl Server {
|
|||||||
|
|
||||||
metrics,
|
metrics,
|
||||||
tick_metrics,
|
tick_metrics,
|
||||||
|
state_tick_metrics,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run pending DB migrations (if any)
|
// Run pending DB migrations (if any)
|
||||||
@ -655,6 +660,59 @@ impl Server {
|
|||||||
.with_label_values(&["persistence:stats"])
|
.with_label_values(&["persistence:stats"])
|
||||||
.set(stats_persistence_nanos);
|
.set(stats_persistence_nanos);
|
||||||
|
|
||||||
|
//detailed state metrics
|
||||||
|
{
|
||||||
|
let res = self
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.read_resource::<common::metrics::SysMetrics>();
|
||||||
|
let c = &self.state_tick_metrics.state_tick_time_count;
|
||||||
|
let agent_ns = res.agent_ns.load(Ordering::Relaxed);
|
||||||
|
let mount_ns = res.mount_ns.load(Ordering::Relaxed);
|
||||||
|
let controller_ns = res.controller_ns.load(Ordering::Relaxed);
|
||||||
|
let character_behavior_ns = res.character_behavior_ns.load(Ordering::Relaxed);
|
||||||
|
let stats_ns = res.stats_ns.load(Ordering::Relaxed);
|
||||||
|
let phys_ns = res.phys_ns.load(Ordering::Relaxed);
|
||||||
|
let projectile_ns = res.projectile_ns.load(Ordering::Relaxed);
|
||||||
|
let combat_ns = res.combat_ns.load(Ordering::Relaxed);
|
||||||
|
|
||||||
|
c.with_label_values(&[common::sys::AGENT_SYS])
|
||||||
|
.inc_by(agent_ns);
|
||||||
|
c.with_label_values(&[common::sys::MOUNT_SYS])
|
||||||
|
.inc_by(mount_ns);
|
||||||
|
c.with_label_values(&[common::sys::CONTROLLER_SYS])
|
||||||
|
.inc_by(controller_ns);
|
||||||
|
c.with_label_values(&[common::sys::CHARACTER_BEHAVIOR_SYS])
|
||||||
|
.inc_by(character_behavior_ns);
|
||||||
|
c.with_label_values(&[common::sys::STATS_SYS])
|
||||||
|
.inc_by(stats_ns);
|
||||||
|
c.with_label_values(&[common::sys::PHYS_SYS])
|
||||||
|
.inc_by(phys_ns);
|
||||||
|
c.with_label_values(&[common::sys::PROJECTILE_SYS])
|
||||||
|
.inc_by(projectile_ns);
|
||||||
|
c.with_label_values(&[common::sys::COMBAT_SYS])
|
||||||
|
.inc_by(combat_ns);
|
||||||
|
|
||||||
|
const NANOSEC_PER_SEC: f64 = Duration::from_secs(1).as_nanos() as f64;
|
||||||
|
let h = &self.state_tick_metrics.state_tick_time_hist;
|
||||||
|
h.with_label_values(&[common::sys::AGENT_SYS])
|
||||||
|
.observe(agent_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::MOUNT_SYS])
|
||||||
|
.observe(mount_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::CONTROLLER_SYS])
|
||||||
|
.observe(controller_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::CHARACTER_BEHAVIOR_SYS])
|
||||||
|
.observe(character_behavior_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::STATS_SYS])
|
||||||
|
.observe(stats_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::PHYS_SYS])
|
||||||
|
.observe(phys_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::PROJECTILE_SYS])
|
||||||
|
.observe(projectile_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
h.with_label_values(&[common::sys::COMBAT_SYS])
|
||||||
|
.observe(combat_ns as f64 / NANOSEC_PER_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
// Report other info
|
// Report other info
|
||||||
self.tick_metrics
|
self.tick_metrics
|
||||||
.time_of_day
|
.time_of_day
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use prometheus::{
|
use prometheus::{
|
||||||
Encoder, Gauge, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Opts, Registry, TextEncoder,
|
Encoder, Gauge, HistogramOpts, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec,
|
||||||
|
Opts, Registry, TextEncoder,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
@ -16,6 +17,13 @@ use tracing::{debug, error};
|
|||||||
|
|
||||||
type RegistryFn = Box<dyn FnOnce(&Registry) -> Result<(), prometheus::Error>>;
|
type RegistryFn = Box<dyn FnOnce(&Registry) -> Result<(), prometheus::Error>>;
|
||||||
|
|
||||||
|
pub struct StateTickMetrics {
|
||||||
|
// Counter will only give us granularity on pool speed (2s?) for actuall spike detection we
|
||||||
|
// need the Historgram
|
||||||
|
pub state_tick_time_hist: HistogramVec,
|
||||||
|
pub state_tick_time_count: IntCounterVec,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PlayerMetrics {
|
pub struct PlayerMetrics {
|
||||||
pub players_connected: IntCounter,
|
pub players_connected: IntCounter,
|
||||||
pub players_disconnected: IntCounterVec, // timeout, network_error, gracefully
|
pub players_disconnected: IntCounterVec, // timeout, network_error, gracefully
|
||||||
@ -23,7 +31,7 @@ pub struct PlayerMetrics {
|
|||||||
|
|
||||||
pub struct NetworkRequestMetrics {
|
pub struct NetworkRequestMetrics {
|
||||||
pub chunks_request_dropped: IntCounter,
|
pub chunks_request_dropped: IntCounter,
|
||||||
pub chunks_served_from_cache: IntCounter,
|
pub chunks_served_from_memory: IntCounter,
|
||||||
pub chunks_generation_triggered: IntCounter,
|
pub chunks_generation_triggered: IntCounter,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +60,57 @@ pub struct ServerMetrics {
|
|||||||
tick: Arc<AtomicU64>,
|
tick: Arc<AtomicU64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StateTickMetrics {
|
||||||
|
pub fn new() -> Result<(Self, RegistryFn), prometheus::Error> {
|
||||||
|
let bucket = vec![
|
||||||
|
Duration::from_micros(1).as_secs_f64(),
|
||||||
|
Duration::from_micros(10).as_secs_f64(),
|
||||||
|
Duration::from_micros(100).as_secs_f64(),
|
||||||
|
Duration::from_micros(200).as_secs_f64(),
|
||||||
|
Duration::from_micros(400).as_secs_f64(),
|
||||||
|
Duration::from_millis(2).as_secs_f64(),
|
||||||
|
Duration::from_millis(5).as_secs_f64(),
|
||||||
|
Duration::from_millis(10).as_secs_f64(),
|
||||||
|
Duration::from_millis(20).as_secs_f64(),
|
||||||
|
Duration::from_millis(30).as_secs_f64(),
|
||||||
|
Duration::from_millis(50).as_secs_f64(),
|
||||||
|
Duration::from_millis(100).as_secs_f64(),
|
||||||
|
];
|
||||||
|
let state_tick_time_hist = HistogramVec::new(
|
||||||
|
HistogramOpts::new(
|
||||||
|
"state_tick_time_hist",
|
||||||
|
"shows the number of clients joined to the server",
|
||||||
|
)
|
||||||
|
.buckets(bucket),
|
||||||
|
&["system"],
|
||||||
|
)?;
|
||||||
|
let state_tick_time_count = IntCounterVec::new(
|
||||||
|
Opts::new(
|
||||||
|
"state_tick_time_count",
|
||||||
|
"shows the detailed time inside the `state_tick` for each system",
|
||||||
|
),
|
||||||
|
&["system"],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let state_tick_time_hist_clone = state_tick_time_hist.clone();
|
||||||
|
let state_tick_time_count_clone = state_tick_time_count.clone();
|
||||||
|
|
||||||
|
let f = |registry: &Registry| {
|
||||||
|
registry.register(Box::new(state_tick_time_hist_clone))?;
|
||||||
|
registry.register(Box::new(state_tick_time_count_clone))?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
Self {
|
||||||
|
state_tick_time_hist,
|
||||||
|
state_tick_time_count,
|
||||||
|
},
|
||||||
|
Box::new(f),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PlayerMetrics {
|
impl PlayerMetrics {
|
||||||
pub fn new() -> Result<(Self, RegistryFn), prometheus::Error> {
|
pub fn new() -> Result<(Self, RegistryFn), prometheus::Error> {
|
||||||
let players_connected = IntCounter::with_opts(Opts::new(
|
let players_connected = IntCounter::with_opts(Opts::new(
|
||||||
@ -91,8 +150,8 @@ impl NetworkRequestMetrics {
|
|||||||
"chunks_request_dropped",
|
"chunks_request_dropped",
|
||||||
"number of all chunk request dropped, e.g because the player was to far away",
|
"number of all chunk request dropped, e.g because the player was to far away",
|
||||||
))?;
|
))?;
|
||||||
let chunks_served_from_cache = IntCounter::with_opts(Opts::new(
|
let chunks_served_from_memory = IntCounter::with_opts(Opts::new(
|
||||||
"chunks_served_from_cache",
|
"chunks_served_from_memory",
|
||||||
"number of all requested chunks already generated and could be served out of cache",
|
"number of all requested chunks already generated and could be served out of cache",
|
||||||
))?;
|
))?;
|
||||||
let chunks_generation_triggered = IntCounter::with_opts(Opts::new(
|
let chunks_generation_triggered = IntCounter::with_opts(Opts::new(
|
||||||
@ -101,12 +160,12 @@ impl NetworkRequestMetrics {
|
|||||||
))?;
|
))?;
|
||||||
|
|
||||||
let chunks_request_dropped_clone = chunks_request_dropped.clone();
|
let chunks_request_dropped_clone = chunks_request_dropped.clone();
|
||||||
let chunks_served_from_cache_clone = chunks_served_from_cache.clone();
|
let chunks_served_from_memory_clone = chunks_served_from_memory.clone();
|
||||||
let chunks_generation_triggered_clone = chunks_generation_triggered.clone();
|
let chunks_generation_triggered_clone = chunks_generation_triggered.clone();
|
||||||
|
|
||||||
let f = |registry: &Registry| {
|
let f = |registry: &Registry| {
|
||||||
registry.register(Box::new(chunks_request_dropped_clone))?;
|
registry.register(Box::new(chunks_request_dropped_clone))?;
|
||||||
registry.register(Box::new(chunks_served_from_cache_clone))?;
|
registry.register(Box::new(chunks_served_from_memory_clone))?;
|
||||||
registry.register(Box::new(chunks_generation_triggered_clone))?;
|
registry.register(Box::new(chunks_generation_triggered_clone))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
@ -114,7 +173,7 @@ impl NetworkRequestMetrics {
|
|||||||
Ok((
|
Ok((
|
||||||
Self {
|
Self {
|
||||||
chunks_request_dropped,
|
chunks_request_dropped,
|
||||||
chunks_served_from_cache,
|
chunks_served_from_memory,
|
||||||
chunks_generation_triggered,
|
chunks_generation_triggered,
|
||||||
},
|
},
|
||||||
Box::new(f),
|
Box::new(f),
|
||||||
|
@ -338,7 +338,7 @@ impl Sys {
|
|||||||
if in_vd {
|
if in_vd {
|
||||||
match terrain.get_key(key) {
|
match terrain.get_key(key) {
|
||||||
Some(chunk) => {
|
Some(chunk) => {
|
||||||
network_metrics.chunks_served_from_cache.inc();
|
network_metrics.chunks_served_from_memory.inc();
|
||||||
client.notify(ServerMsg::TerrainChunkUpdate {
|
client.notify(ServerMsg::TerrainChunkUpdate {
|
||||||
key,
|
key,
|
||||||
chunk: Ok(Box::new(chunk.clone())),
|
chunk: Ok(Box::new(chunk.clone())),
|
||||||
|
Reference in New Issue
Block a user