Skip to content

Commit

Permalink
Use ring buffer for tps monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul1365972 authored and StackDoubleFlow committed Jan 3, 2024
1 parent ab90e7e commit ac1e4d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/core/src/plot/monitor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@ struct MonitorData {
too_slow: AtomicBool,
ticking: AtomicBool,
running: AtomicBool,
timings_record: Mutex<Vec<u32>>,
timings_record: Mutex<VecDeque<u32>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -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);
}
})
}
Expand Down

0 comments on commit ac1e4d6

Please sign in to comment.