Skip to content

Instantly share code, notes, and snippets.

@anthonywong
Created September 3, 2019 08:46
Show Gist options
  • Save anthonywong/a98003b50f9441a6cf2cb4bd3bc02849 to your computer and use it in GitHub Desktop.
Save anthonywong/a98003b50f9441a6cf2cb4bd3bc02849 to your computer and use it in GitHub Desktop.
#!/bin/bash
[ $UID != 0 ] && echo "Must run as root" && exit
i=1
RUNS=3
if [ -n "$1" ]; then
RUNS=$1
fi
while [ $i -le $RUNS ]; do
d=`date +%Y%m%d-%H%M`
raw_f="cpu_stress_log-$d.txt"
csv_f="cpu_stress_log-$d.csv"
png_f="cpu_stress_log-$d.png"
turbostat --debug --show CPU,Core,Bzy_MHz,PkgTmp,PkgWatt --quiet --interval 1 -o $raw_f &
p=$!
echo "Run $i"
sleep 5
stress-ng --cpu 0 --cpu-method all -t 5m
echo "Cooling down..."
sleep 30 # to cool down
kill $p
uname -a >> $raw_f
egrep '^[ ]*0' $raw_f | awk '{ print $4 " " $5 " " $6 }' > $csv_f
gnuplot <<-_EOS
set term png; set output '$png_f'; set yrange [0:120]; \
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"; \
plot '$csv_f' using (\$1/100) with lines title "Freq" lw 3 lt rgb "gold", \
'$csv_f' using 2 with lines title "Temp" lw 3 lt rgb "blue", \
'$csv_f' using 3 with lines title "Watt" lw 3 lt rgb "red"
_EOS
echo "Log is written to cpu_stress_log-$d.txt"
i=`expr $i + 1`
echo "Cooling down for 60 seconds..."
sleep 60
done
f="cpu_stress_logs-`date +%Y%m%d`-`uname -r`.tar.xz"
tar Jcf $f cpu_stress_log-*.*
echo "Logs collected to $f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment