一、简介
本脚本是开启定时记录温度、hogs和top等日志的脚本,用于特定问题的调试,默认不会开启。
本脚本可以定时把记录到的信息打印到文本和终端,hogs不会打印到终端。
下面保存成一个diff, 代码应用到工程 qcom/es17/QNX:
diff --git a/apps/qnx_ap/AMSS/platform/utilities/scripts/record_sysinfo.sh b/apps/qnx_ap/AMSS/platform/utilities/scripts/record_sysinfo.sh
new file mode 100755
index 0000000..169168f
--- /dev/null
+++ b/apps/qnx_ap/AMSS/platform/utilities/scripts/record_sysinfo.sh
@@ -0,0 +1,120 @@
+#! /bin/sh
+TAG=record_sysinfo.sh
+
+## User set: enable/disable record type(1 enable, 0 disable)
+RECORD_THERMAL=1
+RECORD_HOGS=1
+RECORD_TOP=0
+## User set: record interval time(unit seconds)
+SLEEP_TIME_SEC=30
+
+
+LOG_HOME=/usr/nfs_share/qlog/record_sysinfo/
+SYSINFO_LOGPATH=${LOG_HOME}sysinfo.log
+TIME_FMT="+%m-%d %H:%M:%S"
+SYSINFO_LOG_COUNT_FILE=${LOG_HOME}test_count
+
+
+echo_msg()
+{
+ echo "$TAG `date "+%m-%d %H:%M:%S"`: $@";
+}
+
+print_msg()
+{
+ echo "$TAG `date "+%m-%d %H:%M:%S"`: $@" >> $SYSINFO_LOGPATH;
+}
+
+
+RCNT_THERMAL=0
+THERMAL_INFO_SYSFS_FILE="/dev/thermalmgr"
+do_record_thermal()
+{
+ let RCNT_THERMAL++
+ print_msg "--------record NO.$RCNT_THERMAL thermal info start----------"
+ cat ${THERMAL_INFO_SYSFS_FILE} 2>&1 >> $SYSINFO_LOGPATH
+ print_msg "--------record NO.$RCNT_THERMAL thermal info end----------\n\n\n"
+}
+
+RCNT_HOGS=0
+do_record_hogs()
+{
+ let RCNT_HOGS++
+ print_msg "--------record NO.$RCNT_HOGS hogs info start----------"
+ hogs -Sc -i1 2>&1 >> $SYSINFO_LOGPATH
+ print_msg "--------record NO.$RCNT_HOGS hogs info end----------\n\n\n"
+}
+
+RCNT_TOP=0
+do_record_top()
+{
+ let RCNT_TOP++
+ print_msg "--------record NO.$RCNT_TOP top info start----------"
+ top -b -i1 2>&1 >> $SYSINFO_LOGPATH
+ print_msg "--------record NO.$RCNT_TOP top info end----------\n\n\n"
+}
+
+
+do_record_sysinfos()
+{
+ mkdir -p $LOG_HOME
+
+ ## manage test_count
+ if [ -f $SYSINFO_LOG_COUNT_FILE ]; then
+ SYSINFO_LOG_COUNT=$(cat $SYSINFO_LOG_COUNT_FILE)
+ else
+ SYSINFO_LOG_COUNT=0
+ fi
+ let NEW_SYSINFO_LOG_COUNT=SYSINFO_LOG_COUNT+1
+ echo ${NEW_SYSINFO_LOG_COUNT} > $SYSINFO_LOG_COUNT_FILE
+
+ ## rename last log
+ LAST_SYSINFO_LOGPATH="${LOG_HOME}sysinfo_${SYSINFO_LOG_COUNT}_`date "+%m-%d_%H%M%S"`.log"
+ if [ -f "$SYSINFO_LOGPATH" ]; then
+ mv $SYSINFO_LOGPATH $LAST_SYSINFO_LOGPATH
+ echo_msg "do mv $SYSINFO_LOGPATH $LAST_SYSINFO_LOGPATH"
+ print_msg "do mv $SYSINFO_LOGPATH $LAST_SYSINFO_LOGPATH"
+ print_msg "rename last log $LAST_SYSINFO_LOGPATH"
+ fi
+
+ ## print version and enable types
+ print_msg "record_sysinfo version: 0.1 20230504"
+ ENABLED_RECORD_TYPE_STR=""
+ if [ "${RECORD_THERMAL}" == "1" ]; then
+ ENABLED_RECORD_TYPE_STR="${ENABLED_RECORD_TYPE_STR}thermal "
+ fi
+ if [ "${RECORD_HOGS}" == "1" ]; then
+ ENABLED_RECORD_TYPE_STR="${ENABLED_RECORD_TYPE_STR}hogs "
+ fi
+ if [ "${RECORD_TOP}" == "1" ]; then
+ ENABLED_RECORD_TYPE_STR="${ENABLED_RECORD_TYPE_STR}top "
+ fi
+ echo_msg "start NO.${NEW_SYSINFO_LOG_COUNT} times sysinfo record, will record such sysinfos log type: ${ENABLED_RECORD_TYPE_STR}"
+ print_msg "start NO.${NEW_SYSINFO_LOG_COUNT} times sysinfo record, will record such sysinfos log type: ${ENABLED_RECORD_TYPE_STR}"
+
+ print_msg "--------------------------------------------------------------------------------"
+
+ ## do record
+ while [ true ]; do
+ if [ -e /tmp/record_sysinfo_stop -o -e /bin/record_sysinfo_stop ]; then
+ echo_msg "user stop record sysinfo"
+ print_msg "user stop record sysinfo"
+ return
+ fi
+
+ if [ "${RECORD_THERMAL}" == "1" ]; then
+ do_record_thermal
+ fi
+ if [ "${RECORD_HOGS}" == "1" ]; then
+ do_record_hogs
+ fi
+ if [ "${RECORD_TOP}" == "1" ]; then
+ do_record_top
+ fi
+
+ sleep $SLEEP_TIME_SEC
+ done
+}
+
+
+do_record_sysinfos
diff --git a/apps/qnx_ap/target/filesets/qc.scripts.build b/apps/qnx_ap/target/filesets/qc.scripts.build
index c6ace55..74d7e43 100755
--- a/apps/qnx_ap/target/filesets/qc.scripts.build
+++ b/apps/qnx_ap/target/filesets/qc.scripts.build
@@ -15,4 +15,5 @@#ifdef TARGET_BUILD_VARIANT_user#else[perms=0700]scripts/hut_test.sh=aarch64le/bin/hut_test.sh
-#endif
\ No newline at end of file
+#endif
+[perms=0700]scripts/record_sysinfo.sh=aarch64le/bin/record_sysinfo.sh
diff --git a/apps/qnx_ap/target/hypervisor/host/startup.qvmhost.tmpl b/apps/qnx_ap/target/hypervisor/host/startup.qvmhost.tmpl
index f52c811..81ba06d 100755
--- a/apps/qnx_ap/target/hypervisor/host/startup.qvmhost.tmpl
+++ b/apps/qnx_ap/target/hypervisor/host/startup.qvmhost.tmpl
@@ -529,6 +529,15 @@fifi+## record sysinfo for debug
+if [ -e /bin/record_sysinfo ]; then
+ if [ -e /scripts/record_sysinfo.sh ]; then
+ echo "start run record_sysinfo script."
+ . /scripts/record_sysinfo.sh &
+ else
+ echo "record_sysinfo no script."
+ fi
+fi
二、配置
默认开启了抓取 温度和hogs的信息,打开/scripts/record_sysinfo.sh文件(V4项目路径是/mnt/scripts/record_sysinfo.sh)可以修改配置。
先对目录改为可写权限挂载:
mount -uw /mnt
打开文件(vi /scripts/record_sysinfo.sh),找到“## User set”这块代码修改:
## User set: enable/disable record type(1 enable, 0 disable)
RECORD_HOGS=0 ##这里修改为1,启动记录hogs命令的日志
RECORD_TOP=1 ##这里修改为1,启动记录top命令的日志RECORD_CLOCK=1 ##这里修改为1,启动记录clock.sh info|grep apcs命令的日志RECORD_THERMAL=1 ##这里修改为1,启动记录温度的日志## User set: record interval time(unit seconds)
SLEEP_TIME_SEC=5 ##这里修改打印间隔时间,单位秒
三、开启日志记录
1. 单次执行
/scripts/record_sysinfo.sh
2. 参数
-n 收集的内容不打印到终端
<循环任务秒数> 每次收集任务完成后,间隔多久开始下一次收集任务
例子:# 收集的内容不打印到终端,每隔5秒收集一次
/scripts/record_sysinfo.sh -n 5
3. 每次重启都自动开启执行
在目录可写的前提下,touch文件/bin/record_sysinfo开启记录日志标记:
touch /mnt/bin/record_sysinfosync; reset; ## 重启系统
停止日志记录:
临时停止本次日志记录:
touch /tmp/record_sysinfo_stop
停止日志记录:
rm /mnt/bin/record_sysinfo
四、日志文件收集
日志将保存在此处:
/usr/nfs_share/qlog/record_sysinfo/sysinfoxxxx.log
当次开机的日志名字是:
/usr/nfs_share/qlog/record_sysinfo/sysinfo.log
每次脚本启动都把上次log改名:sysinfo测试次数时间.log
五、日志保存参考:
record_sysinfo.sh 01-01 00:00:52: --------record NO.1 thermal info start----------
XO_THERM 80000
SYS_THERM2 83000
SYS_THERM1 93000
PMIC_THERM4 83245
。。。
tsens_tz_sensor3 109900
tsens_tz_sensor2 109200
tsens_tz_sensor1 110300
tsens_tz_sensor0 106500
record_sysinfo.sh 01-01 00:00:52: --------record NO.1 thermal info end----------record_sysinfo.sh 01-01 00:00:53: --------record NO.1 hogs info start----------
PID NAME MSEC PIDS SYS MEMORY
12306 slm 1 0% 0% 228k 0%
839764 name_server 1 0% 0% 480k 0%。。。
6 [idle] 5 0% 0% 0k 0%
7 [idle] 1 0% 0% 0k 0%record_sysinfo.sh 01-01 00:00:56: --------record NO.1 hogs info end----------record_sysinfo.sh 01-01 00:01:26: --------record NO.2 thermal info start----------
XO_THERM 80000
SYS_THERM2 83000
SYS_THERM1 93000