1. 查看系统启动的时间消耗:
# env LD_DEBUG=statistics LD_DEBUG_OUTPUT=debugfile /usr/bin/ls
# cat dbugfile.104876
104876:
104876: runtime linker statistics:
104876: total startup time in dynamic loader: 333159 cycles
104876: time needed for relocation: 77891 cycles (23.3%)
104876: number of relocations: 248
104876: number of relocations from cache: 3
104876: number of relative relocations: 1558
104876: time needed to load objects: 197597 cycles (59.3%)
104876:
104876: runtime linker statistics:
104876: final number of relocations: 264
104876: final number of relocations from cache: 3
2. 查看程序依赖的动态库
# ldd /usr/bin/ls
linux-vdso.so.1 (0x00007fff5dbbc000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007ffb0ab1c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffb0a92a000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007ffb0a89a000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffb0a894000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffb0ab84000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffb0a871000)
3. 然后可以考虑使用prelink工具,在prelink.conf中指定预加载的动态库
# prelink -a
预链接之后,在坚持程序启动的耗时。
这个方法对启动时加载的动态库很多、很大时,效果明显。
缺点:
动态库变更后,要重写执行预加载的操作。