diff --git a/src/uu/top/src/picker.rs b/src/uu/top/src/picker.rs index afe82e8..62cb3e8 100644 --- a/src/uu/top/src/picker.rs +++ b/src/uu/top/src/picker.rs @@ -223,13 +223,19 @@ fn todo(_pid: u32, _stat: Stat) -> Box { Box::new("TODO".to_string()) } -fn cpu(pid: u32, _stat: Stat) -> Box { +fn cpu(pid: u32, stat: Stat) -> Box { let binding = sysinfo().read().unwrap(); let Some(proc) = binding.process(Pid::from_u32(pid)) else { return PercentValue::new_boxed(0.0); }; - PercentValue::new_boxed(proc.cpu_usage()) + let cpu_usage = if stat.1.irix_mode { + proc.cpu_usage() + } else { + proc.cpu_usage() / binding.cpus().len() as f32 + }; + + PercentValue::new_boxed(cpu_usage) } fn pid(pid: u32, _stat: Stat) -> Box { diff --git a/src/uu/top/src/tui/input.rs b/src/uu/top/src/tui/input.rs index e87158c..d9f1212 100644 --- a/src/uu/top/src/tui/input.rs +++ b/src/uu/top/src/tui/input.rs @@ -74,6 +74,15 @@ pub fn handle_input( data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap()); should_update.store(true, Ordering::Relaxed); } + char!('I') => { + { + let mut stat = tui_stat.write().unwrap(); + stat.irix_mode = !stat.irix_mode; + } + + data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap()); + should_update.store(true, Ordering::Relaxed); + } char!('l') => { let mut stat = tui_stat.write().unwrap(); stat.show_load_avg = !stat.show_load_avg; diff --git a/src/uu/top/src/tui/stat.rs b/src/uu/top/src/tui/stat.rs index 4691636..97d54bb 100644 --- a/src/uu/top/src/tui/stat.rs +++ b/src/uu/top/src/tui/stat.rs @@ -30,6 +30,7 @@ pub(crate) struct TuiStat { pub highlight_bold: bool, pub show_coordinates: bool, pub show_zeros: bool, + pub irix_mode: bool, pub filter: Option, } @@ -66,6 +67,7 @@ impl TuiStat { highlight_bold: false, show_coordinates: false, show_zeros: true, + irix_mode: true, filter: None, }