码迷,mamicode.com
首页 > 其他好文 > 详细

交叉编译和使用HTOP

时间:2014-05-08 13:57:59      阅读:485      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   java   

1、什么是htop

 htop来源于top,top是Unix/linux下功能强大的性能检测工具之一,用于实时检测并统计进程的属性和状态,基于ncurses库,可上显示文字界面。但是top已经非常陈旧,不支持鼠标点击操作,不支持查看进程的各个子线程的信息(对于我来说,这个非常重要,有助于分析代码的效率并优化),不支持color显示,易用性较差(曾有人提出改进top但未被接受)。htop官网对htop和top的比较,如下示例图为我的ubuntu12.4的htop效果:

  • In ‘htop‘ you can scroll the list vertically and horizontally to see all processes and complete command lines.
  • In ‘top‘ you are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are triggered by accident).
  • ‘htop‘ starts faster (‘top‘ seems to collect data for a while before displaying anything).
  • In ‘htop‘ you don‘t need to type the process number to kill a process, in ‘top‘ you do.
  • In ‘htop‘ you don‘t need to type the process number or the priority value to renice a process, in ‘top‘ you do.
  • ‘htop‘ supports mouse operation, ‘top‘ doesn‘t
  • ‘top‘ is older, hence, more used and tested.

 bubuko.com,布布扣

 

2、下载htop

 htop官网提供两种下载:部分Linux发行版本的预编译二进制文件,以及源代码方式。

htop官网:http://hisham.hm/htop/index.php?page=downloads
 github上的源码:https://github.com/hishamhm/htop (git clone获取)

 

3、解决htop的编译依赖

 htop编译时,必须有ncurses库的支持,所以编译htop之前,必须确保已存在ncurses库,交叉编译前需编译对应的ncurses库。

ncurses最新版本源码:ftp://invisible-island.net/ncurses/ncurses.tar.gz

 

bubuko.com,布布扣
 1 $ tar -zxvf ncurses-5.9.tar.gz

 2 $ cd ncurses-5.9
 3 #配置前,可使用./configure --help查看配置帮助
 4 $ ./configure CC=arm-hisiv200-linux-gnueabi-gcc --prefix=$PWD/_install --host=arm-linux --with-shared #编译为共享库
 5 $ make && make install
 6 $ ls -lh _install/lib 
 7 total 4.5M
 8 -rw-r--r-- 1 root root  93K  5月  6 15:04 libform.a
 9 -rw-r--r-- 1 root root 529K  5月  6 15:04 libform_g.a
10 lrwxrwxrwx 1 root root   12  5月  6 15:04 libform.so -> libform.so.5
11 lrwxrwxrwx 1 root root   14  5月  6 15:04 libform.so.5 -> libform.so.5.9
12 -rwxr-xr-x 1 root root  68K  5月  6 15:04 libform.so.5.9
13 -rw-r--r-- 1 root root  51K  5月  6 15:04 libmenu.a
14 -rw-r--r-- 1 root root 321K  5月  6 15:04 libmenu_g.a
15 lrwxrwxrwx 1 root root   12  5月  6 15:04 libmenu.so -> libmenu.so.5
16 lrwxrwxrwx 1 root root   14  5月  6 15:04 libmenu.so.5 -> libmenu.so.5.9
17 -rwxr-xr-x 1 root root  36K  5月  6 15:04 libmenu.so.5.9
18 -rw-r--r-- 1 root root 446K  5月  6 15:04 libncurses.a
19 -rw-r--r-- 1 root root 129K  5月  6 15:04 libncurses++.a
20 -rw-r--r-- 1 root root 2.3M  5月  6 15:04 libncurses_g.a
21 lrwxrwxrwx 1 root root   15  5月  6 15:04 libncurses.so -> libncurses.so.5
22 lrwxrwxrwx 1 root root   17  5月  6 15:04 libncurses.so.5 -> libncurses.so.5.9
23 -rwxr-xr-x 1 root root 327K  5月  6 15:04 libncurses.so.5.9
24 -rw-r--r-- 1 root root  23K  5月  6 15:04 libpanel.a
25 -rw-r--r-- 1 root root 131K  5月  6 15:04 libpanel_g.a
26 lrwxrwxrwx 1 root root   13  5月  6 15:04 libpanel.so -> libpanel.so.5
27 lrwxrwxrwx 1 root root   15  5月  6 15:04 libpanel.so.5 -> libpanel.so.5.9
28 -rwxr-xr-x 1 root root  15K  5月  6 15:04 libpanel.so.5.9
29 lrwxrwxrwx 1 root root   17  5月  6 15:04 terminfo -> ../share/terminfo

bubuko.com,布布扣

 

    Libncurses库用来在显示器上显示文本界面。典型例子:Linux内核的make menuconfig配置界面,busybox的make menuconfig,fdisk磁盘分区工具界面,甚至open suse的yasT2。

    Libform库用于 在ncurses中使用表格。

    Libmenu库用于在ncurses中使用菜单。

    Libpanel库用于在ncurses中使用面板。

 将编译好的这些动态库拷贝到htop的源码目录下。

 htop的交叉编译流程类似:

 1 $ ./configure CC=arm-hisiv200-linux-gnueabi-gcc  --prefix=$PWD/_install

2 $ make && make install 

3 $ ls -lh _install

 

4、 命令的挂载和执行

htop程序的执行需要libcurses和term的支持,执行之前请检查TERM环境变量的值(echo $TERM),以及TERMINFO的值(echo $TERMINFO,为空则必须保证/usr/share/terminfo存在对应的term程序)。 

理想的状态是,将libcurses(放在/lib、/usr/lib 或/usr/local/lib)和htop直接拷贝到开发板上直接就能运行,但如果嵌入式Linux裁剪的太厉害,将/usr/share/terminfo目录裁剪了,htop将无法正常启动。此时可从别处拷贝terminfo目录。

 最不理想的状态是板子将所有程序编译成了静态程序,同时裁撤了所有lib和/usr/share目录,且此时文件系统为只读,此时可以将机型对应的linux lib目录mount到板子上的/lib目录,同时将设置TERMINFO的环境变量为对应的terminfo目录(比如:export TERMINFO="/var/nfs/terminfo")。

 举例:如$TERM=xterm,则/usr/share/terminfo/x/xterm必须存在。

 

5、htop的应用举例 

详细应用请man htop查阅。 

选择某一进程,按s:用strace追踪进程的系统调用

P、T、M和top下是一样的,按CPU,Time+、Memory使用排序。
下面有F1~F10的功能和对应的字母快捷键。
Shortcut Key Function Key Description
h F1 Invoke htop Help
S F2 Htop Setup Menu
/ F3 Search for a Process
I F4 Invert Sort Order
t F5 Tree View
> F6 Sort by a column
[ F7 Nice - (change priority)
] F8 Nice + (change priority)
k F9 Kill a Process
q F10 Quit htop

 此段落来自:http://www.lylinux.org/linux-top%E5%91%BD%E4%BB%A4%E7%9A%84%E6%9B%BF%E4%BB%A3%E8%80%85htop.html

 

交叉编译和使用HTOP,布布扣,bubuko.com

交叉编译和使用HTOP

标签:des   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/txsf/p/3713991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!