better factoring-out of cache memory logic to allow individual disabling

This commit is contained in:
Twan Stok 2023-03-13 22:46:22 +01:00
parent 0b0c1b00d3
commit 69e1783bfb

View File

@ -214,21 +214,17 @@ impl DataCollection {
self.eat_network(network, &mut new_entry);
}
// Memory, Swap, and Cache if not windows
#[cfg(not(target_os = "windows"))]
if let (Some(memory), Some(cache), Some(swap)) = (
harvested_data.memory,
harvested_data.cache,
harvested_data.swap,
) {
self.eat_memory_and_swap(memory, cache, swap, &mut new_entry);
}
#[cfg(target_os = "windows")]
// 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);
@ -280,31 +276,28 @@ impl DataCollection {
}
fn eat_memory_and_swap(
&mut self, memory: memory::MemHarvest,
#[cfg(not(target_os = "windows"))] cache: memory::MemHarvest, swap: memory::MemHarvest,
new_entry: &mut TimedData,
&mut self, memory: memory::MemHarvest, swap: memory::MemHarvest, new_entry: &mut TimedData,
) {
// Memory
new_entry.mem_data = memory.use_percent;
// Cache
#[cfg(not(target_os = "windows"))]
{
new_entry.cache_data = cache.use_percent;
}
// Swap
new_entry.swap_data = swap.use_percent;
// In addition copy over latest data for easy reference
self.memory_harvest = memory;
#[cfg(not(target_os = "windows"))]
{
self.cache_harvest = cache;
}
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 {