From 1e53f0d4f3fabfa2e3c53d75f57364aa3c3278bd Mon Sep 17 00:00:00 2001 From: Chuck Date: Thu, 18 Feb 2021 19:38:06 +0800 Subject: [PATCH] autocore: optimize the performance of obtaining CPU temperature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Preformance Test (on NanoPi R2s, repeat 1000 times): old command: temp="$(awk "BEGIN{printf (\"%.1f\n\",$(cat /sys/class/thermal/thermal_zone0/temp)/1000) }")°C" ``` real 0m 9.20s user 0m 3.29s sys 0m 6.24s ``` new command: temp="$(awk '{ printf("%.1f °C", $0 / 1000) }' /sys/class/thermal/thermal_zone0/temp)" ``` real 0m 5.57s user 0m 1.78s sys 0m 3.97s ``` Signed-off-by: Chuck [adjusted for our own tree] Signed-off-by: CN_SZTL --- package/lean/autocore/files/arm/sbin/cpuinfo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/lean/autocore/files/arm/sbin/cpuinfo b/package/lean/autocore/files/arm/sbin/cpuinfo index 1ea33f869e..630e92de53 100755 --- a/package/lean/autocore/files/arm/sbin/cpuinfo +++ b/package/lean/autocore/files/arm/sbin/cpuinfo @@ -18,7 +18,7 @@ if grep -q "bcm27xx" "/etc/openwrt_release"; then cpu_temp="$(vcgencmd measure_temp | awk -F '=' '{print $2}' | awk -F "'" '{print $1}')°C" else [ -e "/sys/class/thermal/thermal_zone0/temp" ] && \ - cpu_temp="$(awk "BEGIN{printf (\"%.1f\n\",$(cat "/sys/class/thermal/thermal_zone0/temp")/1000)}")°C" + cpu_temp="$(awk '{printf("%.1f°C", $0 / 1000)}' /sys/class/thermal/thermal_zone0/temp)" fi if [ -z "${cpu_freq}" ] && [ -z "${cpu_temp}" ]; then