Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Fix: [page monitoring] la consommation de CPU était tout le temps à 100% #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/lib/osutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,19 @@ exports.cpuUsage = function(callback){
getCPUUsage(callback, false);
};

var prev_cpu = null;
exports.listCPUs = function () {
var list = getCPUsList();

wait(300);

var list = prev_cpu;
// On the first turn, we fake the result
if(list === null){
list = getCPUsList();
for (var i=0; i< list.length; i++){
list[i].percent = 0;
}
prev_cpu = list;
return list;
}
// real results are after 1s of display
var stats = getCPUsList();

for (var i = 0; i < stats.length; i++) {
Expand All @@ -199,14 +207,6 @@ exports.listCPUs = function () {
return list;
};

function wait(ms) {
var start = new Date().getTime();
var end = start;

while(end < start + ms) {
end = new Date().getTime();
}
}

function getCPUsList() {
var cpus = _os.cpus();
Expand Down