Merge branch 'xMAC94x/metrics_fixes' into 'master'

get rid of a lazy_static and update agent multithreaded metrics

See merge request veloren/veloren!1865
This commit is contained in:
Marcel 2021-03-09 12:59:00 +00:00
commit f6028f4ae3
4 changed files with 33 additions and 19 deletions

View File

@ -10,7 +10,7 @@ pub enum ParMode {
None, /* Job is not running at all */
Single,
Rayon,
Exact(u16),
Exact(u32),
}
//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.
/// `Rayon` means you are running on the rayon threadpool.
impl ParMode {
fn threads(&self, rayon_threads: u16) -> u16 {
fn threads(&self, rayon_threads: u32) -> u32 {
match self {
ParMode::None => 0,
ParMode::Single => 1,
@ -144,8 +144,8 @@ impl CpuTimeStats {
pub fn gen_stats(
timelines: &HashMap<String, CpuTimeline>,
tick_work_start: Instant,
rayon_threads: u16,
physical_threads: u16,
rayon_threads: u32,
physical_threads: u32,
) -> HashMap<String, CpuTimeStats> {
let mut result = HashMap::new();
let mut all = timelines
@ -171,7 +171,7 @@ pub fn gen_stats(
let total = individual_cores_wanted
.iter()
.map(|(_, a)| a)
.sum::<u16>()
.sum::<u32>()
.max(1) as f32;
let total_or_max = total.max(physical_threads as f32);
// update ALL states
@ -309,8 +309,8 @@ mod tests {
#[test]
fn single() {
const RAYON_THREADS: u16 = 4;
const PHYSICAL_THREADS: u16 = RAYON_THREADS;
const RAYON_THREADS: u32 = 4;
const PHYSICAL_THREADS: u32 = RAYON_THREADS;
let tick_start = Instant::now();
let job_d = vec![(500, 1500, ParMode::Rayon)];
let timelines = mock_timelines(tick_start, job_d);
@ -336,8 +336,8 @@ mod tests {
#[test]
fn two_jobs() {
const RAYON_THREADS: u16 = 8;
const PHYSICAL_THREADS: u16 = RAYON_THREADS;
const RAYON_THREADS: u32 = 8;
const PHYSICAL_THREADS: u32 = RAYON_THREADS;
let tick_start = Instant::now();
let job_d = vec![(2000, 3000, ParMode::Single), (5000, 6500, ParMode::Single)];
let timelines = mock_timelines(tick_start, job_d);
@ -375,8 +375,8 @@ mod tests {
#[test]
fn generate_stats() {
const RAYON_THREADS: u16 = 6;
const PHYSICAL_THREADS: u16 = RAYON_THREADS;
const RAYON_THREADS: u32 = 6;
const PHYSICAL_THREADS: u32 = RAYON_THREADS;
let tick_start = Instant::now();
let job_d = vec![
(2000, 5000, ParMode::Rayon),

View File

@ -118,6 +118,12 @@ struct SpawnPoint(Vec3<f32>);
#[derive(Copy, Clone, Default)]
pub struct Tick(u64);
#[derive(Clone)]
pub struct HwStats {
hardware_threads: u32,
rayon_threads: u32,
}
// Start of Tick, used for metrics
#[derive(Copy, Clone)]
pub struct TickStart(Instant);
@ -178,6 +184,10 @@ impl Server {
state
.ecs_mut()
.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(TickStart(Instant::now()));
state.ecs_mut().insert(network_request_metrics);

View File

@ -23,7 +23,7 @@ use common::{
util::Dir,
vol::ReadVol,
};
use common_ecs::{Job, Origin, Phase, System};
use common_ecs::{Job, Origin, ParMode, Phase, System};
use rand::{thread_rng, Rng};
use rayon::iter::ParallelIterator;
use specs::{
@ -113,9 +113,10 @@ impl<'a> System<'a> for Sys {
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587
fn run(
_job: &mut Job<Self>,
job: &mut Job<Self>,
(read_data, event_bus, mut agents, mut controllers): Self::SystemData,
) {
job.cpu_stats.measure(ParMode::Rayon);
(
&read_data.entities,
(&read_data.energies, &read_data.healths),

View File

@ -1,6 +1,6 @@
use crate::{
metrics::{EcsSystemMetrics, PhysicsMetrics, TickMetrics},
Tick, TickStart,
HwStats, Tick, TickStart,
};
use common::{resources::TimeOfDay, terrain::TerrainGrid};
use common_ecs::{Job, Origin, Phase, SysMetrics, System};
@ -14,6 +14,7 @@ impl<'a> System<'a> for Sys {
#[allow(clippy::type_complexity)]
type SystemData = (
Option<Entities<'a>>,
ReadExpect<'a, HwStats>,
ReadExpect<'a, Tick>,
ReadExpect<'a, TimeOfDay>,
ReadExpect<'a, TickStart>,
@ -33,6 +34,7 @@ impl<'a> System<'a> for Sys {
_job: &mut Job<Self>,
(
entities,
hw_stats,
tick,
time_of_day,
tick_start,
@ -52,11 +54,12 @@ impl<'a> System<'a> for Sys {
//this system hasn't run yet
state.remove(Self::NAME);
lazy_static::lazy_static! {
static ref THREADS: u16 = num_cpus::get() as u16;
}
for (name, stat) in common_ecs::gen_stats(&state, tick_start.0, *THREADS, *THREADS) {
for (name, stat) in common_ecs::gen_stats(
&state,
tick_start.0,
hw_stats.rayon_threads,
hw_stats.hardware_threads,
) {
export_ecs
.system_start_time
.with_label_values(&[&name])