fix: NaN values for memory and cpu usage in toplist #1052

上级 3512a9dd
...@@ -25,8 +25,8 @@ class Toplist { ...@@ -25,8 +25,8 @@ class Toplist {
}).filter((e, index, a) => { }).filter((e, index, a) => {
let i = a.findIndex(x => x.name === e.name); let i = a.findIndex(x => x.name === e.name);
if (i !== -1 && i !== index) { if (i !== -1 && i !== index) {
a[i].pcpu = a[i].pcpu+e.pcpu; a[i].cpu = a[i].cpu+e.cpu;
a[i].pmem = a[i].pmem+e.pmem; a[i].mem = a[i].mem+e.mem;
return false; return false;
} }
return true; return true;
...@@ -34,7 +34,7 @@ class Toplist { ...@@ -34,7 +34,7 @@ class Toplist {
} }
let list = data.list.sort((a, b) => { 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); }).splice(0, 5);
document.querySelectorAll("#mod_toplist_table > tr").forEach(el => { document.querySelectorAll("#mod_toplist_table > tr").forEach(el => {
...@@ -44,8 +44,8 @@ class Toplist { ...@@ -44,8 +44,8 @@ class Toplist {
let el = document.createElement("tr"); let el = document.createElement("tr");
el.innerHTML = `<td>${proc.pid}</td> el.innerHTML = `<td>${proc.pid}</td>
<td><strong>${proc.name}</strong></td> <td><strong>${proc.name}</strong></td>
<td>${Math.round(proc.pcpu*10)/10}%</td> <td>${Math.round(proc.cpu*10)/10}%</td>
<td>${Math.round(proc.pmem*10)/10}%</td>`; <td>${Math.round(proc.mem*10)/10}%</td>`;
document.getElementById("mod_toplist_table").append(el); document.getElementById("mod_toplist_table").append(el);
}); });
}); });
...@@ -98,8 +98,8 @@ class Toplist { ...@@ -98,8 +98,8 @@ class Toplist {
}).filter((e, index, a) => { }).filter((e, index, a) => {
let i = a.findIndex(x => x.name === e.name); let i = a.findIndex(x => x.name === e.name);
if (i !== -1 && i !== index) { if (i !== -1 && i !== index) {
a[i].pcpu = a[i].pcpu + e.pcpu; a[i].cpu = a[i].cpu + e.cpu;
a[i].pmem = a[i].pmem + e.pmem; a[i].mem = a[i].mem + e.mem;
return false; return false;
} }
return true; return true;
...@@ -138,11 +138,11 @@ class Toplist { ...@@ -138,11 +138,11 @@ class Toplist {
return 0; return 0;
} }
case "CPU": case "CPU":
if (ascending) return a.pcpu - b.pcpu; if (ascending) return a.cpu - b.cpu;
else return b.pcpu - a.pcpu; else return b.cpu - a.cpu;
case "Memory": case "Memory":
if (ascending) return a.pmem - b.pmem; if (ascending) return a.mem - b.mem;
else return b.pmem - a.pmem; else return b.mem - a.mem;
case "State": case "State":
if (a.state < b.state) return -1; if (a.state < b.state) return -1;
if (a.state > b.state) return 1; if (a.state > b.state) return 1;
...@@ -155,7 +155,7 @@ class Toplist { ...@@ -155,7 +155,7 @@ class Toplist {
else return b.runtime - a.runtime; else return b.runtime - a.runtime;
default: default:
// default to the same sorting as the toplist // 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);
} }
}); });
...@@ -170,8 +170,8 @@ class Toplist { ...@@ -170,8 +170,8 @@ class Toplist {
el.innerHTML = `<td class="pid">${proc.pid}</td> el.innerHTML = `<td class="pid">${proc.pid}</td>
<td class="name">${proc.name}</td> <td class="name">${proc.name}</td>
<td class="user">${proc.user}</td> <td class="user">${proc.user}</td>
<td class="cpu">${Math.round(proc.pcpu * 10) / 10}%</td> <td class="cpu">${Math.round(proc.cpu * 10) / 10}%</td>
<td class="mem">${Math.round(proc.pmem * 10) / 10}%</td> <td class="mem">${Math.round(proc.mem * 10) / 10}%</td>
<td class="state">${proc.state}</td> <td class="state">${proc.state}</td>
<td class="started">${proc.started}</td> <td class="started">${proc.started}</td>
<td class="runtime">${formatRuntime(proc.runtime)}</td>`; <td class="runtime">${formatRuntime(proc.runtime)}</td>`;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册