编译显示线程的top命令

实际项目遇到一个程序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了

编译遇到报错:

undefined reference to rpl_malloc

注释掉config.h中的这两行,问题解决

/* Define to rpl_malloc if the replacement function should be used. */

//#define malloc rpl_malloc

/* Define to `int' if <sys/types.h> does not define. */

/* #undef pid_t */

/* Define to rpl_realloc if the replacement function should be used. */

//#define realloc rpl_realloc

最后成功的话就会在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中的库拷贝到目标板子 运行即可了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值