Slightly improved code
original code displays 1 cpu freq and 1 temperature every 2 seconds
benchmark:
real 1m0.056s
user 0m0.254s
sys 0m0.353s
new code displays frequencies of groups of cpus (2 in my case) and all temperatures (also 2 in my case) every 0.5 seconds
benchmark:
real 1m0.083s
user 0m0.271s
sys 0m0.113s
May need cleaning/testing...
#! /bin/bash
# Usage: cpu-temp-speed
#
# Monitors CPU clock speed and temperature.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
for file in /usr/lib/bash/sleep /usr/lib32/bash/sleep /usr/lib64/bash/sleep; do [ -r "$file" ] && enable -f "$file" sleep && break; done
policies=(/sys/devices/system/cpu/cpufreq/policy[0-9]*)
cpu_temp=(/sys/class/thermal/thermal_zone?/temp)
[ ! -e "${cpu_temp[0]}" ] && exit
while true; do
echo -n "[ "
for cf in ${policies[@]}; do
read clk < $cf/scaling_cur_freq
printf "%4.0fMHz " $((clk))e-3
done
echo -n "] [ "
for ct in ${cpu_temp[@]}; do
read cpu < $ct
printf "%2.0f°C " $((cpu))e-3
done
echo -n "]"
sleep 0.5
echo -ne "\r"
done