1.cmdline中传入initcall_debug

对于android开发环境来说,可以在device中的BoardConfig.mk中添加如下:


BOARD_KERNEL_CMDLINE += initcal_debug

对于linux系统,可以在defconfig中添加:


CONFIG_CMDLINE="initcall_debug"

当然这种方式同样适用于android设备。

当我们使用上面的配置重新编译了boot.img之后烧入系统,会发现在dmesg打印的启动阶段的log中有如下风格的打印:



 [    4.746509] initcall phy_init+0x0/0x6c returned 0 after 186 usecs

 [    4.763443] initcall usb_init+0x0/0x17c returned 0 after 16525 usecs

 [    4.763483] initcall dual_role_class_init+0x0/0x8c returned 0 after 27 usecs

 [    4.774618] initcall usb_phy_generic_init+0x0/0x24 returned 0 after 10861 usecs

 [    4.774662] initcall usb_udc_init+0x0/0x70 returned 0 after 31 usecs

 [    4.774741] initcall serio_init+0x0/0x44 returned 0 after 65 usecs

 [    4.774800] initcall input_init+0x0/0x110 returned 0 after 45 usecs

 [    4.775528] initcall qpnp_pon_init+0x0/0x24 returned 0 after 698 usecs

 [    4.775575] initcall rtc_init+0x0/0x6c returned 0 after 34 usecs

 [    4.776189] initcall i2c_gpio_init+0x0/0x48 returned 0 after 587 usecs

 [    4.780986] initcall media_devnode_init+0x0/0x98 returned 0 after 4672 usecs

 [    4.785784] initcall videodev_init+0x0/0x9c returned 0 after 4673 usecs

 [    4.785842] initcall init_dvbdev+0x0/0xf4 returned 0 after 43 usecs

 [    4.785906] initcall rc_core_init+0x0/0x6c returned 0 after 51 usecs

 [    4.785953] initcall power_supply_class_init+0x0/0x58 returned 0 after 33 usecs

 [    4.785993] initcall hwmon_init+0x0/0x48 returned 0 after 27 usecs

 [    4.817853] initcall thermal_init+0x0/0x140 returned 0 after 31094 usecs

 [    4.844966] initcall tsens_tm_init_driver+0x0/0x24 returned 0 after 26456 usecs

2.使能loglevel

当我们使能initcall_debug功能之后发现,这个log并没有默认输出到串口中,对于那些系统启动过程就卡死的问题,我们很难看到对应的log来定位问题,所以我们可以考虑把loglevel默认打印级别调高,比如在cmdline中设置loglevel=8,这样就会默认把所有log输出到串口了。方法如下:

对于android开发环境来说,可以在device中的BoardConfig.mk中添加如下:


BOARD_KERNEL_CMDLINE += initcal_debug loglevel=8

对于linux系统,可以在defconfig中添加:


CONFIG_CMDLINE="initcall_debug loglevel=8"

3.解析initcall debug log


cat log.txt | grep "initcall" | sed "s/\(.*\)after\(.*\)/\2 \1/g" | sort -n

这个命令可以解析log中的initcall数据,并根据时间长短进行排序,结果如下:


 27 usecs  [    4.763483] initcall dual_role_class_init+0x0/0x8c returned 0 

 27 usecs  [    4.785993] initcall hwmon_init+0x0/0x48 returned 0 

 31 usecs  [    4.774662] initcall usb_udc_init+0x0/0x70 returned 0 

 33 usecs  [    4.785953] initcall power_supply_class_init+0x0/0x58 returned 0 

 34 usecs  [    4.775575] initcall rtc_init+0x0/0x6c returned 0 

 43 usecs  [    4.785842] initcall init_dvbdev+0x0/0xf4 returned 0 

 45 usecs  [    4.774800] initcall input_init+0x0/0x110 returned 0 

 51 usecs  [    4.785906] initcall rc_core_init+0x0/0x6c returned 0 

 65 usecs  [    4.774741] initcall serio_init+0x0/0x44 returned 0 

 186 usecs  [    4.746509] initcall phy_init+0x0/0x6c returned 0 

 587 usecs  [    4.776189] initcall i2c_gpio_init+0x0/0x48 returned 0 

 698 usecs  [    4.775528] initcall qpnp_pon_init+0x0/0x24 returned 0 

 4672 usecs  [    4.780986] initcall media_devnode_init+0x0/0x98 returned 0 

 4673 usecs  [    4.785784] initcall videodev_init+0x0/0x9c returned 0 

 10861 usecs  [    4.774618] initcall usb_phy_generic_init+0x0/0x24 returned 0 

 16525 usecs  [    4.763443] initcall usb_init+0x0/0x17c returned 0 

 26456 usecs  [    4.844966] initcall tsens_tm_init_driver+0x0/0x24 returned 0 

 31094 usecs  [    4.817853] initcall thermal_init+0x0/0x140 returned 0 

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐