summaryrefslogtreecommitdiffstats
path: root/src/data_conversion.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-08-17 12:41:37 -0700
committerGitHub <noreply@github.com>2020-08-17 15:41:37 -0400
commit3c373d7129f953242bca813a62b6e920d25f65f5 (patch)
treee474b558f0e0ab22e121e12d1788113a589e6ad8 /src/data_conversion.rs
parent59ce90f5779f63b8d21af92279189c2691a7b7d1 (diff)
feature: Add appox. total mem as an option for processes and basic mem
Adds a way to display the memory value as a column in the processes widget and the basic memory widget, rather than just the percentage.
Diffstat (limited to 'src/data_conversion.rs')
-rw-r--r--src/data_conversion.rs55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/data_conversion.rs b/src/data_conversion.rs
index 7218d305..0bf19d0b 100644
--- a/src/data_conversion.rs
+++ b/src/data_conversion.rs
@@ -34,8 +34,10 @@ pub struct ConvertedNetworkData {
pub struct ConvertedProcessData {
pub pid: u32,
pub name: String,
- pub cpu_usage: f64,
- pub mem_usage: f64,
+ pub cpu_percent_usage: f64,
+ pub mem_percent_usage: f64,
+ pub mem_usage_kb: u64,
+ pub mem_usage_str: (f64, String),
pub group_pids: Vec<u32>,
pub read_per_sec: String,
pub write_per_sec: String,
@@ -51,8 +53,9 @@ pub struct ConvertedProcessData {
#[derive(Clone, Default, Debug)]
pub struct SingleProcessData {
pub pid: u32,
- pub cpu_usage: f64,
- pub mem_usage: f64,
+ pub cpu_percent_usage: f64,
+ pub mem_percent_usage: f64,
+ pub mem_usage_kb: u64,
pub group_pids: Vec<u32>,
pub read_per_sec: u64,
pub write_per_sec: u64,
@@ -231,9 +234,11 @@ pub fn convert_swap_data_points(
result
}
-pub fn convert_mem_labels(current_data: &data_farmer::DataCollection) -> (String, String) {
- let mem_label = "RAM:".to_string()
- + &format!(
+pub fn convert_mem_labels(
+ current_data: &data_farmer::DataCollection,
+) -> (String, String, String, String) {
+ (
+ format!(
"{:3.0}%",
match current_data.memory_harvest.mem_total_in_mb {
0 => 0.0,
@@ -241,15 +246,13 @@ pub fn convert_mem_labels(current_data: &data_farmer::DataCollection) -> (String
current_data.memory_harvest.mem_used_in_mb as f64 * 100.0
/ current_data.memory_harvest.mem_total_in_mb as f64,
}
- )
- + &format!(
+ ),
+ format!(
" {:.1}GB/{:.1}GB",
current_data.memory_harvest.mem_used_in_mb as f64 / 1024.0,
(current_data.memory_harvest.mem_total_in_mb as f64 / 1024.0)
- );
-
- let swap_label = "SWP:".to_string()
- + &format!(
+ ),
+ format!(
"{:3.0}%",
match current_data.swap_harvest.mem_total_in_mb {
0 => 0.0,
@@ -257,14 +260,13 @@ pub fn convert_mem_labels(current_data: &data_farmer::DataCollection) -> (String
current_data.swap_harvest.mem_used_in_mb as f64 * 100.0
/ current_data.swap_harvest.mem_total_in_mb as f64,
}
- )
- + &format!(
+ ),
+ format!(
" {:.1}GB/{:.1}GB",
current_data.swap_harvest.mem_used_in_mb as f64 / 1024.0,
(current_data.swap_harvest.mem_total_in_mb as f64 / 1024.0)
- );
-
- (mem_label, swap_label)
+ ),
+ )
}
pub fn get_rx_tx_data_points(
@@ -398,8 +400,10 @@ pub fn convert_process_data(
ProcessNamingType::Name => process.name.to_string(),
ProcessNamingType::Path => process.path.to_string(),
},
- cpu_usage: process.cpu_usage_percent,
- mem_usage: process.mem_usage_percent,
+ cpu_percent_usage: process.cpu_usage_percent,
+ mem_percent_usage: process.mem_usage_percent,
+ mem_usage_kb: process.mem_usage_kb,
+ mem_usage_str: get_exact_byte_values(process.mem_usage_kb * 1024, false),
group_pids: vec![process.pid],
read_per_sec,
write_per_sec,
@@ -428,8 +432,9 @@ pub fn convert_process_data(
..SingleProcessData::default()
});
- (*entry).cpu_usage += process.cpu_usage_percent;
- (*entry).mem_usage += process.mem_usage_percent;
+ (*entry).cpu_percent_usage += process.cpu_usage_percent;
+ (*entry).mem_percent_usage += process.mem_usage_percent;
+ (*entry).mem_usage_kb += process.mem_usage_kb;
(*entry).group_pids.push(process.pid);
(*entry).read_per_sec += process.read_bytes_per_sec;
(*entry).write_per_sec += process.write_bytes_per_sec;
@@ -458,8 +463,10 @@ pub fn convert_process_data(
ConvertedProcessData {
pid: p.pid,
name: identifier.to_string(),
- cpu_usage: p.cpu_usage,
- mem_usage: p.mem_usage,
+ cpu_percent_usage: p.cpu_percent_usage,
+ mem_percent_usage: p.mem_percent_usage,
+ mem_usage_kb: p.mem_usage_kb,
+ mem_usage_str: get_exact_byte_values(p.mem_usage_kb * 1024, false),
group_pids: p.group_pids,
read_per_sec,
write_per_sec,