在AMD PetaLinux中添加命令pstree

命令pstree将相关进程以树状图显示,方便查看进程间的关系。由于调试需要,需要在Linux里使用命令pstree。但是PetaLinux产生的Linux映像,默认不带命令pstree。

在rootfs里查找pstree

首先使用命令“petalinux-config -c rootfs ”尝试在rootfs里查找pstree。没有找到pstree。

在psmisc里查找pstree

在Debian里,软件包psmisc包含pstree。

This package contains miscellaneous utilities that use the proc FS:

  • fuser: identifies processes that are using files or sockets.
  • killall: kills processes by name (e.g. "killall -HUP named").
  • peekfd: shows the data traveling over a file descriptor.
  • pstree: shows currently running processes as a tree.
  • prtstat: print the contents of /proc//stat

在PetaLinux工程里能找到对应的bb文件。


hankf@XSZGS4:k26-cms-peta-0118$ find -name "*psmisc*.bb*"
./components/yocto/layers/core/meta/recipes-extended/psmisc/psmisc_23.4.bb

hankf@XSZGS4:k26-cms-peta-0118$ ls -l ./components/yocto/layers/core/meta/recipes-extended/psmisc/psmisc_23.4.bb 
-rw-r--r-- 1 hankf hankf 343 May 22 18:19 ./components/yocto/layers/core/meta/recipes-extended/psmisc/psmisc_23.4.bb

hankf@XSZGS4:k26-cms-peta-0118$ cat ./components/yocto/layers/core/meta/recipes-extended/psmisc/psmisc_23.4.bb
require psmisc.inc
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3"

SRC_URI = "git://gitlab.com/psmisc/psmisc.git;protocol=https;branch=master \
           file://0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch \
           "
SRCREV = "5fab6b7ab385080f1db725d6803136ec1841a15f"
S = "${WORKDIR}/git"

配置对应的模块, 却失败。

hankf@XSZGS4:k26-cms-peta-0118$ petalinux-config -c psmisc
[INFO] Sourcing buildtools
[INFO] Silentconfig project
......
Warning: Root password set to 'root', It is highly recommended to change Root password.
[INFO] Generating workspace directory
[INFO] Configuring: psmisc
[INFO] bitbake psmisc -c menuconfig
NOTE: Started PRServer with DBfile: proj/hankf/kv260/v221/k26-cms-peta-0118/build/cache/prserv.sqlite3, Address: 127.0.0.1:35651, PID: 9607
Loading cache: 100% |##########################################################################################################################################################| Time: 0:00:02
Loaded 5398 entries from dependency cache.
Parsing recipes: 100% |########################################################################################################################################################| Time: 0:00:03
Parsing of 3601 .bb files complete (3596 cached, 5 parsed). 5403 targets, 507 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
ERROR: Task do_menuconfig does not exist for target psmisc (proj/hankf/kv260/v221/k26-cms-peta-0118/components/yocto/layers/core/meta/recipes-extended/psmisc/psmisc_23.4.bb:do_menuconfig). Close matches:
  do_configure
ERROR: Command execution failed: 1

Summary: There were 2 ERROR messages shown, returning a non-zero exit code.
ERROR: bitbake failed to configure psmisc
ERROR: Failed to config psmisc. Check the proj/hankf/kv260/v221/k26-cms-peta-0118/build/config.log file for more details...```

在busybox里查找pstree

单板上已经有psmisc里的killall。检查killall,它来自于busybox。

root@k26-cms-xsa-temp-peta:~# which killall
/usr/bin/killall

root@k26-cms-xsa-temp-peta:~# ls -l /usr/bin/killall
lrwxrwxrwx 1 root root 12 Mar  9  2018 /usr/bin/killall -> /bin/busybox

root@k26-cms-xsa-temp-peta:~# ls -l /bin/busybox
-rwsr-xr-x 1 root root 1736016 Mar  9  2018 /bin/busybox

root@k26-cms-xsa-temp-peta:~# ls -l -h /bin/busybox
-rwsr-xr-x 1 root root 1.7M Mar  9  2018 /bin/busybox

于是使用命令“petalinux-config -c busybox”,尝试在busybox里配置pstree。有对应的命令和界面,选择使能pstree和其它模块。

hankf@XSZGS4:k26-cms-peta-0118$ petalinux-config -c busybox 
[INFO] Sourcing buildtools
[INFO] Silentconfig project
[INFO] Sourcing build environment
..............
Loaded 0 entries from dependency cache.
Parsing recipes: 100% |########################################################################################################################################################| Time: 0:00:23
Parsing of 3601 .bb files complete (0 cached, 3601 parsed). 5403 targets, 507 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Initialising tasks: 100% |#####################################################################################################################################################| Time: 0:00:12
Sstate summary: Wanted 50 Local 0 Network 50 Missed 0 Current 47 (100% match, 100% complete)
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 432 tasks of which 426 didn't need to be rerun and all succeeded.
[INFO] bitbake busybox -c diffconfig
......
generate_bbappend /proj/hankf/kv260/v221/k26-cms-peta-0118/build/tmp/work/cortexa72-cortexa53-xilinx-linux/busybox/1.34.1-r0/user_2023-08-07-04-25-00.cfg proj/hankf/kv260/v221/k26-cms-peta-0118/project-spec/meta-user/
[INFO] recipetool appendsrcfile -wW proj/hankf/kv260/v221/k26-cms-peta-0118/project-spec/meta-user/ busybox /proj/hankf/kv260/v221/k26-cms-peta-0118/build/tmp/work/cortexa72-cortexa53-xilinx-linux/busybox/1.34.1-r0/user_2023-08-07-04-25-00.cfg
NOTE: Starting bitbake server...
NOTE: Started PRServer with DBfile: /proj/hankf/kv260/v221/k26-cms-peta-0118/build/cache/prserv.sqlite3, Address: 127.0.0.1:46587, PID: 7626
Loading cache...done.

在生成的文件里,看到“CONFIG_PSTREE”被使能。

hankf@XSZGS4:k26-cms-peta-0118$ cd project-spec/

hankf@XSZGS4:project-spec$ find -name "*busybox*bb*"
./meta-user/recipes-core/busybox/busybox_%.bbappend

hankf@XSZGS4:k26-cms-peta-0118$ cat   project-spec/meta-user/recipes-core/busybox/busybox/user_2023-08-07-04-25-00.cfg   
# Thu Sep 30 20:27:40 2021
CONFIG_IOSTAT=y
CONFIG_KILLALL5=y
CONFIG_LSOF=y
CONFIG_MPSTAT=y
CONFIG_NMETER=y
CONFIG_PSTREE=y
CONFIG_SMEMCAP=y
CONFIG_FEATURE_SHOW_THREADS=y

验证

编译PetaLinux工程后,再启动单板,单板上有pstree命令。

root@k26-cms-xsa-temp-peta:~# which pstree
/usr/bin/pstree

root@k26-cms-xsa-temp-peta:~# ls -l /usr/bin/pstree
lrwxrwxrwx 1 root root 12 Mar  9  2018 /usr/bin/pstree -> /bin/busybox

root@k26-cms-xsa-temp-peta:~# ls -l -h /usr/bin/pstree
lrwxrwxrwx 1 root root 12 Mar  9  2018 /usr/bin/pstree -> /bin/busybox
posted @ 2023-08-07 15:49  HankFu  阅读(86)  评论(0编辑  收藏  举报