Skip to content

Commit 82c1641

Browse files
committed
top: tui impl I (irix or solaris)
1 parent 1b94527 commit 82c1641

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/uu/top/src/picker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,19 @@ fn todo(_pid: u32, _stat: Stat) -> Box<dyn Column> {
223223
Box::new("TODO".to_string())
224224
}
225225

226-
fn cpu(pid: u32, _stat: Stat) -> Box<dyn Column> {
226+
fn cpu(pid: u32, stat: Stat) -> Box<dyn Column> {
227227
let binding = sysinfo().read().unwrap();
228228
let Some(proc) = binding.process(Pid::from_u32(pid)) else {
229229
return PercentValue::new_boxed(0.0);
230230
};
231231

232-
PercentValue::new_boxed(proc.cpu_usage())
232+
let cpu_usage = if stat.1.irix_mode {
233+
proc.cpu_usage()
234+
} else {
235+
proc.cpu_usage() / binding.cpus().len() as f32
236+
};
237+
238+
PercentValue::new_boxed(cpu_usage)
233239
}
234240

235241
fn pid(pid: u32, _stat: Stat) -> Box<dyn Column> {

src/uu/top/src/tui/input.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ pub fn handle_input(
7474
data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap());
7575
should_update.store(true, Ordering::Relaxed);
7676
}
77+
char!('I') => {
78+
{
79+
let mut stat = tui_stat.write().unwrap();
80+
stat.irix_mode = !stat.irix_mode;
81+
}
82+
83+
data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap());
84+
should_update.store(true, Ordering::Relaxed);
85+
}
7786
char!('l') => {
7887
let mut stat = tui_stat.write().unwrap();
7988
stat.show_load_avg = !stat.show_load_avg;

src/uu/top/src/tui/stat.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) struct TuiStat {
3030
pub highlight_bold: bool,
3131
pub show_coordinates: bool,
3232
pub show_zeros: bool,
33+
pub irix_mode: bool,
3334

3435
pub filter: Option<crate::Filter>,
3536
}
@@ -66,6 +67,7 @@ impl TuiStat {
6667
highlight_bold: false,
6768
show_coordinates: false,
6869
show_zeros: true,
70+
irix_mode: true,
6971

7072
filter: None,
7173
}

0 commit comments

Comments
 (0)