mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
get rid of a lazy_static and update agent multithreaded metrics
This commit is contained in:
parent
2b2ac2da05
commit
1fd0e15e29
@ -10,7 +10,7 @@ pub enum ParMode {
|
|||||||
None, /* Job is not running at all */
|
None, /* Job is not running at all */
|
||||||
Single,
|
Single,
|
||||||
Rayon,
|
Rayon,
|
||||||
Exact(u16),
|
Exact(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make use of the phase of a system for advanced scheduling and logging
|
//TODO: make use of the phase of a system for advanced scheduling and logging
|
||||||
@ -54,7 +54,7 @@ pub struct CpuTimeStats {
|
|||||||
/// isn't running. `Single` means you are running single threaded.
|
/// isn't running. `Single` means you are running single threaded.
|
||||||
/// `Rayon` means you are running on the rayon threadpool.
|
/// `Rayon` means you are running on the rayon threadpool.
|
||||||
impl ParMode {
|
impl ParMode {
|
||||||
fn threads(&self, rayon_threads: u16) -> u16 {
|
fn threads(&self, rayon_threads: u32) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
ParMode::None => 0,
|
ParMode::None => 0,
|
||||||
ParMode::Single => 1,
|
ParMode::Single => 1,
|
||||||
@ -144,8 +144,8 @@ impl CpuTimeStats {
|
|||||||
pub fn gen_stats(
|
pub fn gen_stats(
|
||||||
timelines: &HashMap<String, CpuTimeline>,
|
timelines: &HashMap<String, CpuTimeline>,
|
||||||
tick_work_start: Instant,
|
tick_work_start: Instant,
|
||||||
rayon_threads: u16,
|
rayon_threads: u32,
|
||||||
physical_threads: u16,
|
physical_threads: u32,
|
||||||
) -> HashMap<String, CpuTimeStats> {
|
) -> HashMap<String, CpuTimeStats> {
|
||||||
let mut result = HashMap::new();
|
let mut result = HashMap::new();
|
||||||
let mut all = timelines
|
let mut all = timelines
|
||||||
@ -171,7 +171,7 @@ pub fn gen_stats(
|
|||||||
let total = individual_cores_wanted
|
let total = individual_cores_wanted
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, a)| a)
|
.map(|(_, a)| a)
|
||||||
.sum::<u16>()
|
.sum::<u32>()
|
||||||
.max(1) as f32;
|
.max(1) as f32;
|
||||||
let total_or_max = total.max(physical_threads as f32);
|
let total_or_max = total.max(physical_threads as f32);
|
||||||
// update ALL states
|
// update ALL states
|
||||||
@ -309,8 +309,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single() {
|
fn single() {
|
||||||
const RAYON_THREADS: u16 = 4;
|
const RAYON_THREADS: u32 = 4;
|
||||||
const PHYSICAL_THREADS: u16 = RAYON_THREADS;
|
const PHYSICAL_THREADS: u32 = RAYON_THREADS;
|
||||||
let tick_start = Instant::now();
|
let tick_start = Instant::now();
|
||||||
let job_d = vec![(500, 1500, ParMode::Rayon)];
|
let job_d = vec![(500, 1500, ParMode::Rayon)];
|
||||||
let timelines = mock_timelines(tick_start, job_d);
|
let timelines = mock_timelines(tick_start, job_d);
|
||||||
@ -336,8 +336,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn two_jobs() {
|
fn two_jobs() {
|
||||||
const RAYON_THREADS: u16 = 8;
|
const RAYON_THREADS: u32 = 8;
|
||||||
const PHYSICAL_THREADS: u16 = RAYON_THREADS;
|
const PHYSICAL_THREADS: u32 = RAYON_THREADS;
|
||||||
let tick_start = Instant::now();
|
let tick_start = Instant::now();
|
||||||
let job_d = vec![(2000, 3000, ParMode::Single), (5000, 6500, ParMode::Single)];
|
let job_d = vec![(2000, 3000, ParMode::Single), (5000, 6500, ParMode::Single)];
|
||||||
let timelines = mock_timelines(tick_start, job_d);
|
let timelines = mock_timelines(tick_start, job_d);
|
||||||
@ -375,8 +375,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_stats() {
|
fn generate_stats() {
|
||||||
const RAYON_THREADS: u16 = 6;
|
const RAYON_THREADS: u32 = 6;
|
||||||
const PHYSICAL_THREADS: u16 = RAYON_THREADS;
|
const PHYSICAL_THREADS: u32 = RAYON_THREADS;
|
||||||
let tick_start = Instant::now();
|
let tick_start = Instant::now();
|
||||||
let job_d = vec![
|
let job_d = vec![
|
||||||
(2000, 5000, ParMode::Rayon),
|
(2000, 5000, ParMode::Rayon),
|
||||||
|
@ -118,6 +118,12 @@ struct SpawnPoint(Vec3<f32>);
|
|||||||
#[derive(Copy, Clone, Default)]
|
#[derive(Copy, Clone, Default)]
|
||||||
pub struct Tick(u64);
|
pub struct Tick(u64);
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct HwStats {
|
||||||
|
hardware_threads: u32,
|
||||||
|
rayon_threads: u32,
|
||||||
|
}
|
||||||
|
|
||||||
// Start of Tick, used for metrics
|
// Start of Tick, used for metrics
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct TickStart(Instant);
|
pub struct TickStart(Instant);
|
||||||
@ -178,6 +184,10 @@ impl Server {
|
|||||||
state
|
state
|
||||||
.ecs_mut()
|
.ecs_mut()
|
||||||
.insert(LoginProvider::new(settings.auth_server_address.clone()));
|
.insert(LoginProvider::new(settings.auth_server_address.clone()));
|
||||||
|
state.ecs_mut().insert(HwStats {
|
||||||
|
hardware_threads: num_cpus::get() as u32,
|
||||||
|
rayon_threads: num_cpus::get() as u32,
|
||||||
|
});
|
||||||
state.ecs_mut().insert(Tick(0));
|
state.ecs_mut().insert(Tick(0));
|
||||||
state.ecs_mut().insert(TickStart(Instant::now()));
|
state.ecs_mut().insert(TickStart(Instant::now()));
|
||||||
state.ecs_mut().insert(network_request_metrics);
|
state.ecs_mut().insert(network_request_metrics);
|
||||||
|
@ -23,7 +23,7 @@ use common::{
|
|||||||
util::Dir,
|
util::Dir,
|
||||||
vol::ReadVol,
|
vol::ReadVol,
|
||||||
};
|
};
|
||||||
use common_ecs::{Job, Origin, Phase, System};
|
use common_ecs::{Job, Origin, ParMode, Phase, System};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use rayon::iter::ParallelIterator;
|
use rayon::iter::ParallelIterator;
|
||||||
use specs::{
|
use specs::{
|
||||||
@ -113,9 +113,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587
|
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587
|
||||||
fn run(
|
fn run(
|
||||||
_job: &mut Job<Self>,
|
job: &mut Job<Self>,
|
||||||
(read_data, event_bus, mut agents, mut controllers): Self::SystemData,
|
(read_data, event_bus, mut agents, mut controllers): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
|
job.cpu_stats.measure(ParMode::Rayon);
|
||||||
(
|
(
|
||||||
&read_data.entities,
|
&read_data.entities,
|
||||||
(&read_data.energies, &read_data.healths),
|
(&read_data.energies, &read_data.healths),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
metrics::{EcsSystemMetrics, PhysicsMetrics, TickMetrics},
|
metrics::{EcsSystemMetrics, PhysicsMetrics, TickMetrics},
|
||||||
Tick, TickStart,
|
HwStats, Tick, TickStart,
|
||||||
};
|
};
|
||||||
use common::{resources::TimeOfDay, terrain::TerrainGrid};
|
use common::{resources::TimeOfDay, terrain::TerrainGrid};
|
||||||
use common_ecs::{Job, Origin, Phase, SysMetrics, System};
|
use common_ecs::{Job, Origin, Phase, SysMetrics, System};
|
||||||
@ -14,6 +14,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
Option<Entities<'a>>,
|
Option<Entities<'a>>,
|
||||||
|
ReadExpect<'a, HwStats>,
|
||||||
ReadExpect<'a, Tick>,
|
ReadExpect<'a, Tick>,
|
||||||
ReadExpect<'a, TimeOfDay>,
|
ReadExpect<'a, TimeOfDay>,
|
||||||
ReadExpect<'a, TickStart>,
|
ReadExpect<'a, TickStart>,
|
||||||
@ -33,6 +34,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
_job: &mut Job<Self>,
|
_job: &mut Job<Self>,
|
||||||
(
|
(
|
||||||
entities,
|
entities,
|
||||||
|
hw_stats,
|
||||||
tick,
|
tick,
|
||||||
time_of_day,
|
time_of_day,
|
||||||
tick_start,
|
tick_start,
|
||||||
@ -52,11 +54,12 @@ impl<'a> System<'a> for Sys {
|
|||||||
//this system hasn't run yet
|
//this system hasn't run yet
|
||||||
state.remove(Self::NAME);
|
state.remove(Self::NAME);
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
for (name, stat) in common_ecs::gen_stats(
|
||||||
static ref THREADS: u16 = num_cpus::get() as u16;
|
&state,
|
||||||
}
|
tick_start.0,
|
||||||
|
hw_stats.rayon_threads,
|
||||||
for (name, stat) in common_ecs::gen_stats(&state, tick_start.0, *THREADS, *THREADS) {
|
hw_stats.hardware_threads,
|
||||||
|
) {
|
||||||
export_ecs
|
export_ecs
|
||||||
.system_start_time
|
.system_start_time
|
||||||
.with_label_values(&[&name])
|
.with_label_values(&[&name])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user