Separated stale and display constants.

This commit is contained in:
ClementTsang 2019-10-12 19:19:53 -04:00
parent 7cbb540ffc
commit 902ed9a839
6 changed files with 16 additions and 23 deletions

View File

@ -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:

View File

@ -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;
}

View File

@ -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<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
// Set up blocks and their components
// CPU usage graph
{
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
let x_axis : Axis<String> = 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<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
//Memory usage graph
{
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
let x_axis : Axis<String> = 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...

View File

@ -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;

View File

@ -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,
);

View File

@ -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();
{