mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-22 21:24:49 +02:00
resolved merge conflicts
This commit is contained in:
parent
f6a0b55a5d
commit
bd9e576486
@ -41,16 +41,16 @@ pub(crate) fn get_swap_usage(sys: &System) -> Option<MemHarvest> {
|
||||
/// between the available and free memory. On windows, this will always be 0.
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub(crate) fn get_cache_usage(sys: &System) -> Option<MemHarvest> {
|
||||
let mem_used_in_kib = (sys.available_memory() - sys.free_memory()) / 1024;
|
||||
let mem_total_in_kib = sys.total_memory() / 1024;
|
||||
let mem_used = sys.available_memory() - sys.free_memory();
|
||||
let mem_total = sys.total_memory();
|
||||
|
||||
Some(MemHarvest {
|
||||
total_kib: mem_total_in_kib,
|
||||
used_kib: mem_used_in_kib,
|
||||
use_percent: if mem_total_in_kib == 0 {
|
||||
total_bytes: mem_total,
|
||||
used_bytes: mem_used,
|
||||
use_percent: if mem_total == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(mem_used_in_kib as f64 / mem_total_in_kib as f64 * 100.0)
|
||||
Some(mem_used as f64 / mem_total as f64 * 100.0)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -280,33 +280,17 @@ fn get_mem_binary_unit_and_denominator(bytes: u64) -> (&'static str, f64) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the unit type and denominator for given total amount of memory in kibibytes.
|
||||
pub fn convert_mem_label(harvest: &MemHarvest) -> Option<(String, String)> {
|
||||
/// Returns the unit type and denominator for given total amount of memory in kibibytes.
|
||||
fn return_unit_and_denominator_for_mem_kib(mem_total_kib: u64) -> (&'static str, f64) {
|
||||
if mem_total_kib < 1024 {
|
||||
// Stay with KiB
|
||||
("KiB", 1.0)
|
||||
} else if mem_total_kib < MEBI_LIMIT {
|
||||
// Use MiB
|
||||
("MiB", KIBI_LIMIT_F64)
|
||||
} else if mem_total_kib < GIBI_LIMIT {
|
||||
// Use GiB
|
||||
("GiB", MEBI_LIMIT_F64)
|
||||
} else {
|
||||
// Use TiB
|
||||
("TiB", GIBI_LIMIT_F64)
|
||||
}
|
||||
}
|
||||
|
||||
if harvest.total_kib > 0 {
|
||||
if harvest.total_bytes > 0 {
|
||||
Some((format!("{:3.0}%", harvest.use_percent.unwrap_or(0.0)), {
|
||||
let (unit, denominator) = return_unit_and_denominator_for_mem_kib(harvest.total_kib);
|
||||
let (unit, denominator) = get_mem_binary_unit_and_denominator(harvest.total_bytes);
|
||||
|
||||
format!(
|
||||
" {:.1}{}/{:.1}{}",
|
||||
harvest.used_kib as f64 / denominator,
|
||||
harvest.used_bytes as f64 / denominator,
|
||||
unit,
|
||||
(harvest.total_kib as f64 / denominator),
|
||||
(harvest.total_bytes as f64 / denominator),
|
||||
unit
|
||||
)
|
||||
}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user