What is the best way to get the physical CPU load value?

,

FYI, on Discourse the text of your script was truncated, at least for me.

Strange, I used the right syntax, as I have done in the past.

Could you try sharing it again?

https://paste.opensuse.org/pastes/b9b214cde630

Without any formatting markup (because the above has max expiration 3 months):

#!/usr/bin/env bash

Measure physical CPU load in Xen

1 Like

Looks really cool, I could use that. If you wouldn’t mind, could you share it with us?

It’s truncated again. Maybe it’s an issue with a forum link in your message.
Maybe related:

Thanks!

==>

#!/usr/bin/env bash

# Measure physical CPU load in Xen
#
# https://forum.qubes-os.org/t/what-is-the-best-way-to-get-the-physical-cpu-load-value/27277/14

set -euo pipefail
renice --priority 19 $$ > /dev/null 2>&1

# Prevent two processes from trying to create the same qube
readonly pidfile="/run/user/${UID}/${0##*/}.pid"
[ -f "${pidfile}" ] && exit 1

touch "${pidfile}"

load=$(xenpm start 1 \
	| awk 'BEGIN { sum=0; tot=0 } \
		/^  C0/ { tot++; sum+=$2 } \
		END { printf("%3.2f%%", sum/tot/10) }')
printf "%6s" "${load}"

rm -f "${pidfile}"

Here is the code
https://github.com/renehoj/xencpumon/blob/main/xencpumon.py

It’s pretty much hard coded for an i9 intel with 16/16 cores, if you have a CPU with a different core count you need to modify the code, there are no settings you can configure.

Something in the c lib used by the Python drawingarea seems to crash randomly, I think it’s a threading issue with the queue_draw, but I don’t really know anything about Python.

1 Like

It’s truncated again. Maybe it’s an issue with a forum link in your message.
Maybe related:

Maybe.

BTW, sometimes I see the script output “100.05%” which has no physical meaning. Not sure why this is happening. My speculation: rounding happening before summing. Not a big deal, just an observation.