summaryrefslogtreecommitdiff
path: root/services/Resource.qml
diff options
context:
space:
mode:
Diffstat (limited to 'services/Resource.qml')
-rw-r--r--services/Resource.qml35
1 files changed, 25 insertions, 10 deletions
diff --git a/services/Resource.qml b/services/Resource.qml
index d2ab9af..0c2d1d6 100644
--- a/services/Resource.qml
+++ b/services/Resource.qml
@@ -20,6 +20,7 @@ Singleton {
property double cpuUsage: 0
property double cpuTemp: 0
+ property double cpuFreq: 0
property var previousCpuStats
property int gpuUsage: 0
@@ -33,14 +34,15 @@ Singleton {
fileMeminfo.reload();
fileStat.reload();
fileCpuThermal.reload();
+ fileCpuInfo.reload();
const textMeminfo = fileMeminfo.text();
- memoryTotal = Number(textMeminfo.match(/MemTotal: *(\d+)/)[1] ?? 1);
- memoryFree = Number(textMeminfo.match(/MemAvailable: *(\d+)/)[1] ?? 0);
+ memoryTotal = Number(textMeminfo.match(/MemTotal:\s*(\d+)/)[1] ?? 1);
+ memoryFree = Number(textMeminfo.match(/MemAvailable:\s*(\d+)/)[1] ?? 0);
memoryUsed = memoryTotal - memoryFree;
memoryUsedPercentage = memoryUsed / memoryTotal;
- swapTotal = Number(textMeminfo.match(/SwapTotal: *(\d+)/)[1] ?? 1);
- swapFree = Number(textMeminfo.match(/SwapFree: *(\d+)/)[1] ?? 0);
+ swapTotal = Number(textMeminfo.match(/SwapTotal:\s*(\d+)/)[1] ?? 1);
+ swapFree = Number(textMeminfo.match(/SwapFree:\s*(\d+)/)[1] ?? 0);
const textStat = fileStat.text();
const cpuLine = textStat.match(/^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
@@ -48,21 +50,30 @@ Singleton {
const stats = cpuLine.slice(1).map(Number);
const total = stats.reduce((a, b) => a + b, 0);
const idle = stats[3];
-
if (root.previousCpuStats) {
- const totalDiff = total - root.previousCpuStats.total;
- const idleDiff = idle - root.previousCpuStats.idle;
- cpuUsage = totalDiff > 0 ? (1 - idleDiff / totalDiff) : 0;
+ const td = total - root.previousCpuStats.total;
+ const id = idle - root.previousCpuStats.idle;
+ cpuUsage = td > 0 ? (1 - id / td) : 0;
}
-
root.previousCpuStats = {
total,
idle
};
}
+
const cpuTempText = fileCpuThermal.text();
cpuTemp = cpuTempText ? parseInt(cpuTempText.trim()) / 100000 : 0;
+ const textCpuInfo = fileCpuInfo.text();
+ let sum = 0, cnt = 0;
+ const re = /^cpu MHz\s*:\s*([\d.]+)/mg;
+ let m;
+ while ((m = re.exec(textCpuInfo)) !== null) {
+ sum += Number(m[1]);
+ cnt++;
+ }
+ cpuFreq = cnt ? sum / cnt : 0;
+
gpuUsageProc.running = true;
gpuTempProc.running = true;
interval = General.resourceUpdateInterval * 1000;
@@ -81,7 +92,11 @@ Singleton {
id: fileCpuThermal
path: General.cpuThermalPath
}
- // nvidia-smi may be dead if firmware update so ABI break etc.
+ FileView {
+ id: fileCpuInfo
+ path: "/proc/cpuinfo"
+ }
+
Process {
id: gpuUsageProc
running: true