summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClementTsang <clementjhtsang@gmail.com>2020-01-21 23:10:32 -0500
committerClementTsang <clementjhtsang@gmail.com>2020-01-21 23:29:47 -0500
commite6b6048afb3ddfa89d308742f0be1eb5478ecf5c (patch)
tree6b512d00f99c70ffffb2f715e83538f452126113 /src
parent1339df81e1a9f9fcb7b7e934d54370607c313fda (diff)
Further tweaking of network
Diffstat (limited to 'src')
-rw-r--r--src/app/data_collection.rs19
-rw-r--r--src/app/data_collection/network.rs19
2 files changed, 29 insertions, 9 deletions
diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs
index 8d3c4dbe..0d07e084 100644
--- a/src/app/data_collection.rs
+++ b/src/app/data_collection.rs
@@ -37,6 +37,22 @@ pub struct Data {
pub list_of_disks: Vec<disks::DiskData>,
}
+impl Data {
+ pub fn first_run_cleanup(&mut self) {
+ self.list_of_cpu_packages = Vec::new();
+ self.list_of_io = Vec::new();
+ self.list_of_physical_io = Vec::new();
+ self.memory = Vec::new();
+ self.swap = Vec::new();
+ self.list_of_temperature_sensor = Vec::new();
+ self.list_of_processes = Vec::new();
+ self.grouped_list_of_processes = None;
+ self.list_of_disks = Vec::new();
+
+ self.network.first_run();
+ }
+}
+
pub struct DataState {
pub data: Data,
first_run: bool,
@@ -110,7 +126,6 @@ impl DataState {
.get(&self.data.network.last_collection_time)
{
// If not empty, inject joining points
-
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 time_gap = current_instant
@@ -188,7 +203,7 @@ impl DataState {
);
if self.first_run {
- self.data = Data::default();
+ self.data.first_run_cleanup();
self.first_run = false;
}
diff --git a/src/app/data_collection/network.rs b/src/app/data_collection/network.rs
index c9b97de6..da646ad2 100644
--- a/src/app/data_collection/network.rs
+++ b/src/app/data_collection/network.rs
@@ -35,6 +35,14 @@ impl Default for NetworkStorage {
}
}
+impl NetworkStorage {
+ pub fn first_run(&mut self) {
+ self.data_points = BTreeMap::default();
+ self.rx = 0;
+ self.tx = 0;
+ }
+}
+
#[derive(Clone, Debug)]
/// Note all values are in bytes...
pub struct NetworkData {
@@ -68,13 +76,10 @@ pub async fn get_network_data(
.duration_since(*prev_net_access_time)
.as_secs_f64();
- if *prev_net_rx == 0 {
- *prev_net_rx = net_rx;
- }
-
- if *prev_net_tx == 0 {
- *prev_net_tx = net_tx;
- }
+ 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 tx = ((net_tx - *prev_net_tx) as f64 / elapsed_time) as u64;