This commit is contained in:
wt committed 2025-03-11 17:51:22 +07:00
1 parent dddb4bce11
commit 3edfbc19f6
11 files changed
+134 -116

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import GTop from "gi://GTop";
let previousCpuData = new GTop.glibtop_cpu();
GTop.glibtop_get_cpu(previousCpuData);
const computeCPU = (): string => {
const currentCpuData = new GTop.glibtop_cpu();
GTop.glibtop_get_cpu(currentCpuData);
// Calculate the differences from the previous to current data
const totalDiff = currentCpuData.total - previousCpuData.total;
const idleDiff = currentCpuData.idle - previousCpuData.idle;
const cpuUsagePercentage =
totalDiff > 0 ? ((totalDiff - idleDiff) / totalDiff) * 100 : 0;
previousCpuData = currentCpuData;
const cpuUsagePercentageString =
" " + Math.floor(cpuUsagePercentage) + "%";
return cpuUsagePercentageString;
};
export default computeCPU;