From 68f520bcd774828c98666fca689b3686ba2cd202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Tue, 4 Jun 2024 18:01:53 +0200 Subject: [PATCH] initial commit --- benchmark | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 benchmark 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[@]}"