From e17961f67e9e073c2bfe258a0d951a2012ecf4c2 Mon Sep 17 00:00:00 2001 From: Chuck Date: Sun, 21 Feb 2021 12:27:55 +0800 Subject: [PATCH] optimize the performance of obtaining CPU temperature (#6398) 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 --- 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 d1b697eb0..c55738b65 100755 --- a/package/lean/autocore/files/arm/sbin/cpuinfo +++ b/package/lean/autocore/files/arm/sbin/cpuinfo @@ -17,7 +17,7 @@ fi if grep -q "ipq40xx" "/etc/openwrt_release"; then sys_temp="$(sensors | grep -Eo '\+[0-9]+.+C' | sed ':a;N;$!ba;s/\n/ /g;s/+//g')" else - sys_temp="$(awk "BEGIN{printf (\"%.1f\n\",$(cat /sys/class/thermal/thermal_zone0/temp)/1000) }")°C" + sys_temp="$(awk '{ printf("%.1f °C", $0 / 1000) }' /sys/class/thermal/thermal_zone0/temp)" fi echo -n "${cpu_arch} x ${cpu_cores} (${cpu_freq}, ${sys_temp})"