前言
只是简单简单介绍了如何抓取内核各模块启动时间,以查看有无异常占用时间
步骤
1. 添加内核模块打印 Log:
--- a/init/main.c
+++ b/init/main.c
@@ -785,7 +785,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
if (initcall_blacklisted(fn))
return -EPERM;
- if (initcall_debug)
+ if (1)
ret = do_one_initcall_debug(fn);
else
ret = fn()
2. 对开机拿到的 Log 进行处理
dmesg.txt
通过 notepad++ 搜索过滤 initcall 保存结果为 ModuleTime.txt
ModulTime.txt
Line 101: [ 0.091509] initcall trace_init_flags_sys_exit+0x0/0x1c returned 0 after 0 usecs
Line 103: [ 0.091549] initcall trace_init_flags_sys_enter+0x0/0x1c returned 0 after 0 usecs
Line 106: [ 0.099573] initcall init_hw_perf_events+0x0/0x184 returned 0 after 7801 usecs
Line 108: [ 0.099611] initcall cpu_suspend_init+0x0/0xa4 returned 0 after 3 usecs
Line 111: [ 0.104036] initcall arm64_enable_runtime_services+0x0/0x1e0 returned -1 after 4288 usecs
Line 114: [ 0.109439] initcall asids_init+0x0/0xec returned 0 after 5239 usecs
占用时间提到第一列:
cat ModuleTime.txt | awk '{ print $10" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$11}' > ModuleTime_first.txt
排序,查找最大时间:
cat ModuleTime_first.txt | sort -rn > ModuleTime_first.sort.txt
注:要删除最后几个多余项,因第一过搜索多余项
统计所有模块占用时间和:
cat ModuleTime_first.sort.txt | awk 'BEGIN{ sum=0; print "总和:" } { sum+=$1 } END{ print "等于"; print sum"us" }'