Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
perf(win32): throttle expensive systeminformation calls
Browse files Browse the repository at this point in the history
  • Loading branch information
GitSquared committed May 6, 2021
1 parent a8755f7 commit 5bf9018
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/classes/cpuinfo.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -118,6 +121,8 @@ class Cpuinfo {
});
}
updateCPUload() {
if (this.updatingCPUload) return;
this.updatingCPUload = true;
window.si.currentLoad().then(data => {
let average = [[], []];

Expand All @@ -141,6 +146,7 @@ class Cpuinfo {
// Fail silently, DOM element is probably getting refreshed (new theme, etc)
}
});
this.updatingCPUload = false;
});
}
updateCPUtemp() {
Expand All @@ -153,22 +159,28 @@ 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`;
document.getElementById("mod_cpuinfo_speed_max").innerText = `${data.speedMax}GHz`;
} 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;
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/classes/ramwatcher.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/classes/toplist.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -48,13 +53,15 @@ class Toplist {
<td>${Math.round(proc.mem*10)/10}%</td>`;
document.getElementById("mod_toplist_table").append(el);
});
this.currentlyUpdating = false;
});
}

processList(){
let sortKey;
let ascending = false;
let removed = false;
let currentlyUpdating = false;

function setSortKey(fieldName){
if (sortKey === fieldName){
Expand Down Expand Up @@ -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) => {
Expand All @@ -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":
Expand Down

0 comments on commit 5bf9018

Please # to comment.