实际项目遇到一个程序CPU突然飙升的问题,希望查看是哪个线程导致的CPU飙升,板子自带的top命令不支持显示线程级别的信息,所以需要自己编译一个支持显示线程信息的top命令
上网查看了,主要就是两个htop和procps
其中htop我交叉编译完,放到板子上运行直接崩溃,猜想可能和ncurses库的版本有关,折腾了一会不行转用procps。
Procps是一个工具集,提供如下的command
· free - Report the amount of free and used memory in the system
· kill - Send a signal to a process based on PID
· pgrep - List processes based on name or other attributes
· pkill - Send a signal to a process based on name or other attributes
· pmap - Report memory map of a process
· ps - Report information of processes
· pwdx - Report current directory of a process
· skill - Obsolete version of pgrep/pkill
· slabtop - Display kernel slab cache information in real time
· snice - Renice a process
· sysctl - Read or Write kernel parameters at run-time
· tload - Graphical representation of system load average
· top - Dynamic real-time view of running processes
· uptime - Display how long the system has been running
· vmstat - Report virtual memory statistics
· w - Report logged in users and what they are doing
· watch - Execute a program periodically, showing output fullscreen
地址:https://gitlab.com/procps-ng/procps/
开始选用的是procps-v3.3.16,编译完发现top命令还是不支持显示线程信息,然后使用最新的procps-v4.0.3才OK.
编译步骤:
下载到版本压缩包后,解压,进入目录,比如我的是
gateway@edenliu_ubuntu:~/Eden/procps-v4.0.3$
执行命令:
./ autogen.sh 生成./configure 文件
这一步可能报如下错误:
Error: You must have `libtool’ installed.
gateway@edenliu_ubuntu:~/Eden/procps-v3.3.16$ ./autogen.sh
./autogen.sh: 33: ./autogen.sh: libtool: not found
You must have libtool-2 installed to generate procps-ng build system.
执行:
apt-get install libtool
和
apt-get install libtool-bin
后即可,如果有其他未安装的,根据提示安装对应工具也就可以了
生成configure后,执行如下命令:
./configure --target=arm-poky-linux --host=arm-poky-linux –prefix=/home/gateway/Eden/install_procps_4 CC="/opt/fsl-imx-fb/4.14-sumo/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux/arm-poky-linux-gcc -march=armv7ve -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -D__arm__=1 --sysroot=/opt/fsl-imx-fb/4.14-sumo/sysroots/cortexa7hf-neon-poky-linux-gnueabi" CFLAGS="-mfloat-abi=hard -I /opt/fsl-imx-fb/4.14-sumo/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include -L/opt/fsl-imx-fb/4.14-sumo/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib" CPPFLAGS="-I /opt/fsl-imx-fb/4.14-sumo/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include -march=armv7ve -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7"
其中一些配置是我的CPU需要的特定配置,大家主要关注 –target –host –prefix, CFLAGS 换成自己需要的就行了
./configure成功后就是make & make install了,成功的话就会在prefix的路径下生成如下信息
gateway@edenliu_ubuntu:~/Eden/install_procps_4$ tree -L 2
.
├── bin
│ ├── free
│ ├── kill
│ ├── pgrep
│ ├── pidof
│ ├── pkill
│ ├── pmap
│ ├── ps
│ ├── pwdx
│ ├── slabtop
│ ├── tload
│ ├── top
│ ├── uptime
│ ├── vmstat
│ ├── w
│ └── watch
├── include
│ └── libproc2
├── lib
│ ├── libncurses.so.5
│ ├── libncursesw.so.5
│ ├── libproc2.a
│ ├── libproc2.la
│ ├── libproc2.so -> libproc2.so.0.0.1
│ ├── libproc2.so.0 -> libproc2.so.0.0.1
│ ├── libproc2.so.0.0.1
│ └── pkgconfig
├── sbin
│ └── sysctl
└── share
├── doc
├── locale
└── man
将bin中需要的工具和lib中的库拷贝到目标板子 运行即可了