mirror of
https://github.com/ClementTsang/bottom
synced 2025-02-17 05:38:27 +00:00
Removed btreemap and went back to vec as it makes more sense for us
This commit is contained in:
parent
e6b6048afb
commit
fe99b99d0a
2 changed files with 7 additions and 16 deletions
|
@ -119,13 +119,9 @@ impl DataState {
|
||||||
|
|
||||||
let joining_points: Option<Vec<network::NetworkJoinPoint>> =
|
let joining_points: Option<Vec<network::NetworkJoinPoint>> =
|
||||||
if !self.data.network.data_points.is_empty() {
|
if !self.data.network.data_points.is_empty() {
|
||||||
if let Some(prev_data) = self
|
if let Some(last_entry) = self.data.network.data_points.last() {
|
||||||
.data
|
|
||||||
.network
|
|
||||||
.data_points
|
|
||||||
.get(&self.data.network.last_collection_time)
|
|
||||||
{
|
|
||||||
// If not empty, inject joining points
|
// If not empty, inject joining points
|
||||||
|
let prev_data = &last_entry.1;
|
||||||
let rx_diff = new_network_data.rx as f64 - prev_data.0.rx as f64;
|
let rx_diff = new_network_data.rx as f64 - prev_data.0.rx as f64;
|
||||||
let tx_diff = new_network_data.tx as f64 - prev_data.0.tx as f64;
|
let tx_diff = new_network_data.tx as f64 - prev_data.0.tx as f64;
|
||||||
let time_gap = current_instant
|
let time_gap = current_instant
|
||||||
|
@ -161,7 +157,7 @@ impl DataState {
|
||||||
self.data
|
self.data
|
||||||
.network
|
.network
|
||||||
.data_points
|
.data_points
|
||||||
.insert(current_instant, (new_network_data, joining_points));
|
.push((current_instant, (new_network_data, joining_points)));
|
||||||
|
|
||||||
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
|
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
|
||||||
push_if_valid(
|
push_if_valid(
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use heim::net;
|
use heim::net;
|
||||||
use heim::units::information::byte;
|
use heim::units::information::byte;
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use sysinfo::{NetworkExt, System, SystemExt};
|
use sysinfo::{NetworkExt, System, SystemExt};
|
||||||
|
|
||||||
|
@ -12,9 +11,10 @@ pub struct NetworkJoinPoint {
|
||||||
pub time_offset_milliseconds: f64,
|
pub time_offset_milliseconds: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NetworkDataGroup = (Instant, (NetworkData, Option<Vec<NetworkJoinPoint>>));
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct NetworkStorage {
|
pub struct NetworkStorage {
|
||||||
pub data_points: BTreeMap<Instant, (NetworkData, Option<Vec<NetworkJoinPoint>>)>,
|
pub data_points: Vec<NetworkDataGroup>,
|
||||||
pub rx: u64,
|
pub rx: u64,
|
||||||
pub tx: u64,
|
pub tx: u64,
|
||||||
pub total_rx: u64,
|
pub total_rx: u64,
|
||||||
|
@ -25,7 +25,7 @@ pub struct NetworkStorage {
|
||||||
impl Default for NetworkStorage {
|
impl Default for NetworkStorage {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
NetworkStorage {
|
NetworkStorage {
|
||||||
data_points: BTreeMap::default(),
|
data_points: Vec::default(),
|
||||||
rx: 0,
|
rx: 0,
|
||||||
tx: 0,
|
tx: 0,
|
||||||
total_rx: 0,
|
total_rx: 0,
|
||||||
|
@ -37,7 +37,7 @@ impl Default for NetworkStorage {
|
||||||
|
|
||||||
impl NetworkStorage {
|
impl NetworkStorage {
|
||||||
pub fn first_run(&mut self) {
|
pub fn first_run(&mut self) {
|
||||||
self.data_points = BTreeMap::default();
|
self.data_points = Vec::default();
|
||||||
self.rx = 0;
|
self.rx = 0;
|
||||||
self.tx = 0;
|
self.tx = 0;
|
||||||
}
|
}
|
||||||
|
@ -76,11 +76,6 @@ pub async fn get_network_data(
|
||||||
.duration_since(*prev_net_access_time)
|
.duration_since(*prev_net_access_time)
|
||||||
.as_secs_f64();
|
.as_secs_f64();
|
||||||
|
|
||||||
debug!(
|
|
||||||
"net rx: {}, net tx: {}, net prev rx: {}, net prev tx: {}",
|
|
||||||
net_rx, net_tx, *prev_net_rx, *prev_net_tx
|
|
||||||
);
|
|
||||||
|
|
||||||
let rx = ((net_rx - *prev_net_rx) as f64 / elapsed_time) as u64;
|
let rx = ((net_rx - *prev_net_rx) as f64 / elapsed_time) as u64;
|
||||||
let tx = ((net_tx - *prev_net_tx) as f64 / elapsed_time) as u64;
|
let tx = ((net_tx - *prev_net_tx) as f64 / elapsed_time) as u64;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue