commit 68f520bcd774828c98666fca689b3686ba2cd202 Author: Nicolas Massé Date: Tue Jun 4 18:01:53 2024 +0200 initial commit diff --git a/benchmark b/benchmark new file mode 100755 index 0000000..95314c7 --- /dev/null +++ b/benchmark @@ -0,0 +1,25 @@ +#!/bin/bash +set -Eeuo pipefail + +# see /proc/stat in proc(5) +# user nice system idle iowait irq softirq steal guest guest_nice +declare -a last_cpu_stats=( 0 0 0 0 0 0 0 0 0 0 ) +declare -a cpu_usage=( 0 0 0 0 0 0 0 0 0 0 ) + +function gather_cpu_usage () { + local cpu_stats=( $(read head numbers < /proc/stat; echo "$numbers") ) + local i + for i in ${!cpu_usage[@]}; do + cpu_usage[$i]=$((cpu_stats[$i] - last_cpu_stats[$i])) + done + + last_cpu_stats=( ${cpu_stats[@]} ) +} + +gather_cpu_usage +sleep 2 +echo "${cpu_usage[@]}" +gather_cpu_usage +echo "${last_cpu_stats[@]}" + +echo "${cpu_usage[@]}"