From 902ed9a8391f6567718c83391bff567434069591 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sat, 12 Oct 2019 19:19:53 -0400 Subject: [PATCH] Separated stale and display constants. --- .travis.yml | 6 ------ src/app/data_collection.rs | 7 ++----- src/canvas.rs | 11 +++++++---- src/constants.rs | 4 ++-- src/convert_data.rs | 8 ++++---- src/main.rs | 3 +-- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index cd33a1f1..ec07db4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,9 +37,6 @@ matrix: rust: nightly before_script: rustup target add $TARGET script: cargo build --release --target $TARGET - on: - branch: master - tags: true addons: apt: packages: @@ -52,9 +49,6 @@ matrix: rust: nightly before_script: rustup target add $TARGET script: cargo build --release --target $TARGET - on: - branch: master - tags: true <<: *DEPLOY_TO_GITHUB notifications: diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index b46e39bc..42b7a661 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -1,5 +1,6 @@ //! This is the main file to house data collection functions. +use crate::constants; use std::{collections::HashMap, time::Instant}; use sysinfo::{System, SystemExt}; @@ -53,7 +54,7 @@ impl Default for DataState { data : Data::default(), first_run : true, sys : System::new(), - stale_max_seconds : 60, + stale_max_seconds : constants::STALE_MAX_MILLISECONDS / 1000, prev_pid_stats : HashMap::new(), prev_idle : 0_f64, prev_non_idle : 0_f64, @@ -64,10 +65,6 @@ impl Default for DataState { } impl DataState { - pub fn set_stale_max_seconds(&mut self, stale_max_seconds : u64) { - self.stale_max_seconds = stale_max_seconds; - } - pub fn set_temperature_type(&mut self, temperature_type : temperature::TemperatureType) { self.temperature_type = temperature_type; } diff --git a/src/canvas.rs b/src/canvas.rs index ae60873a..33c136a0 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -1,3 +1,4 @@ +use crate::{app, constants, utils::error}; use tui_temp_fork::{ backend, layout::{Alignment, Constraint, Direction, Layout}, @@ -6,8 +7,6 @@ use tui_temp_fork::{ Terminal, }; -use crate::{app, utils::error}; - const COLOUR_LIST : [Color; 6] = [ Color::Red, Color::Green, @@ -110,7 +109,9 @@ pub fn draw_data(terminal : &mut Terminal, app_state : // Set up blocks and their components // CPU usage graph { - let x_axis : Axis = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]); + let x_axis : Axis = Axis::default() + .style(Style::default().fg(GRAPH_COLOUR)) + .bounds([0.0, constants::TIME_STARTS_FROM as f64 * 10.0]); let y_axis = Axis::default() .style(Style::default().fg(GRAPH_COLOUR)) .bounds([-0.5, 100.5]) @@ -167,7 +168,9 @@ pub fn draw_data(terminal : &mut Terminal, app_state : //Memory usage graph { - let x_axis : Axis = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]); + let x_axis : Axis = Axis::default() + .style(Style::default().fg(GRAPH_COLOUR)) + .bounds([0.0, constants::TIME_STARTS_FROM as f64 * 10.0]); let y_axis = Axis::default() .style(Style::default().fg(GRAPH_COLOUR)) .bounds([-0.5, 100.5]) // Offset as the zero value isn't drawn otherwise... diff --git a/src/constants.rs b/src/constants.rs index 7e6646df..98ab6aaf 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,5 +1,5 @@ // TODO: Store like three minutes of data, then change how much is shown based on scaling! -pub const STALE_MAX_MILLISECONDS : u64 = 60 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable. -pub const _TIME_STARTS_FROM : u64 = 60 * 1000; // TODO: Fix this +pub const STALE_MAX_MILLISECONDS : u64 = 180 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable. +pub const TIME_STARTS_FROM : u64 = 60 * 1000; // TODO: Fix this pub const TICK_RATE_IN_MILLISECONDS : u64 = 200; // We use this as it's a good value to work with. pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000; diff --git a/src/convert_data.rs b/src/convert_data.rs index 65b2524d..28f280d4 100644 --- a/src/convert_data.rs +++ b/src/convert_data.rs @@ -146,7 +146,7 @@ pub fn update_cpu_data_points(show_avg_cpu : bool, app_data : &data_collection:: let current_cpu_usage = data.cpu_vec[cpu_num].cpu_usage; let new_entry = ( - ((STALE_MAX_MILLISECONDS as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), + ((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), current_cpu_usage, ); @@ -221,7 +221,7 @@ fn convert_mem_data(mem_data : &[data_collection::mem::MemData]) -> Vec<(f64, f6 for data in mem_data { let current_time = std::time::Instant::now(); let new_entry = ( - ((STALE_MAX_MILLISECONDS as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), + ((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), if data.mem_total_in_mb == 0 { -1000.0 } @@ -265,11 +265,11 @@ pub fn convert_network_data_points(network_data : &[data_collection::network::Ne for data in network_data { let current_time = std::time::Instant::now(); let rx_data = ( - ((STALE_MAX_MILLISECONDS as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), + ((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), data.rx as f64 / 1024.0, ); let tx_data = ( - ((STALE_MAX_MILLISECONDS as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), + ((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(), data.tx as f64 / 1024.0, ); diff --git a/src/main.rs b/src/main.rs index ad05f8cf..cb2e4733 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ mod constants; mod convert_data; use app::data_collection; -use constants::{STALE_MAX_MILLISECONDS, TICK_RATE_IN_MILLISECONDS}; +use constants::TICK_RATE_IN_MILLISECONDS; use convert_data::*; use utils::error::{self, RustopError}; @@ -158,7 +158,6 @@ fn main() -> error::Result<()> { // Event loop let mut data_state = data_collection::DataState::default(); data_state.init(); - data_state.set_stale_max_seconds(STALE_MAX_MILLISECONDS / 1000); data_state.set_temperature_type(app.temperature_type.clone()); let (rtx, rrx) = mpsc::channel(); {