Linux 下的性能分析,包括CPU使用情况,内存使用情况,IO状态等等与系统相关的状态,少不了要使用 sysstat 工具包中的命令,它包括:cifsiostat iostat mpstat pidstat sadf sar tapestat 七条命令。 sysstat 服务启动后,它会自动每个10分钟收集一次系统状态信息,并将它们存储到 /var/log/sa目录下。每天一个文件,文件名分别是sa01, sa02,... sa30.. 但是对于嵌入式设备,一般的busybox里面不会包含sysstat里面的命令,或者说是这些命令有些功能已经被裁减了。为了更好的分析嵌入式设备的状态和性能,可以将sysstat工具包里的命令移植到嵌入式设备中。
http://sebastien.godard.pagesperso-orange.fr/
https://github.com/sysstat/sysstat
在不同版本的linuxPC机上安装,可以直接参考gihub上readme上的介绍就可以。
sysstat的configure文件默认是使用GCC编译的,需要更改为我们所需要的交叉编译工具。我使用的交叉编译工具是:arm-hisiv300-linux-gcc
git clone git://github.com/sysstat/sysstat
CC=arm-hisiv300-linux-gcc ./configure --host=arm --cache-file=home/biao/test/iostat/sysstat/cache_file_0 --prefix=/home/biao/test/iostat/sysstat/biao --exec-prefix=/home/biao/test/iostat/sysstat/biao
上面这条命令解析:
CC=arm-hisiv300-linux-gcc 设置交叉编译工具,这个必须放到./configure 之前,不然不会生效
--host=arm 设置主机类型,这个必须设置,否则会出现configure 错误
--cache-file=home/biao/test/iostat/sysstat/cache_file_0 设置缓存文件
--prefix=/home/biao/test/iostat/sysstat/output 设置输出文件目录,需使用绝对路径
--exec-prefix=/home/biao/test/iostat/sysstat/output 设置可执行文件目录,需使用绝对路径
执行完上面语句,会生成Makefile文件
执行结果如下:
biao@ubuntu:~/test/test/sysstat$ CC=arm-hisiv300-linux-gcc ./configure --host=arm --cache-file=home/biao/test/iostat/sysstat/cache_file_0 --prefix=/home/biao/test/iostat/sysstat/output --exec-prefix=/home/biao/test/iostat/sysstat/output
configure: creating cache home/biao/test/iostat/sysstat/cache_file_0
./configure: line 2181: home/biao/test/iostat/sysstat/cache_file_0: No such file or directory
.
Check programs:
.
checking for arm-gcc... arm-hisiv300-linux-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-hisiv300-linux-gcc accepts -g... yes
checking for arm-hisiv300-linux-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... arm-hisiv300-linux-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether ln -s works... yes
checking for chmod... chmod
checking for chown... chown
checking for ar... ar
checking for install... install
checking for msgfmt... msgfmt
checking for xgettext... xgettext
checking for msgmerge... msgmerge
checking for xz... xz
checking for cp... /bin/cp
checking for chkconfig... no
checking for pkg-config... pkg-config
checking for systemctl... /bin/systemctl
.
Check header files:
.
checking for ANSI C header files... (cached) yes
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking ctype.h usability... yes
checking ctype.h presence... yes
checking for ctype.h... yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking libintl.h usability... no
checking libintl.h presence... no
checking for libintl.h... no
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking net/if.h usability... yes
checking net/if.h presence... yes
checking for net/if.h... yes
checking regex.h usability... yes
checking regex.h presence... yes
checking for regex.h... yes
checking signal.h usability... yes
checking signal.h presence... yes
checking for signal.h... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking for sys/stat.h... (cached) yes
checking sys/sysmacros.h usability... yes
checking sys/sysmacros.h presence... yes
checking for sys/sysmacros.h... yes
.
Check typedefs, structures and compiler characteristics:
.
checking return type of signal handlers... void
checking for size_t... yes
checking for off_t... yes
.
Check library functions:
.
checking for strchr... yes
checking for strcspn... yes
checking for strspn... yes
checking for strstr... yes
checking for sensors support... yes
checking for sensors_get_detected_chips in -lsensors... no
checking for sensors lib... no
.
Check system services:
.
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
.
Check configuration:
.
checking run-commands directory... /etc
checking sadc directory... /home/biao/test/iostat/sysstat/output/lib/sa
INFO: Directory /home/biao/test/iostat/sysstat/output/lib/sa will be created during installation stage.
checking system activity directory... /var/log/sa
checking sysstat configuration directory... /etc/sysconfig
checking National Language Support... no
checking number of daily data files to keep... 7
checking number of days after which data files are compressed... 10
checking group for manual pages... man
checking whether attributes should not be set on files being installed... no
checking whether manual pages should be compressed... no
checking whether system activity directory should be cleaned... no
checking whether cron should start sar automatically... no
checking whether documentation should be installed... yes
checking whether object files should be stripped... yes
.
Now create files:
.
configure: not updating unwritable cache home/biao/test/iostat/sysstat/cache_file_0
configure: creating ./config.status
config.status: creating sa1
config.status: creating sa2
config.status: creating cron/crontab
config.status: creating sysstat.sysconfig
config.status: creating version.h
config.status: creating sysconfig.h
config.status: creating cron/sysstat.cron.daily
config.status: creating cron/sysstat.cron.hourly
config.status: creating cron/sysstat.crond
config.status: creating cron/sysstat.crond.sample.in
config.status: creating sysstat
config.status: creating sysstat.service
config.status: creating cron/sysstat-collect.service
config.status: creating cron/sysstat-collect.timer
config.status: creating cron/sysstat-summary.service
config.status: creating cron/sysstat-summary.timer
config.status: creating man/sa1.8
config.status: creating man/sa2.8
config.status: creating man/sadc.8
config.status: creating man/sadf.1
config.status: creating man/sar.1
config.status: creating man/sysstat.5
config.status: creating man/iostat.1
config.status: creating man/cifsiostat.1
config.status: creating Makefile
Sysstat version: 12.1.1
Installation prefix: /home/biao/test/iostat/sysstat/output
rc directory: /etc
Init directory: /etc/init.d
Systemd unit dir: /lib/systemd/system
Configuration directory: /etc/sysconfig
Man pages directory: ${datarootdir}/man
Compiler: arm-hisiv300-linux-gcc
Compiler flags: -g -O2
biao@ubuntu:~/test/test/sysstat$
sudo make
sudo make install
执行完上面命令,会在configure时设置的目录中生成所有的输出文件,包括库文件和可执行文件:
biao@ubuntu:~/test/iostat/sysstat/output$ pwd
/home/biao/test/iostat/sysstat/output
biao@ubuntu:~/test/iostat/sysstat/output$ ls
bin lib share
biao@ubuntu:~/test/iostat/sysstat/output$ tree
.
├── bin
│ ├── cifsiostat
│ ├── iostat
│ ├── mpstat
│ ├── pidstat
│ ├── sadf
│ ├── sar
│ └── tapestat
├── lib
│ └── sa
│ ├── sa1
│ ├── sa2
│ └── sadc
└── share
├── doc
│ └── sysstat-12.1.1
│ ├── CHANGES
│ ├── COPYING
│ ├── CREDITS
│ ├── FAQ.md
│ ├── README.md
│ └── sysstat-12.0.0.lsm
└── man
├── man1
│ ├── cifsiostat.1
│ ├── iostat.1
│ ├── mpstat.1
│ ├── pidstat.1
│ ├── sadf.1
│ ├── sar.1
│ └── tapestat.1
├── man5
│ └── sysstat.5
└── man8
├── sa1.8
├── sa2.8
└── sadc.8
10 directories, 27 files
biao@ubuntu:~/test/iostat/sysstat/output$
可以直接将bin 文件中的可执行文件拷贝到嵌入式设备中去就可以直接执行。有些命令可以直接使用,有些命令需要打开sysstat功能才能使用,比如sar命令。打开sysstat 命令的方法是:
[root@localhost ~]# chkconfig --level 35 sysstat on
[root@localhost ~]# chkconfig |grep sysstat
sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off