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

Commit a0e9814

Browse files
committed
fix: NaN values for memory and cpu usage in toplist #1052
1 parent 3512a9d commit a0e9814

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/classes/toplist.class.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ class Toplist {
2525
}).filter((e, index, a) => {
2626
let i = a.findIndex(x => x.name === e.name);
2727
if (i !== -1 && i !== index) {
28-
a[i].pcpu = a[i].pcpu+e.pcpu;
29-
a[i].pmem = a[i].pmem+e.pmem;
28+
a[i].cpu = a[i].cpu+e.cpu;
29+
a[i].mem = a[i].mem+e.mem;
3030
return false;
3131
}
3232
return true;
3333
});
3434
}
3535

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

4040
document.querySelectorAll("#mod_toplist_table > tr").forEach(el => {
@@ -44,8 +44,8 @@ class Toplist {
4444
let el = document.createElement("tr");
4545
el.innerHTML = `<td>${proc.pid}</td>
4646
<td><strong>${proc.name}</strong></td>
47-
<td>${Math.round(proc.pcpu*10)/10}%</td>
48-
<td>${Math.round(proc.pmem*10)/10}%</td>`;
47+
<td>${Math.round(proc.cpu*10)/10}%</td>
48+
<td>${Math.round(proc.mem*10)/10}%</td>`;
4949
document.getElementById("mod_toplist_table").append(el);
5050
});
5151
});
@@ -98,8 +98,8 @@ class Toplist {
9898
}).filter((e, index, a) => {
9999
let i = a.findIndex(x => x.name === e.name);
100100
if (i !== -1 && i !== index) {
101-
a[i].pcpu = a[i].pcpu + e.pcpu;
102-
a[i].pmem = a[i].pmem + e.pmem;
101+
a[i].cpu = a[i].cpu + e.cpu;
102+
a[i].mem = a[i].mem + e.mem;
103103
return false;
104104
}
105105
return true;
@@ -138,11 +138,11 @@ class Toplist {
138138
return 0;
139139
}
140140
case "CPU":
141-
if (ascending) return a.pcpu - b.pcpu;
142-
else return b.pcpu - a.pcpu;
141+
if (ascending) return a.cpu - b.cpu;
142+
else return b.cpu - a.cpu;
143143
case "Memory":
144-
if (ascending) return a.pmem - b.pmem;
145-
else return b.pmem - a.pmem;
144+
if (ascending) return a.mem - b.mem;
145+
else return b.mem - a.mem;
146146
case "State":
147147
if (a.state < b.state) return -1;
148148
if (a.state > b.state) return 1;
@@ -155,10 +155,10 @@ class Toplist {
155155
else return b.runtime - a.runtime;
156156
default:
157157
// default to the same sorting as the toplist
158-
return ((b.pcpu - a.pcpu) * 100 + b.pmem - a.pmem);
158+
return ((b.cpu - a.cpu) * 100 + b.mem - a.mem);
159159
}
160160
});
161-
161+
162162
if (removed) clearInterval(updateInterval);
163163
else {
164164
document.querySelectorAll("#processList > tr").forEach(el => {
@@ -170,8 +170,8 @@ class Toplist {
170170
el.innerHTML = `<td class="pid">${proc.pid}</td>
171171
<td class="name">${proc.name}</td>
172172
<td class="user">${proc.user}</td>
173-
<td class="cpu">${Math.round(proc.pcpu * 10) / 10}%</td>
174-
<td class="mem">${Math.round(proc.pmem * 10) / 10}%</td>
173+
<td class="cpu">${Math.round(proc.cpu * 10) / 10}%</td>
174+
<td class="mem">${Math.round(proc.mem * 10) / 10}%</td>
175175
<td class="state">${proc.state}</td>
176176
<td class="started">${proc.started}</td>
177177
<td class="runtime">${formatRuntime(proc.runtime)}</td>`;

0 commit comments

Comments
 (0)