Removed unsafe unwraps
This commit is contained in:
parent
042a55fcd5
commit
7bd49be49a
18
TODO.md
18
TODO.md
|
@ -2,24 +2,16 @@
|
||||||
|
|
||||||
Note this will probably migrate to GitHub's native Issues; this was mostly for personal use during early stages.
|
Note this will probably migrate to GitHub's native Issues; this was mostly for personal use during early stages.
|
||||||
|
|
||||||
## Want to do really badly
|
## Want to do
|
||||||
|
|
||||||
- Rebalance cpu usage in process by using current value (it's currently just summing to 100%)
|
|
||||||
|
|
||||||
- Travis to automate building
|
- Travis to automate building
|
||||||
|
|
||||||
- Refactoring!
|
|
||||||
|
|
||||||
- Scaling in and out (zoom), may need to show zoom levels
|
- Scaling in and out (zoom), may need to show zoom levels
|
||||||
|
|
||||||
- More keybinds (jumping, scaling, help)
|
- More keybinds (jumping, scaling, help)
|
||||||
|
|
||||||
- Tests
|
|
||||||
|
|
||||||
- ~~Add custom error because it's really messy~~ Done, but need to implement across rest of app!
|
- ~~Add custom error because it's really messy~~ Done, but need to implement across rest of app!
|
||||||
|
|
||||||
- Remove any `unwrap()`, ensure no crashing! Might have to use this: <https://doc.rust-lang.org/std/panic/fn.catch_unwind.html>
|
|
||||||
|
|
||||||
- Efficiency... for example, reduce some redraw logic if possible (ie: no changes to dir sorting)
|
- Efficiency... for example, reduce some redraw logic if possible (ie: no changes to dir sorting)
|
||||||
|
|
||||||
- Filtering in processes (that is, allow searching)
|
- Filtering in processes (that is, allow searching)
|
||||||
|
@ -30,6 +22,12 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
|
||||||
|
|
||||||
## Less important
|
## Less important
|
||||||
|
|
||||||
|
- Rebalance cpu usage in process by using current value (it's currently just summing to 100%)
|
||||||
|
|
||||||
|
- Tests
|
||||||
|
|
||||||
|
- Refactoring!
|
||||||
|
|
||||||
- Mouse + key events conflict? Make it so that some events don't clog up the loop if they are not valid keys!
|
- Mouse + key events conflict? Make it so that some events don't clog up the loop if they are not valid keys!
|
||||||
|
|
||||||
- Modularity
|
- Modularity
|
||||||
|
@ -39,3 +37,5 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
|
||||||
- Truncate columns if needed for tables
|
- Truncate columns if needed for tables
|
||||||
|
|
||||||
- Grouping by process
|
- Grouping by process
|
||||||
|
|
||||||
|
- Deal with async and stuff (remove if not needed)
|
||||||
|
|
|
@ -67,7 +67,12 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64
|
||||||
*prev_idle = idle;
|
*prev_idle = idle;
|
||||||
*prev_non_idle = non_idle;
|
*prev_non_idle = non_idle;
|
||||||
|
|
||||||
let result = if total_delta - idle_delta != 0_f64 { total_delta - idle_delta } else { 1_f64 };
|
let result = if total_delta - idle_delta != 0_f64 {
|
||||||
|
total_delta - idle_delta
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
1_f64
|
||||||
|
};
|
||||||
|
|
||||||
Ok(result) // This works, REALLY damn well. The percentage check is within like 2% of the sysinfo one.
|
Ok(result) // This works, REALLY damn well. The percentage check is within like 2% of the sysinfo one.
|
||||||
}
|
}
|
||||||
|
@ -169,7 +174,7 @@ pub async fn get_sorted_processes_list(
|
||||||
let ps_result = Command::new("ps").args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"]).output()?;
|
let ps_result = Command::new("ps").args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"]).output()?;
|
||||||
let ps_stdout = String::from_utf8_lossy(&ps_result.stdout);
|
let ps_stdout = String::from_utf8_lossy(&ps_result.stdout);
|
||||||
let split_string = ps_stdout.split('\n');
|
let split_string = ps_stdout.split('\n');
|
||||||
let cpu_usage = vangelis_cpu_usage_calculation(prev_idle, prev_non_idle).unwrap(); // TODO: FIX THIS ERROR CHECKING
|
if let Ok(cpu_usage) = vangelis_cpu_usage_calculation(prev_idle, prev_non_idle) {
|
||||||
let process_stream = split_string.collect::<Vec<&str>>();
|
let process_stream = split_string.collect::<Vec<&str>>();
|
||||||
|
|
||||||
for process in process_stream {
|
for process in process_stream {
|
||||||
|
@ -180,6 +185,7 @@ pub async fn get_sorted_processes_list(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if cfg!(target_os = "windows") {
|
else if cfg!(target_os = "windows") {
|
||||||
// Windows
|
// Windows
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,9 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
|
||||||
.style(Style::default().fg(Color::LightBlue))
|
.style(Style::default().fg(Color::LightBlue))
|
||||||
.data(&canvas_data.mem_data)];
|
.data(&canvas_data.mem_data)];
|
||||||
|
|
||||||
if !(&canvas_data.swap_data).is_empty() && (&canvas_data.swap_data).last().unwrap().1 >= 0.0 {
|
if !(&canvas_data.swap_data).is_empty() {
|
||||||
|
if let Some(last_canvas_result) = (&canvas_data.swap_data).last() {
|
||||||
|
if last_canvas_result.1 >= 0.0 {
|
||||||
swap_name = "SWP:".to_string()
|
swap_name = "SWP:".to_string()
|
||||||
+ &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
|
+ &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
|
||||||
+ &format!(
|
+ &format!(
|
||||||
|
@ -163,6 +165,8 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
|
||||||
.data(&canvas_data.swap_data),
|
.data(&canvas_data.swap_data),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Chart::default()
|
Chart::default()
|
||||||
.block(
|
.block(
|
||||||
|
|
|
@ -28,12 +28,12 @@ pub fn update_disk_row(app_data : &data_collection::Data) -> Vec<Vec<String>> {
|
||||||
let mut disk_vector : Vec<Vec<String>> = Vec::new();
|
let mut disk_vector : Vec<Vec<String>> = Vec::new();
|
||||||
for disk in &app_data.list_of_disks {
|
for disk in &app_data.list_of_disks {
|
||||||
let io_activity = if app_data.list_of_io.len() > 2 {
|
let io_activity = if app_data.list_of_io.len() > 2 {
|
||||||
let io_package = &app_data.list_of_io.last().unwrap();
|
if let Some(io_package) = &app_data.list_of_io.last() {
|
||||||
|
if let Some(trimmed_mount) = disk.name.to_string().split('/').last() {
|
||||||
let prev_io_package = &app_data.list_of_io[app_data.list_of_io.len() - 2];
|
let prev_io_package = &app_data.list_of_io[app_data.list_of_io.len() - 2];
|
||||||
|
|
||||||
let io_hashmap = &io_package.io_hash;
|
let io_hashmap = &io_package.io_hash;
|
||||||
let prev_io_hashmap = &prev_io_package.io_hash;
|
let prev_io_hashmap = &prev_io_package.io_hash;
|
||||||
let trimmed_mount = &disk.name.to_string().split('/').last().unwrap().to_string();
|
|
||||||
let time_difference = io_package.instant.duration_since(prev_io_package.instant).as_secs_f64();
|
let time_difference = io_package.instant.duration_since(prev_io_package.instant).as_secs_f64();
|
||||||
if io_hashmap.contains_key(trimmed_mount) && prev_io_hashmap.contains_key(trimmed_mount) {
|
if io_hashmap.contains_key(trimmed_mount) && prev_io_hashmap.contains_key(trimmed_mount) {
|
||||||
// Ideally change this...
|
// Ideally change this...
|
||||||
|
@ -66,6 +66,14 @@ pub fn update_disk_row(app_data : &data_collection::Data) -> Vec<Vec<String>> {
|
||||||
("0B".to_string(), "0B".to_string())
|
("0B".to_string(), "0B".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
("0B".to_string(), "0B".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
("0B".to_string(), "0B".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
("0B".to_string(), "0B".to_string())
|
("0B".to_string(), "0B".to_string())
|
||||||
};
|
};
|
||||||
|
@ -161,6 +169,7 @@ pub fn update_cpu_data_points(show_avg_cpu : bool, app_data : &data_collection::
|
||||||
|
|
||||||
// Finally, add it all onto the end
|
// Finally, add it all onto the end
|
||||||
for (i, data) in cpu_collection.iter().enumerate() {
|
for (i, data) in cpu_collection.iter().enumerate() {
|
||||||
|
if !app_data.list_of_cpu_packages.is_empty() {
|
||||||
cpu_data_vector.push((
|
cpu_data_vector.push((
|
||||||
// + 1 to skip total CPU if show_avg_cpu is false
|
// + 1 to skip total CPU if show_avg_cpu is false
|
||||||
format!(
|
format!(
|
||||||
|
@ -172,6 +181,7 @@ pub fn update_cpu_data_points(show_avg_cpu : bool, app_data : &data_collection::
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cpu_data_vector
|
cpu_data_vector
|
||||||
}
|
}
|
||||||
|
@ -287,16 +297,10 @@ pub fn convert_network_data_points(network_data : &[data_collection::network::Ne
|
||||||
|
|
||||||
rx.push(rx_data);
|
rx.push(rx_data);
|
||||||
tx.push(tx_data);
|
tx.push(tx_data);
|
||||||
|
|
||||||
//debug!("Pushed rx: ({}, {})", rx.last().unwrap().0, rx.last().unwrap().1);
|
|
||||||
//debug!("Pushed tx: ({}, {})", tx.last().unwrap().0, tx.last().unwrap().1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let rx_display = if network_data.is_empty() {
|
let rx_display = if let Some(last_num_bytes_entry) = network_data.last() {
|
||||||
"0B".to_string()
|
let num_bytes = last_num_bytes_entry.rx;
|
||||||
}
|
|
||||||
else {
|
|
||||||
let num_bytes = network_data.last().unwrap().rx;
|
|
||||||
if num_bytes < 1024 {
|
if num_bytes < 1024 {
|
||||||
format!("RX: {:4} B", num_bytes).to_string()
|
format!("RX: {:4} B", num_bytes).to_string()
|
||||||
}
|
}
|
||||||
|
@ -309,12 +313,13 @@ pub fn convert_network_data_points(network_data : &[data_collection::network::Ne
|
||||||
else {
|
else {
|
||||||
format!("RX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
|
format!("RX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
|
||||||
}
|
}
|
||||||
};
|
|
||||||
let tx_display = if network_data.is_empty() {
|
|
||||||
"0B".to_string()
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let num_bytes = network_data.last().unwrap().tx;
|
"0B".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
let tx_display = if let Some(last_num_bytes_entry) = network_data.last() {
|
||||||
|
let num_bytes = last_num_bytes_entry.tx;
|
||||||
if num_bytes < 1024 {
|
if num_bytes < 1024 {
|
||||||
format!("TX: {:4} B", num_bytes).to_string()
|
format!("TX: {:4} B", num_bytes).to_string()
|
||||||
}
|
}
|
||||||
|
@ -327,6 +332,9 @@ pub fn convert_network_data_points(network_data : &[data_collection::network::Ne
|
||||||
else {
|
else {
|
||||||
format!("TX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
|
format!("TX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
"0B".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
ConvertedNetworkData {
|
ConvertedNetworkData {
|
||||||
|
|
Loading…
Reference in New Issue