From fcf626d03bf9e3bf1b66412f6b4343575913d34c Mon Sep 17 00:00:00 2001 From: Alessandro Pignotti Date: Wed, 16 Oct 2024 11:13:39 +0200 Subject: [PATCH] Fix CPU load value The new approach keep the last event before the time window limit to correctly measure long running activity --- src/lib/WebVM.svelte | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/WebVM.svelte b/src/lib/WebVM.svelte index 800c744..2783289 100644 --- a/src/lib/WebVM.svelte +++ b/src/lib/WebVM.svelte @@ -41,9 +41,9 @@ } function expireEvents(list, curTime, limitTime) { - while(list.length) + while(list.length > 1) { - if(list[0].t < limitTime) + if(list[1].t < limitTime) { list.shift(); } @@ -73,24 +73,29 @@ for(var i=0;i 0)debugger; - totalActiveTime += (e.t - lastActiveTime); + totalActiveTime += (curTime - lastActiveTime); } cpuPercentage.set(Math.ceil((totalActiveTime / 10000) * 100)); }