summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorTwan Stok <twanstok@gmail.com>2023-04-13 04:51:41 +0200
committerGitHub <noreply@github.com>2023-04-12 22:51:41 -0400
commit1b1e80ec3cf51804204982d6c39f0b64ac735a69 (patch)
tree77bacd1b76000bc14ccc8fed26daf78aef4a4550 /src/app
parente61e5f2af6b5f533461e15bb04250e9ad94a6627 (diff)
feature: add buffer and cache memory (#1063)
* First implementation of cache memory data collection, mostly copied from RAM and swap implementations * First implementation of cache memory display, copied from RAM and swap implementations. placed cache as second in the list as it is more similar to the RAM than any other item in the list * expanded comment to explain method. * rustfmt * all cache-related code excluded on windows, in the process refactored src/data_conversion.rs convert_mem_label() to convert a single label instead of all at once * better factoring-out of cache memory logic to allow individual disabling * added --enable_cache_memory flag, disabled cache memory collection by default * renamed CCH to CHE not sure how i messed that up * changelog updated * Added command line flag documentation * updated config file documentation * specified that buffer and cache memory display does not work on windows * resolved merge conflicts * added documentation to cache memory data collection * capitalized Windows * implemented missing canvas styling logic * fixed misplaced no-windows flag * reduced colour collisions, as cache colour was the same as the first GPU colour * made FIFTH_COLOUR constant windows-only * Revert "made FIFTH_COLOUR constant windows-only" This reverts commit 72698f1dd7e2de7dbda843708ece6a3dba66f94f. * made FIFTH_COLOUR constant non-windows-only * minor fix for basic mode row count * Update src/app/data_harvester/memory/sysinfo.rs Co-authored-by: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> * Update src/canvas/widgets/mem_basic.rs Co-authored-by: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> * updated default_config.toml * formatting --------- Co-authored-by: ClementTsang <34804052+ClementTsang@users.noreply.github.com>
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_farmer.rs23
-rw-r--r--src/app/data_harvester.rs10
-rw-r--r--src/app/data_harvester/memory.rs4
-rw-r--r--src/app/data_harvester/memory/sysinfo.rs22
-rw-r--r--src/app/layout_manager.rs1
5 files changed, 58 insertions, 2 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index af130c3c..c11595bc 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -35,6 +35,8 @@ pub struct TimedData {
pub cpu_data: Vec<Value>,
pub load_avg_data: [f32; 3],
pub mem_data: Option<Value>,
+ #[cfg(not(target_os = "windows"))]
+ pub cache_data: Option<Value>,
pub swap_data: Option<Value>,
#[cfg(feature = "zfs")]
pub arc_data: Option<Value>,
@@ -108,6 +110,8 @@ pub struct DataCollection {
pub timed_data_vec: Vec<(Instant, TimedData)>,
pub network_harvest: network::NetworkHarvest,
pub memory_harvest: memory::MemHarvest,
+ #[cfg(not(target_os = "windows"))]
+ pub cache_harvest: memory::MemHarvest,
pub swap_harvest: memory::MemHarvest,
pub cpu_harvest: cpu::CpuHarvest,
pub load_avg_harvest: cpu::LoadAvgHarvest,
@@ -132,6 +136,8 @@ impl Default for DataCollection {
timed_data_vec: Vec::default(),
network_harvest: network::NetworkHarvest::default(),
memory_harvest: memory::MemHarvest::default(),
+ #[cfg(not(target_os = "windows"))]
+ cache_harvest: memory::MemHarvest::default(),
swap_harvest: memory::MemHarvest::default(),
cpu_harvest: cpu::CpuHarvest::default(),
load_avg_harvest: cpu::LoadAvgHarvest::default(),
@@ -206,11 +212,17 @@ impl DataCollection {
self.eat_network(network, &mut new_entry);
}
- // Memory and Swap
+ // Memory, Swap
if let (Some(memory), Some(swap)) = (harvested_data.memory, harvested_data.swap) {
self.eat_memory_and_swap(memory, swap, &mut new_entry);
}
+ // Cache memory
+ #[cfg(not(target_os = "windows"))]
+ if let Some(cache) = harvested_data.cache {
+ self.eat_cache(cache, &mut new_entry);
+ }
+
#[cfg(feature = "zfs")]
if let Some(arc) = harvested_data.arc {
self.eat_arc(arc, &mut new_entry);
@@ -275,6 +287,15 @@ impl DataCollection {
self.swap_harvest = swap;
}
+ #[cfg(not(target_os = "windows"))]
+ fn eat_cache(&mut self, cache: memory::MemHarvest, new_entry: &mut TimedData) {
+ // Cache and buffer memory
+ new_entry.cache_data = cache.use_percent;
+
+ // In addition copy over latest data for easy reference
+ self.cache_harvest = cache;
+ }
+
fn eat_network(&mut self, network: network::NetworkHarvest, new_entry: &mut TimedData) {
// RX
if network.rx > 0 {
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 7904f495..67ff1e5b 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -31,6 +31,8 @@ pub struct Data {
pub cpu: Option<cpu::CpuHarvest>,
pub load_avg: Option<cpu::LoadAvgHarvest>,
pub memory: Option<memory::MemHarvest>,
+ #[cfg(not(target_os = "windows"))]
+ pub cache: Option<memory::MemHarvest>,
pub swap: Option<memory::MemHarvest>,
pub temperature_sensors: Option<Vec<temperature::TempHarvest>>,
pub network: Option<network::NetworkHarvest>,
@@ -52,6 +54,8 @@ impl Default for Data {
cpu: None,
load_avg: None,
memory: None,
+ #[cfg(not(target_os = "windows"))]
+ cache: None,
swap: None,
temperature_sensors: None,
list_of_processes: None,
@@ -404,6 +408,12 @@ impl DataCollector {
fn update_memory_usage(&mut self) {
if self.widgets_to_harvest.use_mem {
self.data.memory = memory::get_ram_usage(&self.sys);
+
+ #[cfg(not(target_os = "windows"))]
+ if self.widgets_to_harvest.use_cache {
+ self.data.cache = memory::get_cache_usage(&self.sys);
+ }
+
self.data.swap = memory::get_swap_usage(
#[cfg(not(target_os = "windows"))]
&self.sys,
diff --git a/src/app/data_harvester/memory.rs b/src/app/data_harvester/memory.rs
index e8906284..2154b00c 100644
--- a/src/app/data_harvester/memory.rs
+++ b/src/app/data_harvester/memory.rs
@@ -1,8 +1,10 @@
//! Memory data collection.
-pub mod sysinfo;
+#[cfg(not(target_os = "windows"))]
+pub(crate) use self::sysinfo::get_cache_usage;
pub(crate) use self::sysinfo::get_ram_usage;
+pub mod sysinfo;
cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
pub mod windows;
diff --git a/src/app/data_harvester/memory/sysinfo.rs b/src/app/data_harvester/memory/sysinfo.rs
index 56844728..119d44c5 100644
--- a/src/app/data_harvester/memory/sysinfo.rs
+++ b/src/app/data_harvester/memory/sysinfo.rs
@@ -36,3 +36,25 @@ pub(crate) fn get_swap_usage(sys: &System) -> Option<MemHarvest> {
},
})
}
+
+/// Returns cache usage. sysinfo has no way to do this directly but it should equal the difference
+/// between the available and free memory. Free memory is defined as memory not containing any data,
+/// which means cache and buffer memory are not "free". Available memory is defined as memory able
+/// to be allocated by processes, which includes cache and buffer memory. On Windows, this will
+/// always be 0. For more information, see [docs](https://docs.rs/sysinfo/0.28.4/sysinfo/trait.SystemExt.html#tymethod.available_memory)
+/// and [memory explanation](https://askubuntu.com/questions/867068/what-is-available-memory-while-using-free-command)
+#[cfg(not(target_os = "windows"))]
+pub(crate) fn get_cache_usage(sys: &System) -> Option<MemHarvest> {
+ let mem_used = sys.available_memory().saturating_sub(sys.free_memory());
+ let mem_total = sys.total_memory();
+
+ Some(MemHarvest {
+ total_bytes: mem_total,
+ used_bytes: mem_used,
+ use_percent: if mem_total == 0 {
+ None
+ } else {
+ Some(mem_used as f64 / mem_total as f64 * 100.0)
+ },
+ })
+}
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index abc60899..032ccf98 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -997,6 +997,7 @@ Supported widget names:
pub struct UsedWidgets {
pub use_cpu: bool,
pub use_mem: bool,
+ pub use_cache: bool,
pub use_gpu: bool,
pub use_net: bool,
pub use_proc: bool,