mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-29 16:44:54 +02:00
Some cleaning up in the data_conversion area for cpu
This commit is contained in:
parent
e2f2f93750
commit
4418f956c7
68
.vscode/settings.json
vendored
68
.vscode/settings.json
vendored
@ -1,35 +1,35 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"AHHHHHH",
|
"AHHHHHH",
|
||||||
"Dataset",
|
"Dataset",
|
||||||
"Ryzen",
|
"Ryzen",
|
||||||
"Tebibyte",
|
"Tebibyte",
|
||||||
"avgcpu",
|
"avgcpu",
|
||||||
"backend",
|
"backend",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"curr",
|
"curr",
|
||||||
"datasets",
|
"datasets",
|
||||||
"dword",
|
"dword",
|
||||||
"fract",
|
"fract",
|
||||||
"gotop",
|
"gotop",
|
||||||
"gtop",
|
"gtop",
|
||||||
"heim",
|
"heim",
|
||||||
"iowait",
|
"iowait",
|
||||||
"keybinds",
|
"keybinds",
|
||||||
"macos",
|
"macos",
|
||||||
"minwindef",
|
"minwindef",
|
||||||
"noheader",
|
"noheader",
|
||||||
"ntdef",
|
"ntdef",
|
||||||
"processthreadsapi",
|
"processthreadsapi",
|
||||||
"rustop",
|
"rustop",
|
||||||
"softirq",
|
"softirq",
|
||||||
"stime",
|
"stime",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"termion",
|
"termion",
|
||||||
"utime",
|
"utime",
|
||||||
"vangelis",
|
"vangelis",
|
||||||
"winapi",
|
"winapi",
|
||||||
"winnt"
|
"winnt"
|
||||||
],
|
],
|
||||||
"cSpell.language": "en,en-GB"
|
"cSpell.language": "en,en-GB"
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,10 @@ A graphical top clone, written in Rust. Inspired by both [gtop](https://github.c
|
|||||||
|
|
||||||
You can install by cloning and using `cargo build --release`, or use `cargo install bottom`.
|
You can install by cloning and using `cargo build --release`, or use `cargo install bottom`.
|
||||||
|
|
||||||
|
#### Arch Linux
|
||||||
|
|
||||||
|
You can get it from the AUR.
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
You can currently install by cloning and building yourself using `cargo build --release`, or use `cargo install bottom`
|
You can currently install by cloning and building yourself using `cargo build --release`, or use `cargo install bottom`
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
use crate::{app, constants, data_conversion::ConvertedProcessData, utils::error, utils::gen_util::*};
|
use crate::{
|
||||||
|
app, constants,
|
||||||
|
data_conversion::{ConvertedCpuData, ConvertedProcessData},
|
||||||
|
utils::{error, gen_util::*},
|
||||||
|
};
|
||||||
use tui::{
|
use tui::{
|
||||||
backend,
|
backend,
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
@ -50,7 +54,7 @@ pub struct CanvasData {
|
|||||||
pub memory_labels: Vec<(u64, u64)>,
|
pub memory_labels: Vec<(u64, u64)>,
|
||||||
pub mem_data: Vec<(f64, f64)>,
|
pub mem_data: Vec<(f64, f64)>,
|
||||||
pub swap_data: Vec<(f64, f64)>,
|
pub swap_data: Vec<(f64, f64)>,
|
||||||
pub cpu_data: Vec<(String, Vec<(f64, f64)>)>,
|
pub cpu_data: Vec<ConvertedCpuData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates random colours.
|
/// Generates random colours.
|
||||||
@ -248,7 +252,7 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, draw_loc: Rect) {
|
fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, draw_loc: Rect) {
|
||||||
let cpu_data: &[(String, Vec<(f64, f64)>)] = &app_state.canvas_data.cpu_data;
|
let cpu_data: &[ConvertedCpuData] = &app_state.canvas_data.cpu_data;
|
||||||
|
|
||||||
// CPU usage graph
|
// CPU usage graph
|
||||||
let x_axis: Axis<String> = Axis::default()
|
let x_axis: Axis<String> = Axis::default()
|
||||||
@ -260,6 +264,7 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||||||
.labels(&["0%", "100%"]);
|
.labels(&["0%", "100%"]);
|
||||||
|
|
||||||
let mut dataset_vector: Vec<Dataset> = Vec::new();
|
let mut dataset_vector: Vec<Dataset> = Vec::new();
|
||||||
|
let mut cpu_entries_vec: Vec<(Style, Vec<(f64, f64)>)> = Vec::new();
|
||||||
|
|
||||||
for (i, cpu) in cpu_data.iter().enumerate() {
|
for (i, cpu) in cpu_data.iter().enumerate() {
|
||||||
let mut avg_cpu_exist_offset = 0;
|
let mut avg_cpu_exist_offset = 0;
|
||||||
@ -272,21 +277,27 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dataset_vector.push(
|
cpu_entries_vec.push((
|
||||||
Dataset::default()
|
Style::default().fg(COLOUR_LIST[(i - avg_cpu_exist_offset) % COLOUR_LIST.len()]),
|
||||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
cpu.cpu_data.iter().map(<(f64, f64)>::from).collect::<Vec<_>>(),
|
||||||
.style(Style::default().fg(COLOUR_LIST[(i - avg_cpu_exist_offset) % COLOUR_LIST.len()]))
|
));
|
||||||
.data(&(cpu.1)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cpu_data.is_empty() && app_state.show_average_cpu {
|
if app_state.show_average_cpu {
|
||||||
// Unwrap should be safe here, this assumes that the cpu_data vector is populated...
|
if let Some(avg_cpu_entry) = cpu_data.first() {
|
||||||
|
cpu_entries_vec.push((
|
||||||
|
Style::default().fg(COLOUR_LIST[(cpu_data.len() - 1) % COLOUR_LIST.len()]),
|
||||||
|
avg_cpu_entry.cpu_data.iter().map(<(f64, f64)>::from).collect::<Vec<_>>(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for cpu_entry in &cpu_entries_vec {
|
||||||
dataset_vector.push(
|
dataset_vector.push(
|
||||||
Dataset::default()
|
Dataset::default()
|
||||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||||
.style(Style::default().fg(COLOUR_LIST[(cpu_data.len() - 1) % COLOUR_LIST.len()]))
|
.style(cpu_entry.0)
|
||||||
.data(&(cpu_data.first().unwrap().1)),
|
.data(&(cpu_entry.1)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +318,7 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
||||||
let cpu_data: &[(String, Vec<(f64, f64)>)] = &(app_state.canvas_data.cpu_data);
|
let cpu_data: &[ConvertedCpuData] = &(app_state.canvas_data.cpu_data);
|
||||||
|
|
||||||
let num_rows = i64::from(draw_loc.height) - 4;
|
let num_rows = i64::from(draw_loc.height) - 4;
|
||||||
let start_position = get_start_position(
|
let start_position = get_start_position(
|
||||||
@ -321,8 +332,8 @@ fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
|
|||||||
let mut stringified_cpu_data: Vec<Vec<String>> = Vec::new();
|
let mut stringified_cpu_data: Vec<Vec<String>> = Vec::new();
|
||||||
|
|
||||||
for cpu in sliced_cpu_data {
|
for cpu in sliced_cpu_data {
|
||||||
if let Some(cpu_data) = cpu.1.last() {
|
if let Some(cpu_data) = cpu.cpu_data.last() {
|
||||||
stringified_cpu_data.push(vec![cpu.0.clone(), format!("{:.0}%", cpu_data.1.round())]);
|
stringified_cpu_data.push(vec![cpu.cpu_name.clone(), format!("{:.0}%", cpu_data.usage.round())]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,32 @@ pub struct ConvertedProcessData {
|
|||||||
pub mem_usage: String,
|
pub mem_usage: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default, Debug)]
|
||||||
|
pub struct ConvertedCpuData {
|
||||||
|
pub cpu_name: String,
|
||||||
|
pub cpu_data: Vec<CpuPoint>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default, Debug)]
|
||||||
|
pub struct CpuPoint {
|
||||||
|
pub time: f64,
|
||||||
|
pub usage: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<CpuPoint> for (f64, f64) {
|
||||||
|
fn from(c: CpuPoint) -> (f64, f64) {
|
||||||
|
let CpuPoint { time, usage } = c;
|
||||||
|
(time, usage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&CpuPoint> for (f64, f64) {
|
||||||
|
fn from(c: &CpuPoint) -> (f64, f64) {
|
||||||
|
let CpuPoint { time, usage } = c;
|
||||||
|
(*time, *usage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_temp_row(app_data: &data_collection::Data, temp_type: &data_collection::temperature::TemperatureType) -> Vec<Vec<String>> {
|
pub fn update_temp_row(app_data: &data_collection::Data, temp_type: &data_collection::temperature::TemperatureType) -> Vec<Vec<String>> {
|
||||||
let mut sensor_vector: Vec<Vec<String>> = Vec::new();
|
let mut sensor_vector: Vec<Vec<String>> = Vec::new();
|
||||||
|
|
||||||
@ -121,33 +147,31 @@ pub fn update_process_row(app_data: &data_collection::Data) -> Vec<ConvertedProc
|
|||||||
process_vector
|
process_vector
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: You should really make this a struct...
|
pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Data) -> Vec<ConvertedCpuData> {
|
||||||
pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Data) -> Vec<(String, Vec<(f64, f64)>)> {
|
let mut cpu_data_vector: Vec<ConvertedCpuData> = Vec::new();
|
||||||
let mut cpu_data_vector: Vec<(String, Vec<(f64, f64)>)> = Vec::new();
|
let mut cpu_collection: Vec<Vec<CpuPoint>> = Vec::new();
|
||||||
let mut cpu_collection: Vec<Vec<(f64, f64)>> = Vec::new();
|
|
||||||
|
|
||||||
if !app_data.list_of_cpu_packages.is_empty() {
|
if !app_data.list_of_cpu_packages.is_empty() {
|
||||||
// I'm sorry for the following if statement but I couldn't be bothered here...
|
// I'm sorry for the following if statement but I couldn't be bothered here...
|
||||||
for cpu_num in (if show_avg_cpu { 0 } else { 1 })..app_data.list_of_cpu_packages.last().unwrap().cpu_vec.len() {
|
for cpu_num in (if show_avg_cpu { 0 } else { 1 })..app_data.list_of_cpu_packages.last().unwrap().cpu_vec.len() {
|
||||||
let mut this_cpu_data: Vec<(f64, f64)> = Vec::new();
|
let mut this_cpu_data: Vec<CpuPoint> = Vec::new();
|
||||||
|
|
||||||
for data in &app_data.list_of_cpu_packages {
|
for data in &app_data.list_of_cpu_packages {
|
||||||
let current_time = std::time::Instant::now();
|
let current_time = std::time::Instant::now();
|
||||||
let current_cpu_usage = data.cpu_vec[cpu_num].cpu_usage;
|
let current_cpu_usage = data.cpu_vec[cpu_num].cpu_usage;
|
||||||
|
|
||||||
let new_entry = (
|
let new_entry = CpuPoint {
|
||||||
((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(),
|
time: ((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(),
|
||||||
current_cpu_usage,
|
usage: current_cpu_usage,
|
||||||
);
|
};
|
||||||
|
|
||||||
// Now, inject our joining points...
|
// Now, inject our joining points...
|
||||||
if !this_cpu_data.is_empty() {
|
if let Some(previous_element_data) = this_cpu_data.last().cloned() {
|
||||||
let previous_element_data = *(this_cpu_data.last().unwrap());
|
|
||||||
for idx in 0..50 {
|
for idx in 0..50 {
|
||||||
this_cpu_data.push((
|
this_cpu_data.push(CpuPoint {
|
||||||
previous_element_data.0 + ((new_entry.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
time: previous_element_data.time + ((new_entry.time - previous_element_data.time) / 50.0 * f64::from(idx)),
|
||||||
previous_element_data.1 + ((new_entry.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
usage: previous_element_data.usage + ((new_entry.usage - previous_element_data.usage) / 50.0 * f64::from(idx)),
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +194,8 @@ pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Da
|
|||||||
// .to_uppercase() + &format!("{:3}%", (data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)),
|
// .to_uppercase() + &format!("{:3}%", (data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)),
|
||||||
// data.clone(),
|
// data.clone(),
|
||||||
// ))
|
// ))
|
||||||
cpu_data_vector.push((
|
cpu_data_vector.push(ConvertedCpuData {
|
||||||
format!(
|
cpu_name: format!(
|
||||||
"{} ",
|
"{} ",
|
||||||
if show_avg_cpu && i == 0 {
|
if show_avg_cpu && i == 0 {
|
||||||
"AVG"
|
"AVG"
|
||||||
@ -180,8 +204,8 @@ pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Da
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.to_uppercase(),
|
.to_uppercase(),
|
||||||
data.clone(),
|
cpu_data: data.clone(),
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user