dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 7a6a5f84891413347d7cf2d9a13a9b387a4a94e0
parent 0eec977ad585a4ce257a430fe655a6a67fda0852
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu,  1 Oct 2020 09:20:19 +0200

temptest: add support for linux

Diffstat:
M.local/bin/temptest | 42++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/.local/bin/temptest b/.local/bin/temptest @@ -1,23 +1,45 @@ #!/bin/sh # requirements: stress -n_cores="$(sysctl -n hw.ncpufound)" -if [ "$n_cores" -gt 1 ]; then - label="cpus" -else - label="cpu" -fi +get_ncpu() { + if [ "$(uname)" = OpenBSD ]; then + sysctl -n hw.ncpufound + else + grep 'cpu cores' /proc/cpuinfo | awk 'END{print $4}' + fi +} + +get_temp() { + if [ "$(uname)" = OpenBSD ]; then + sysctl -n hw.sensors.cpu0.temp0 + else + printf '%d/1000\n' "$(cat /sys/class/hwmon/hwmon1/temp1_input)" | bc -l + fi +} + +get_speed() { + if [ "$(uname)" = OpenBSD ]; then + sysctl -n hw.cpuspeed + fi +} show_temp() { load="$(uptime | sed 's/.*: //')" - temp="$(sysctl -n hw.sensors.cpu0.temp0)" - cpuspeed="$(sysctl -n hw.cpuspeed)" + temp="$(get_temp)" + cpuspeed="$(get_speed)" printf '\r ' - printf '\r%s\t%s\t%s MHz\n' "$load" "$temp" "$cpuspeed" + printf '\r%s\t%.4s C\t%s MHz\n' "$load" "$temp" "$cpuspeed" } +n_cores="$(get_ncpu)" +if [ "$n_cores" -gt 1 ]; then + label="cpus" +else + label="cpu" +fi + i=1 -while [ i -le 5 ]; do +while [ $i -le 5 ]; do show_temp printf 'stressing %s %s...' "$n_cores" "$label" stress -c "$n_cores" -t 120s >/dev/null