feat: process list
this is unnacceptably unperformant; I think I've reached the point at which sysinfo doesn't do what I want, which is keep track of a table of processes efficiently enough.
This commit is contained in:
parent
afa6104c28
commit
b20158820b
4 changed files with 105 additions and 22 deletions
|
|
@ -8,7 +8,7 @@ use iced::{
|
|||
|
||||
use crate::{
|
||||
app::{graph::Graph, utils::maybe_widget},
|
||||
sysinfo_snapshot::SysinfoSnapshot,
|
||||
sysinfo_snapshot::{ProcessSnapshot, SysinfoSnapshot},
|
||||
utils::Toggle,
|
||||
};
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ enum Message {
|
|||
ToggleMain,
|
||||
ToggleCpu,
|
||||
ToggleMemory,
|
||||
ToggleProcesses,
|
||||
|
||||
Info(SysinfoSnapshot),
|
||||
}
|
||||
|
|
@ -39,6 +40,9 @@ struct State {
|
|||
is_memory_section_shown: bool,
|
||||
memory_graph: Graph,
|
||||
swap_graph: Graph,
|
||||
|
||||
is_processes_section_shown: bool,
|
||||
processes: Vec<ProcessSnapshot>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
@ -65,6 +69,10 @@ impl State {
|
|||
self.is_memory_section_shown.toggle();
|
||||
self.check_borders();
|
||||
}
|
||||
Message::ToggleProcesses => {
|
||||
self.is_processes_section_shown.toggle();
|
||||
self.check_borders();
|
||||
}
|
||||
|
||||
Message::Info(snapshot) => {
|
||||
self.uptime = snapshot.uptime();
|
||||
|
|
@ -89,6 +97,10 @@ impl State {
|
|||
.zip(snapshot.cpus.into_iter())
|
||||
.for_each(|(graph, value)| graph.update(value));
|
||||
}
|
||||
|
||||
self.processes = snapshot.processes;
|
||||
self.processes
|
||||
.sort_by(|a, b| b.cpu_usage.total_cmp(&a.cpu_usage));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,19 +127,39 @@ impl State {
|
|||
}),
|
||||
])
|
||||
.into(),
|
||||
maybe_widget(self.is_memory_section_shown, || {
|
||||
widget::row([
|
||||
widget::canvas(&self.memory_graph)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into(),
|
||||
widget::canvas(&self.swap_graph)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into(),
|
||||
])
|
||||
.into()
|
||||
}),
|
||||
widget::row([
|
||||
maybe_widget(self.is_memory_section_shown, || {
|
||||
widget::row([
|
||||
widget::canvas(&self.memory_graph)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into(),
|
||||
widget::canvas(&self.swap_graph)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into(),
|
||||
])
|
||||
.into()
|
||||
}),
|
||||
maybe_widget(self.is_processes_section_shown, || {
|
||||
widget::scrollable(
|
||||
widget::grid(self.processes.iter().flat_map(|process| {
|
||||
[
|
||||
widget::text(&process.name).into(),
|
||||
widget::text(process.cpu_usage).into(),
|
||||
widget::text(format!("{:?}", process.cpu_time())).into(),
|
||||
widget::text(process.pid).into(),
|
||||
]
|
||||
}))
|
||||
.height(Length::Shrink)
|
||||
.columns(4),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}),
|
||||
])
|
||||
.into(),
|
||||
])
|
||||
.into()
|
||||
}
|
||||
|
|
@ -139,6 +171,7 @@ impl State {
|
|||
Key::Character("M" | "1") => Some(Message::ToggleMain),
|
||||
Key::Character("c" | "2") => Some(Message::ToggleCpu),
|
||||
Key::Character("m" | "3") => Some(Message::ToggleMemory),
|
||||
Key::Character("p" | "4") => Some(Message::ToggleProcesses),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue