add ProcessList singleton, memory hover panel with breakdown + top processes
This commit is contained in:
parent
edcc78483c
commit
7e0021853f
3 changed files with 309 additions and 7 deletions
48
modules/ProcessList.qml
Normal file
48
modules/ProcessList.qml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import "." as M
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
property var byCpu: []
|
||||
property var byMem: []
|
||||
property int maxItems: 8
|
||||
|
||||
property Process _proc: Process {
|
||||
id: proc
|
||||
running: true
|
||||
command: ["sh", "-c", "ps aux --sort=-%cpu 2>/dev/null | awk 'NR>1 && NR<=50 {cmd=$11; for(i=12;i<=NF&&i<=13;i++) cmd=cmd\" \"$i; print $1\"|\"$2\"|\"$3\"|\"$4\"|\"cmd}'"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const rows = [];
|
||||
for (const line of text.trim().split("\n")) {
|
||||
if (!line)
|
||||
continue;
|
||||
const p = line.split("|");
|
||||
if (p.length < 5)
|
||||
continue;
|
||||
const cmd = p[4].replace(/^.*\//, "");
|
||||
rows.push({
|
||||
"user": p[0],
|
||||
"pid": parseInt(p[1]),
|
||||
"cpu": parseFloat(p[2]),
|
||||
"mem": parseFloat(p[3]),
|
||||
"cmd": cmd || p[4]
|
||||
});
|
||||
}
|
||||
root.byCpu = rows.slice().sort((a, b) => b.cpu - a.cpu).slice(0, root.maxItems);
|
||||
root.byMem = rows.slice().sort((a, b) => b.mem - a.mem).slice(0, root.maxItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property Timer _timer: Timer {
|
||||
interval: 2000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: proc.running = true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue