perf(win32): throttle expensive systeminformation calls

This commit is contained in:
Gabriel Saillard 2021-05-06 12:29:58 +02:00
parent a8755f7435
commit 5bf9018ad3
No known key found for this signature in database
GPG Key ID: 4F615B5FE436611A
3 changed files with 27 additions and 0 deletions

View File

@ -97,9 +97,12 @@ class Cpuinfo {
}
// Init updater
this.updatingCPUload = false;
this.updateCPUload();
if (process.platform !== "win32") {this.updateCPUtemp();}
this.updatingCPUspeed = false;
this.updateCPUspeed();
this.updatingCPUtasks = false;
this.updateCPUtasks();
this.loadUpdater = setInterval(() => {
this.updateCPUload();
@ -118,6 +121,8 @@ class Cpuinfo {
});
}
updateCPUload() {
if (this.updatingCPUload) return;
this.updatingCPUload = true;
window.si.currentLoad().then(data => {
let average = [[], []];
@ -141,6 +146,7 @@ class Cpuinfo {
// Fail silently, DOM element is probably getting refreshed (new theme, etc)
}
});
this.updatingCPUload = false;
});
}
updateCPUtemp() {
@ -153,6 +159,8 @@ class Cpuinfo {
});
}
updateCPUspeed() {
if (this.updatingCPUspeed) return;
this.updatingCPUspeed = true
window.si.cpu().then(data => {
try {
document.getElementById("mod_cpuinfo_speed_min").innerText = `${data.speed}GHz`;
@ -160,15 +168,19 @@ class Cpuinfo {
} catch(e) {
// See above notice
}
this.updatingCPUspeed = false;
});
}
updateCPUtasks() {
if (this.updatingCPUtasks) return;
this.updatingCPUtasks = true;
window.si.processes().then(data => {
try {
document.getElementById("mod_cpuinfo_tasks").innerText = `${data.all}`;
} catch(e) {
// See above notice
}
this.updatingCPUtasks = false;
});
}
}

View File

@ -29,12 +29,15 @@ class RAMwatcher {
this.shuffleArray(this.points);
// Init updaters
this.currentlyUpdating = false;
this.updateInfo();
this.infoUpdater = setInterval(() => {
this.updateInfo();
}, 1500);
}
updateInfo() {
if (this.currentlyUpdating) return;
this.currentlyUpdating = true;
window.si.mem().then(data => {
if (data.free+data.used !== data.total) throw("RAM Watcher Error: Bad memory values");
@ -70,6 +73,8 @@ class RAMwatcher {
let usedSwapGiB = Math.round((data.swapused/1073742000)*10)/10;
document.getElementById("mod_ramwatcher_swaptext").innerText = `${usedSwapGiB} GiB`;
this.currentlyUpdating = false;
});
}
shuffleArray(array) {

View File

@ -12,12 +12,17 @@ class Toplist {
this.parent.append(this._element);
this.currentlyUpdating = false;
this.updateList();
this.listUpdater = setInterval(() => {
this.updateList();
}, 2000);
}
updateList() {
if (this.currentlyUpdating) return;
this.currentlyUpdating = true;
window.si.processes().then(data => {
if (window.settings.excludeThreadsFromToplist === true) {
data.list = data.list.sort((a, b) => {
@ -48,6 +53,7 @@ class Toplist {
<td>${Math.round(proc.mem*10)/10}%</td>`;
document.getElementById("mod_toplist_table").append(el);
});
this.currentlyUpdating = false;
});
}
@ -55,6 +61,7 @@ class Toplist {
let sortKey;
let ascending = false;
let removed = false;
let currentlyUpdating = false;
function setSortKey(fieldName){
if (sortKey === fieldName){
@ -91,6 +98,8 @@ class Toplist {
}
function updateProcessList() {
if (currentlyUpdating) return;
currentlyUpdating = true;
window.si.processes().then(data => {
if (window.settings.excludeThreadsFromToplist === true) {
data.list = data.list.sort((a, b) => {
@ -110,6 +119,7 @@ class Toplist {
proc.runtime = new Date(Date.now() - Date.parse(proc.started));
});
currentlyUpdating = false;
let list = data.list.sort((a, b) => {
switch (sortKey) {
case "PID":