blob: c0bc548349a4b5fa03c25f46d96b32197b0f57e9 [file] [log] [blame]
#!/bin/sh
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Logger wrapper.
log_message() {
logger -t temp_logger "$@"
}
# Output xx:yyC where xx is temp sensor id and yy is the actual temperature.
get_sensor_temp() {
local zone="$1"
local tempc=0
local index=""
local tempstr=""
if [ ! -r "${zone}" ]; then
return
fi
tempc=$(($(cat "${zone}") / 1000))
index=$(echo "${zone}" | grep -o -E '[0-9]+')
tempstr=$(printf "%02d:%dC" "${index}" "${tempc}")
echo "${tempstr}"
}
# Glob all temp sensors sysfs and output temperatures with get_sensor_temp().
get_all_sensor_temps() {
local logstr=""
local tempstr=""
for zone in /sys/class/thermal/thermal_zone*/temp; do
tempstr=$(get_sensor_temp "${zone}")
logstr="${logstr} ${tempstr}"
done
echo "${logstr}"
}
# Read PL1 from powercap sysfs (Intel only), output nothing otherwise.
get_pl1() {
local pl1="/sys/class/powercap/intel-rapl:0/constraint_0_power_limit_uw"
local pl1uw=0
local pl1str=""
if [ ! -r "${pl1}" ]; then
return
fi
pl1uw=$(cat "${pl1}")
pl1str=$(printf "PL1:%.3fW" "$((pl1uw))e-6")
echo "${pl1str}"
}
main() {
if [ $# -ne 0 ]; then
echo "Usage: $0" >&2
exit 1
fi
while true; do
log_message "$(get_all_sensor_temps)" "$(get_pl1)"
sleep 60
done
}
main "$@"