Re: smart fans
David Christensen wrote:
> I would output a header line and then output each set of
> statistics on a single line [...]
>
> I would avoid doing any math on the data. Save raw values
> and deal with math in post-processing [...]
>
> I would put units into the headers. Save raw values and deal
> with units in post processing [...]
OK, the header line is now
time, governor, background processes, CPU temperature C,
system load, CPU fan speed RPM, CPU frequencies MHz
and output can be either
1629843103, ondemand, 1, 33.25, 0.03, 0, 1807.086 2928.002 2418.211 3084.016
or
time 1629843119
governor ondemand
background processes 0
CPU temperature C 36.625
system load 0.02
CPU fan speed RPM 0
CPU frequencies MHz 1966.683 3032.553 2397.819 1399.776
I'll run it next time I go for a walk...
#! /bin/zsh
#
# this file:
# https://dataswamp.org/~incal/conf/.zsh/cpu
cpu-stats-print-raw () {
local time=$1
local gov=$2
local back=$3
local temp=$4
local load=$5
local fan=$6
shift 6
local freq=($@)
echo "${time}, ${gov}, ${back}, ${temp}, ${load}, ${fan}, ${freq}"
}
cpu-stats-print-pretty () {
local time=$1
local gov=$2
local back=$3
local temp=$4
local load=$5
local fan=$6
shift 6
local freq=($@)
echo "time $time"
echo "governor $gov"
echo "background processes $back"
echo "CPU temperature C $temp"
echo "system load $load"
echo "CPU fan speed RPM $fan"
echo -n "CPU frequencies MHz "
for f in $freq; do
echo -n " $f"
done
echo
}
cpu-stats () {
local time=$(date +%s)
local gov=$(cpufreq-info -p | awk '{print $3}')
local back=$1
local temp=$(sensors -j | jq -a '.["k10temp-pci-00c3"].Tdie.temp1_input')
local load=$(awk '{print $1}' /proc/loadavg)
local fan=$(sensors | awk '/cpu_fan/{print $2}')
local freq=("${(@f)$(awk '/cpu MHz/{print $4}' /proc/cpuinfo)}")
cpu-stats-print-raw $time $gov $back $temp $load $fan $freq
echo
cpu-stats-print-pretty $time $gov $back $temp $load $fan $freq
}
test-cpu () {
echo "time, governor, background processes, CPU temperature C, system load, CPU fan speed RPM, CPU frequencies MHz"
local ori=$(cpufreq-info -p | awk '{print $3}')
local cores=$(getconf _NPROCESSORS_ONLN)
local pids=()
local jbs
local g
for g in $(cpufreq-info -g); do
sudo cpufreq-set -g $g
repeat 3 {
sleep 60
jbs=$(jobs -l | wc -l)
cpu-stats $jbs
echo
}
repeat $cores {
perl -e '1 while 1' &
pids+=($!)
repeat 10 {
sleep 6
jbs=$(jobs -l | wc -l)
cpu-stats $jbs
echo
}
}
done
local p
for p in $pids; do
kill $p
done
sudo cpufreq-set -g $ori
}
--
underground experts united
https://dataswamp.org/~incal
Reply to: