summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-12-22 01:12:13 -0500
committerGitHub <noreply@github.com>2020-12-22 01:12:13 -0500
commit9d1f3c9ac2e8f816e275ed46c43d0f1d56a335e7 (patch)
tree1f5d33203bc60109491197f168c794804ed3151b /src/app
parent837c382ee9461dfd7b80fecf8871bb762ae1e639 (diff)
feature: Hide SWAP graph and legend in normal mode if SWAP is 0 (#372)
Firstly, note this currently won't affect basic mode. There is code changes due to it, but instead, we'll just display `0.0B/0.0B` instead. I'm personally not really sure if we want to get rid of it in basic mode, since it'll leave an ugly gap in that mode. Anyways, this change is mainly for the normal mode. All this does is hide the legend entry and chart if the total SWAP drops to 0 KB. It also has a small change to do a unit check on the memory used, as well as slightly adjusting the calculation we use.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_farmer.rs24
-rw-r--r--src/app/data_harvester/mem.rs20
2 files changed, 23 insertions, 21 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index b2dc0cc5..b1ba6a51 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -30,8 +30,8 @@ pub struct TimedData {
pub rx_data: Value,
pub tx_data: Value,
pub cpu_data: Vec<Value>,
- pub mem_data: Value,
- pub swap_data: Value,
+ pub mem_data: Option<Value>,
+ pub swap_data: Option<Value>,
}
/// AppCollection represents the pooled data stored within the main app
@@ -175,20 +175,20 @@ impl DataCollection {
) {
// trace!("Eating mem and swap.");
// Memory
- let mem_percent = match memory.mem_total_in_mb {
- 0 => 0f64,
- total => (memory.mem_used_in_mb as f64) / (total as f64) * 100.0,
+ let mem_percent = if memory.mem_total_in_kib > 0 {
+ Some((memory.mem_used_in_kib as f64) / (memory.mem_total_in_kib as f64) * 100.0)
+ } else {
+ None
};
new_entry.mem_data = mem_percent;
// Swap
- if swap.mem_total_in_mb > 0 {
- let swap_percent = match swap.mem_total_in_mb {
- 0 => 0f64,
- total => (swap.mem_used_in_mb as f64) / (total as f64) * 100.0,
- };
- new_entry.swap_data = swap_percent;
- }
+ let swap_percent = if swap.mem_total_in_kib > 0 {
+ Some((swap.mem_used_in_kib as f64) / (swap.mem_total_in_kib as f64) * 100.0)
+ } else {
+ None
+ };
+ new_entry.swap_data = swap_percent;
// In addition copy over latest data for easy reference
self.memory_harvest = memory;
diff --git a/src/app/data_harvester/mem.rs b/src/app/data_harvester/mem.rs
index 7dd0f4ca..014cbcdc 100644
--- a/src/app/data_harvester/mem.rs
+++ b/src/app/data_harvester/mem.rs
@@ -1,14 +1,14 @@
#[derive(Debug, Clone)]
pub struct MemHarvest {
- pub mem_total_in_mb: u64,
- pub mem_used_in_mb: u64,
+ pub mem_total_in_kib: u64,
+ pub mem_used_in_kib: u64,
}
impl Default for MemHarvest {
fn default() -> Self {
MemHarvest {
- mem_total_in_mb: 0,
- mem_used_in_mb: 0,
+ mem_total_in_kib: 0,
+ mem_used_in_kib: 0,
}
}
}
@@ -31,12 +31,14 @@ pub async fn get_mem_data(
pub async fn get_ram_data() -> crate::utils::error::Result<Option<MemHarvest>> {
let memory = heim::memory::memory().await?;
+ let mem_total_in_kb = memory.total().get::<heim::units::information::kibibyte>();
+
Ok(Some(MemHarvest {
- mem_total_in_mb: memory.total().get::<heim::units::information::megabyte>(),
- mem_used_in_mb: memory.total().get::<heim::units::information::megabyte>()
+ mem_total_in_kib: mem_total_in_kb,
+ mem_used_in_kib: mem_total_in_kb
- memory
.available()
- .get::<heim::units::information::megabyte>(),
+ .get::<heim::units::information::kibibyte>(),
}))
}
@@ -44,7 +46,7 @@ pub async fn get_swap_data() -> crate::utils::error::Result<Option<MemHarvest>>
let memory = heim::memory::swap().await?;
Ok(Some(MemHarvest {
- mem_total_in_mb: memory.total().get::<heim::units::information::megabyte>(),
- mem_used_in_mb: memory.used().get::<heim::units::information::megabyte>(),
+ mem_total_in_kib: memory.total().get::<heim::units::information::kibibyte>(),
+ mem_used_in_kib: memory.used().get::<heim::units::information::kibibyte>(),
}))
}