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

Commit

Permalink
fix: NaN values for memory and cpu usage in toplist #1052
Browse files Browse the repository at this point in the history
  • Loading branch information
GitSquared committed Feb 24, 2021
1 parent 3512a9d commit a0e9814
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/classes/toplist.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class Toplist {
}).filter((e, index, a) => {
let i = a.findIndex(x => x.name === e.name);
if (i !== -1 && i !== index) {
a[i].pcpu = a[i].pcpu+e.pcpu;
a[i].pmem = a[i].pmem+e.pmem;
a[i].cpu = a[i].cpu+e.cpu;
a[i].mem = a[i].mem+e.mem;
return false;
}
return true;
});
}

let list = data.list.sort((a, b) => {
return ((b.pcpu-a.pcpu)*100 + b.pmem-a.pmem);
return ((b.cpu-a.cpu)*100 + b.mem-a.mem);
}).splice(0, 5);

document.querySelectorAll("#mod_toplist_table > tr").forEach(el => {
Expand All @@ -44,8 +44,8 @@ class Toplist {
let el = document.createElement("tr");
el.innerHTML = `<td>${proc.pid}</td>
<td><strong>${proc.name}</strong></td>
<td>${Math.round(proc.pcpu*10)/10}%</td>
<td>${Math.round(proc.pmem*10)/10}%</td>`;
<td>${Math.round(proc.cpu*10)/10}%</td>
<td>${Math.round(proc.mem*10)/10}%</td>`;
document.getElementById("mod_toplist_table").append(el);
});
});
Expand Down Expand Up @@ -98,8 +98,8 @@ class Toplist {
}).filter((e, index, a) => {
let i = a.findIndex(x => x.name === e.name);
if (i !== -1 && i !== index) {
a[i].pcpu = a[i].pcpu + e.pcpu;
a[i].pmem = a[i].pmem + e.pmem;
a[i].cpu = a[i].cpu + e.cpu;
a[i].mem = a[i].mem + e.mem;
return false;
}
return true;
Expand Down Expand Up @@ -138,11 +138,11 @@ class Toplist {
return 0;
}
case "CPU":
if (ascending) return a.pcpu - b.pcpu;
else return b.pcpu - a.pcpu;
if (ascending) return a.cpu - b.cpu;
else return b.cpu - a.cpu;
case "Memory":
if (ascending) return a.pmem - b.pmem;
else return b.pmem - a.pmem;
if (ascending) return a.mem - b.mem;
else return b.mem - a.mem;
case "State":
if (a.state < b.state) return -1;
if (a.state > b.state) return 1;
Expand All @@ -155,10 +155,10 @@ class Toplist {
else return b.runtime - a.runtime;
default:
// default to the same sorting as the toplist
return ((b.pcpu - a.pcpu) * 100 + b.pmem - a.pmem);
return ((b.cpu - a.cpu) * 100 + b.mem - a.mem);
}
});

if (removed) clearInterval(updateInterval);
else {
document.querySelectorAll("#processList > tr").forEach(el => {
Expand All @@ -170,8 +170,8 @@ class Toplist {
el.innerHTML = `<td class="pid">${proc.pid}</td>
<td class="name">${proc.name}</td>
<td class="user">${proc.user}</td>
<td class="cpu">${Math.round(proc.pcpu * 10) / 10}%</td>
<td class="mem">${Math.round(proc.pmem * 10) / 10}%</td>
<td class="cpu">${Math.round(proc.cpu * 10) / 10}%</td>
<td class="mem">${Math.round(proc.mem * 10) / 10}%</td>
<td class="state">${proc.state}</td>
<td class="started">${proc.started}</td>
<td class="runtime">${formatRuntime(proc.runtime)}</td>`;
Expand Down

0 comments on commit a0e9814

Please sign in to comment.