fix CPU usage
This commit is contained in:
@@ -5,6 +5,7 @@ import Quickshell.Io
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
|
||||
// qmllint disable uncreatable-type
|
||||
PanelWindow {
|
||||
id: root
|
||||
|
||||
@@ -19,11 +20,12 @@ PanelWindow {
|
||||
|
||||
Process {
|
||||
id: cpuProc
|
||||
// get cpu usage, first line of /proc/stat
|
||||
command: ["cat", "/proc/stat"]
|
||||
stdout: {
|
||||
console.log(stdout);
|
||||
console.log("test");
|
||||
var line = stdout.split("\n")[0].split(/\s+/);
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
var line = this.text.split(/\r?\n/)[1].split(" ");
|
||||
console.log("the line is " + line);
|
||||
|
||||
var user = parseInt(line[1]);
|
||||
var nice = parseInt(line[2]);
|
||||
@@ -36,17 +38,18 @@ PanelWindow {
|
||||
var idleAll = idle + iowait;
|
||||
var total = user + nice + system + idle + iowait + irq + softirq;
|
||||
|
||||
var diffIdle = idleAll - lastCpuIdle;
|
||||
var diffTotal = total - lastCpuTotal;
|
||||
var diffIdle = idleAll - root.lastCpuIdle;
|
||||
var diffTotal = total - root.lastCpuTotal;
|
||||
|
||||
if (diffTotal > 0) {
|
||||
cpuUsage = Math.round(100 * (1 - diffIdle / diffTotal));
|
||||
root.cpuUsage = Math.round(100 * (1 - diffIdle / diffTotal));
|
||||
}
|
||||
|
||||
console.log("diffTotal is " + diffTotal);
|
||||
|
||||
lastCpuIdle = idleAll;
|
||||
lastCpuTotal = total;
|
||||
root.lastCpuIdle = idleAll;
|
||||
root.lastCpuTotal = total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user