zoukankan      html  css  js  c++  java
  • Linux性能分析工具之----mpstat

    简介

    mpstat是MultiProcessor Statics的缩写,是实时系统监控工具,其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件中。在多CPU系统里。其不但能查看所有CPU的平均状况信息,而且能查看特定CPU的信息。

    命令格式

    mpstat [ -A ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ] [ -P { cpu [,...] | ON | ALL } ] [ interval [ count ] ]
    

    OPTIONS

    -A: 等同于-u -I ALL -P ALL
    -I:可以指定SUM CPU SCPU ALL四个参数,SUM表示每个处理器的中断总数,CPU表示每个核的每秒中断数量, SCPU表示每个核每秒的软中断数量,内核版本在2.6.31之后才支持。
    -P: 统计的CPU编号,一般用ALL
    -u: 输出列的信息
    -V: 查看工具版本号
    

    使用

    每隔1s输出所有cpu的使用情况

    mpstat -P ALL 1
    Linux 3.10.0-693.el7.x86_64 (zhanghao)   2020年05月14日   _x86_64_  (2 CPU)
     
    12时42分03秒 CPU  %usr  %nice  %sys %iowait  %irq  %soft %steal %guest %gnice  %idle
    12时42分04秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分04秒  0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分04秒  1  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
     
    12时42分04秒 CPU  %usr  %nice  %sys %iowait  %irq  %soft %steal %guest %gnice  %idle
    12时42分05秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分05秒  0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分05秒  1  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
     
    12时42分05秒 CPU  %usr  %nice  %sys %iowait  %irq  %soft %steal %guest %gnice  %idle
    12时42分06秒 all  0.00  0.00  0.00  0.50  0.00  0.00  0.00  0.00  0.00  99.50
    12时42分06秒  0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分06秒  1  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
     
    12时42分06秒 CPU  %usr  %nice  %sys %iowait  %irq  %soft %steal %guest %gnice  %idle
    12时42分07秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分07秒  0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分07秒  1  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
     
    12时42分07秒 CPU  %usr  %nice  %sys %iowait  %irq  %soft %steal %guest %gnice  %idle
    12时42分08秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分08秒  0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    12时42分08秒  1  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    

    字段分析

    • CPU: 每个CPU的process id
    • %usr:用户态下,cpu的利用率
    • %nice: 具有nice优先级的用户下,CPU的使用率
    • %sys: 显示在kernel内核态执行时发生的CPU利用率百分比。这不包括维护硬件和软件中断所花费的时间。
    • %iowait: 显示系统有未完成的磁盘I/O请求时,CPU或CPU处于空闲状态的时间百分比
    • %irq: 系统服务于硬中断的时间开销的百分比
    • %soft: 系统服务于软中断开销的时间开销百分比
    • %steal: 显示虚拟CPU或CPU在虚拟机监控程序为另一个虚拟处理器提供服务时被迫等待所花费的时间百分比
    • %guest:CPU处理虚拟进程的花费的时间开销
    • %idel: CPU空闲百分比

    每2秒产生了2个处理器的统计数据报告
    下面的命令可以每2秒产生了2个处理器的统计数据报告,一共产生三个interval 的信息,然后再给出这三个interval的平均信息。默认时,输出是按照CPU 号排序。第一个行给出了从系统引导以来的所有活跃数据。接下来每行对应一个处理器的活跃状态。

    [root@C44 ~]#  mpstat -P ALL 2 3
    Linux 2.6.14.7-selinux1-WR1.4aq_cgl (MSP)       05/14/20
    
    12:47:11     CPU   %user   %nice    %sys %iowait    %irq   %soft   %idle    intr/s
    12:47:13     all    1.51    0.00    0.76    0.00    0.00    0.25   97.48    296.50
    12:47:13       0    2.50    0.00    2.00    0.00    0.00    0.50   95.00    296.50
    12:47:13       1    1.00    0.00    0.00    0.00    0.00    0.50   98.00      0.00
    
    12:47:13     CPU   %user   %nice    %sys %iowait    %irq   %soft   %idle    intr/s
    12:47:15     all    0.50    0.00    0.25    0.00    0.00    0.00   99.24    295.45
    12:47:15       0    1.01    0.00    0.00    0.00    0.00    0.00   98.99    295.45
    12:47:15       1    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
    
    12:47:15     CPU   %user   %nice    %sys %iowait    %irq   %soft   %idle    intr/s
    12:47:17     all    0.51    0.00    0.76    0.25    0.00    0.25   98.23    299.49
    12:47:17       0    1.01    0.00    1.01    0.00    0.00    0.51   97.47    299.49
    12:47:17       1    0.00    0.00    1.01    0.00    0.00    0.00   99.49      0.00
    
    Average:     CPU   %user   %nice    %sys %iowait    %irq   %soft   %idle    intr/s
    Average:     all    0.84    0.00    0.59    0.08    0.00    0.17   98.32    297.15
    Average:       0    1.51    0.00    1.01    0.00    0.00    0.34   97.15    297.15
    :       1    0.34    0.00    0.34    0.00    0.00    0.17   99.16      0.00
    

    查看软中断统计信息

    mpstat -I SCPU 1
    Linux 3.10.0-693.el7.x86_64 (zhanghao)   2020年05月14日   _x86_64_  (2 CPU)
     
    15时23分07秒 CPU    HI/s  TIMER/s  NET_TX/s  NET_RX/s  BLOCK/s BLOCK_IOPOLL/s TASKLET/s  SCHED/s HRTIMER/s   RCU/s
    15时23分08秒  0    0.00    5.00    0.00    0.00    0.00    0.00    0.00    2.00    0.00    4.00
    15时23分08秒  1    0.00   28.00    0.00    5.00    0.00    0.00    0.00   24.00    0.00    3.00
    15时23分09秒  0    0.00    6.00    0.00    0.00    2.00    0.00    0.00    3.00    0.00    5.00
    15时23分09秒  1    0.00   26.00    0.00   70.00    0.00    0.00    0.00   24.00    0.00    2.00
    15时23分10秒  0    0.00   16.00    0.00    0.00    0.00    0.00    0.00   12.00    0.00    3.00
    15时23分10秒  1    0.00   13.00    0.00    6.00    0.00    0.00    0.00   13.00    0.00    1.00
    15时23分11秒  0    0.00   18.00    0.00    0.00    2.00    0.00    0.00   14.00    0.00    3.00
    15时23分11秒  1    0.00   12.00    0.00    5.00    0.00    0.00    0.00   10.00    0.00    1.00
    15时23分12秒  0    0.00    8.00    0.00    0.00    0.00    0.00    0.00    4.00    0.00    3.00
    15时23分12秒  1    0.00   30.00    0.00   40.00    0.00    0.00    0.00   19.00    0.00    4.00
    15时23分13秒  0    0.00    7.00    0.00    0.00    2.00    0.00    0.00    3.00    0.00    3.00
    15时23分13秒  1    0.00   23.00    0.00    7.00    0.00    0.00    0.00   22.00    0.00    1.00
    15时23分14秒  0    0.00   11.00    0.00    0.00    0.00    0.00    0.00    7.00    0.00    6.00
    15时23分14秒  1    0.00   30.00    0.00   12.00    1.00    0.00    0.00   25.00    0.00    8.00
    15时23分15秒  0    0.00    9.00    0.00    0.00    2.00    0.00    0.00    6.00    0.00    6.00
    15时23分15秒  1    0.00   31.00    0.00    7.00    0.00    0.00    0.00   24.00    0.00    5.00
    15时23分16秒  0    0.00    8.00    0.00    0.00    0.00    0.00    0.00    4.00    0.00    6.00
    15时23分16秒  1    0.00   25.00    0.00    6.00    0.00    0.00    0.00   22.00    0.00    3.00
    15时23分17秒  0    0.00   10.00    0.00    0.00    2.00    0.00    0.00    6.00    0.00    3.00
    15时23分17秒  1    0.00   24.00    0.00    7.00    0.00    0.00    0.00   23.00    0.00    1.00
    

    每隔2s输出一次,输出3次

    mpstat 2 3
    Linux 3.10.0-693.el7.x86_64 (zhanghao)   2020年05月14日   _x86_64_  (2 CPU)
     
    02时13分29秒 CPU  %usr  %nice  %sys %iowait  %irq  %soft %steal %guest %gnice  %idle
    02时13分31秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    02时13分33秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    02时13分35秒 all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    平均时间: all  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 100.00
    
    
    喜欢就点个赞吧
  • 相关阅读:
    POJ3114强连通+spfa
    POJ2431贪心(最少加油次数)
    POJ2431贪心(最少加油次数)
    POJ2391 Floyd+离散化+二分+DINIC
    POJ2391 Floyd+离散化+二分+DINIC
    POJ2195费用流+BFS建图
    POJ2195费用流+BFS建图
    POJ2060最小路径覆盖
    POJ2060最小路径覆盖
    POJ2044 深搜+剪枝(云彩下雨)
  • 原文地址:https://www.cnblogs.com/wangjingguan/p/12887222.html
Copyright © 2011-2022 走看看