Linux性能分析的若干工具

注意:文章仅仅是一个整理,知识的搬运。关于更多的信息,请参考相关工具的官网

1、stress和stress-ng

stress is a deliberately simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPLv2. 下载地址: stress

以下是stress的命令说明

`stress' imposes certain types of compute stress on your system

Usage: stress [OPTION [ARG]] ...
 -?, --help         show this help statement
     --version      show version statement
 -v, --verbose      be verbose
 -q, --quiet        be quiet
 -n, --dry-run      show what would have been done
 -t, --timeout N    timeout after N seconds
     --backoff N    wait factor of N microseconds before work starts
 -c, --cpu N        spawn N workers spinning on sqrt()
 -i, --io N         spawn N workers spinning on sync()
 -m, --vm N         spawn N workers spinning on malloc()/free()
     --vm-bytes B   malloc B bytes per vm worker (default is 256MB)
     --vm-stride B  touch a byte every B bytes (default is 4096)
     --vm-hang N    sleep N secs before free (default none, 0 is inf)
     --vm-keep      redirty memory instead of freeing and reallocating
 -d, --hdd N        spawn N workers spinning on write()/unlink()
     --hdd-bytes B  write B bytes per hdd worker (default is 1GB)

Example: stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s

Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size).

stress-ng是一个更加强悍的stress工具,支持的options更多,应用更灵活,可以模拟更多场景. 下载地址: stress-ng

2、sysstat

System performance tools for the Linux operating system。 下载地址 sysstat

The sysstat package contains various utilities, common to many commercial Unixes, to monitor system performance and usage activity:

  • iostat reports CPU statistics and input/output statistics for block devices and partitions.
  • mpstat reports individual or combined processor related statistics.
  • pidstat reports statistics for Linux tasks (processes) : I/O, CPU, memory, etc.
  • tapestat reports statistics for tape drives connected to the system.
  • cifsiostat reports CIFS statistics.

3、strace

trace system calls and signals 关于其详细介绍见strace

4、free\top

不用说,大家都知道

5、进化top系列atop、htop、iftop、iotop、slabtop

这些命令搭配stress/stress-ng来玩,更快了解其用途

5.1 atop

atop: Atop is an ASCII full-screen performance monitor for Linux that is capable of reporting the activity of all processes (even if processes have finished during the interval), daily logging of system and process activity for long-term analysis, highlighting overloaded system resources by using colors, etc. 详细见官网

Usage: atop [-flags] [interval [samples]]
                or
Usage: atop -w  file  [-S] [-a] [interval [samples]]
       atop -r [file] [-b hh:mm] [-e hh:mm] [-flags]

        generic flags:
          -V  show version information
          -a  show or log all processes (i.s.o. active processes only)
          -R  calculate proportional set size (PSS) per process
          -P  generate parseable output for specified label(s)
          -L  alternate line length (default 80) in case of non-screen output
          -f  show fixed number of lines with system statistics
          -F  suppress sorting of system resources
          -G  suppress exited processes in output
          -l  show limited number of lines for certain resources
          -y  show individual threads
          -1  show average-per-second i.s.o. total values

          -x  no colors in case of high occupation
          -g  show general process-info (default)
          -m  show memory-related process-info
          -d  show disk-related process-info
          -n  show network-related process-info
          -s  show scheduling-related process-info
          -v  show various process-info (ppid, user/group, date/time)
          -c  show command line per process
          -o  show own defined process-info
          -u  show cumulated process-info per user
          -p  show cumulated process-info per program (i.e. same name)
          -j  show cumulated process-info per container

          -C  sort processes in order of cpu-consumption (default)
          -M  sort processes in order of memory-consumption
          -D  sort processes in order of disk-activity
          -N  sort processes in order of network-activity
          -A  sort processes in order of most active resource (auto mode)

        specific flags for raw logfiles:
          -w  write raw data to   file (compressed)
          -r  read  raw data from file (compressed)
              special file: y[y...] for yesterday (repeated)
          -S  finish atop automatically before midnight (i.s.o. #samples)
          -b  begin showing data from specified time
          -e  finish showing data after specified time

        interval: number of seconds   (minimum 0)
        samples:  number of intervals (minimum 1)

If the interval-value is zero, a new sample can be
forced manually by sending signal USR1 (kill -USR1 pid_atop)
or with the keystroke 't' in interactive mode.

下图是一个简单测试

stress --cpu 8  -t 1000s
atop

5.2 htop

htop是一个超级强悍的工具,支持鼠标操作,可以好好学习(目前我不会,囧). 详见官网htop

5.3 iftop

iftop does for network usage what top(1) does for CPU usage. It listens to network traffic on a named interface and displays a table of current bandwidth usage by pairs of hosts. Handy for answering the question “why is our ADSL link so slow?”. 详见官网iftop

关于iftop的使用,可以参考如下文章 Linux流量监控工具 - iftop (最全面的iftop教程)

当然关于流量统计,iptables也可以做的

5.4 iotop

linux系统的io监控,详见官网iotop

5.5 slabtop

slabtop displays detailed kernel slab cache information in real time. It displays a listing of the top caches sorted by one of the listed sort criteria. It also displays a statistics header filled with slab layer information. 详见官网 slabtop

6 /proc文件系统

proc文件系统里有很多可能显示系统当前状态的文件,我们应该充分利用它们,而不是一开始就需要用到其他工具,当然前提是对linux系统有较多理解。

总结:

  1. 关于以上工具,在生产环境中可能不允许安装,因此第一时间充分利用系统自带的工具,其实很多时候都可以解决问题了。
  2. 关于性能分析的工具确实很多,这里仅列举了几个,而且工具间的功能存在类似。大家在分析实际问题时在决定使用哪个工具吧。

你可能感兴趣的:(Linux_debug)