The source project of this merge request has been removed.
fix cpuUsage parser for linux
I found on systems where the top
command presented CPU levels as Cpu(s)
the ignorecase setting was not respected.
In testing, I found that replacing IGNORECASE
with toupper
resolved the parser.
Tested with procps-ng 3.3.12 on arm64 and amd64.
root@d3128d68ca51:/opt/shinobi# top -v
procps-ng 3.3.12
top - 13:26:55 up 3 days, 21:09, 0 users, load average: 18.89, 15.12, 13.88
Tasks: 16 total, 3 running, 9 sleeping, 0 stopped, 4 zombie
%Cpu(s): 64.4 us, 27.6 sy, 0.0 ni, 5.5 id, 0.0 wa, 1.2 hi, 1.3 si, 0.0 st
KiB Mem : 4056788 total, 226764 free, 1134340 used, 2695684 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 2688924 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19411 root 20 0 583280 92016 28944 R 61.4 2.3 2:03.03 ffmpeg
19412 root 20 0 245956 47964 27404 R 51.5 1.2 1:34.90 ffmpeg
19380 root 20 0 579188 84764 29156 S 49.1 2.1 1:43.44 ffmpeg
root@d3128d68ca51:/opt/shinobi# top -b -n 2 | awk '{IGNORECASE = 1} /^.?CPU/ {gsub("id,","100",$8); gsub("%","",$8); print 100-$8}' | tail -n 1
root@d3128d68ca51:/opt/shinobi# top -b -n 2 | awk 'toupper($0) ~ /^.?CPU/ {gsub("id,","100",$8); gsub("%","",$8); print 100-$8}' | tail -n 1
95.2
Edited by Kyle Harding