From ac1e4d66c9e9bddeffc77a78f32f17e497929f2d Mon Sep 17 00:00:00 2001 From: Paul1365972 Date: Sun, 3 Dec 2023 22:55:50 +0100 Subject: [PATCH] Use ring buffer for tps monitoring --- crates/core/src/plot/monitor.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/core/src/plot/monitor.rs b/crates/core/src/plot/monitor.rs index 221bfe16..bc0b1b70 100644 --- a/crates/core/src/plot/monitor.rs +++ b/crates/core/src/plot/monitor.rs @@ -1,4 +1,5 @@ use mchprs_save_data::plot_data::Tps; +use std::collections::VecDeque; use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; use std::thread; @@ -44,7 +45,7 @@ struct MonitorData { too_slow: AtomicBool, ticking: AtomicBool, running: AtomicBool, - timings_record: Mutex>, + timings_record: Mutex>, } #[derive(Debug)] @@ -195,9 +196,9 @@ impl TimingsMonitor { // have a max size of 1800 entries. let mut timings_record = data.timings_record.lock().unwrap(); if timings_record.len() == 1800 { - timings_record.pop(); + timings_record.pop_back(); } - timings_record.insert(0, ticks_passed); + timings_record.push_front(ticks_passed); } }) }