美文网首页
性能问题排查常用命令记录

性能问题排查常用命令记录

作者: 鸟它鸟 | 来源:发表于2018-12-17 17:23 被阅读0次

pidstat

输出CPU指标信息
通过此命令可以看到所有进程的CPU使用状态信息,可以迅速的帮助我们抓到可疑程序

[root@localhost ~]# pidstat -u 5 1
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年12月12日     _x86_64_    (4 CPU)

23时42分47秒   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
23时42分52秒     0        60    0.00    0.20    0.00    0.00    0.20     0  kworker/0:2
23时42分52秒     0     27809    0.00    0.20    0.00    0.00    0.20     0  pidstat

平均时间:   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
平均时间:     0        60    0.00    0.20    0.00    0.00    0.20     -  kworker/0:2
平均时间:     0     27809    0.00    0.20    0.00    0.00    0.20     -  pidstat

查看所有进程的上下文切换信息

  • cswch 自愿上下文切换
  • nvcswch 非自愿上下文切换
[root@localhost ~]# 
[root@localhost ~]# pidstat  -w 5 1
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年12月12日     _x86_64_    (4 CPU)

23时50分33秒   UID       PID   cswch/s nvcswch/s  Command
23时50分38秒     0         7      0.20      0.00  migration/0
23时50分38秒     0         9      4.19      0.00  rcu_sched
23时50分38秒     0        11      0.20      0.00  watchdog/0
23时50分38秒     0        12      0.20      0.00  watchdog/1
23时50分38秒     0        13      0.20      0.00  migration/1
23时50分38秒     0        14      0.20      0.00  ksoftirqd/1
23时50分38秒     0        17      0.20      0.00  watchdog/2
23时50分38秒     0        19      0.20      0.00  ksoftirqd/2
23时50分38秒     0        22      0.20      0.00  watchdog/3
23时50分38秒     0        23      0.60      0.00  migration/3
23时50分38秒     0        45      0.20      0.00  khugepaged
23时50分38秒     0        60      1.00      0.00  kworker/0:2
23时50分38秒     0       329      0.40      0.00  kworker/1:2
23时50分38秒     0       425      0.20      0.00  kworker/0:1H
23时50分38秒     0       736      0.60      0.00  rngd
23时50分38秒     0       745     10.78      0.00  vmtoolsd
23时50分38秒     0       805      0.80      0.00  ksmtuned
23时50分38秒     0       884      0.20      0.00  kworker/3:1H
23时50分38秒     0      1970      0.40      0.00  kworker/2:2
23时50分38秒     0     15109      1.00      0.00  kworker/u256:0
23时50分38秒     0     27261      2.59      0.00  kworker/3:2
23时50分38秒     0     27843      0.60      0.00  kworker/3:1
23时50分38秒     0     27871      0.20      0.00  pidstat
23时50分38秒     0     27879      0.20      0.20  sleep

平均时间:   UID       PID   cswch/s nvcswch/s  Command
平均时间:     0         7      0.20      0.00  migration/0
平均时间:     0         9      4.19      0.00  rcu_sched
平均时间:     0        11      0.20      0.00  watchdog/0
平均时间:     0        12      0.20      0.00  watchdog/1
平均时间:     0        13      0.20      0.00  migration/1
平均时间:     0        14      0.20      0.00  ksoftirqd/1
平均时间:     0        17      0.20      0.00  watchdog/2
平均时间:     0        19      0.20      0.00  ksoftirqd/2
平均时间:     0        22      0.20      0.00  watchdog/3
平均时间:     0        23      0.60      0.00  migration/3
平均时间:     0        45      0.20      0.00  khugepaged
平均时间:     0        60      1.00      0.00  kworker/0:2
平均时间:     0       329      0.40      0.00  kworker/1:2
平均时间:     0       425      0.20      0.00  kworker/0:1H
平均时间:     0       736      0.60      0.00  rngd
平均时间:     0       745     10.78      0.00  vmtoolsd
平均时间:     0       805      0.80      0.00  ksmtuned
平均时间:     0       884      0.20      0.00  kworker/3:1H
平均时间:     0      1970      0.40      0.00  kworker/2:2
平均时间:     0     15109      1.00      0.00  kworker/u256:0
平均时间:     0     27261      2.59      0.00  kworker/3:2
平均时间:     0     27843      0.60      0.00  kworker/3:1
平均时间:     0     27871      0.20      0.00  pidstat
平均时间:     0     27879      0.20      0.20  sleep

同时输出CPU和进程上下文切换情况

[root@localhost ~]# pidstat -w -u 1 1
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年12月12日     _x86_64_    (4 CPU)

23时54分19秒   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command

23时54分19秒   UID       PID   cswch/s nvcswch/s  Command
23时54分20秒     0         3      0.99      0.00  ksoftirqd/0
23时54分20秒     0         9      4.95      0.00  rcu_sched
23时54分20秒     0        60      1.98      0.00  kworker/0:2
23时54分20秒     0       329      0.99      0.00  kworker/1:2
23时54分20秒    70       734      0.99      0.00  avahi-daemon
23时54分20秒     0       745      9.90      0.00  vmtoolsd
23时54分20秒     0     15109      0.99      0.00  kworker/u256:0
23时54分20秒     0     25725      0.99      0.00  sshd
23时54分20秒     0     27261      0.99      0.00  kworker/3:2
23时54分20秒     0     27906      0.99      0.00  pidstat

平均时间:   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command

平均时间:   UID       PID   cswch/s nvcswch/s  Command
平均时间:     0         3      0.99      0.00  ksoftirqd/0
平均时间:     0         9      4.95      0.00  rcu_sched
平均时间:     0        60      1.98      0.00  kworker/0:2
平均时间:     0       329      0.99      0.00  kworker/1:2
平均时间:    70       734      0.99      0.00  avahi-daemon
平均时间:     0       745      9.90      0.00  vmtoolsd
平均时间:     0     15109      0.99      0.00  kworker/u256:0
平均时间:     0     25725      0.99      0.00  sshd
平均时间:     0     27261      0.99      0.00  kworker/3:2
平均时间:     0     27906      0.99      0.00  pidstat

查看带线程的上下文切换

[root@localhost ~]# pidstat -wt 1 1
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年12月12日     _x86_64_    (4 CPU)

23时55分23秒   UID      TGID       TID   cswch/s nvcswch/s  Command
23时55分24秒     0         9         -     12.75      0.00  rcu_sched
23时55分24秒     0         -         9     12.75      0.00  |__rcu_sched
23时55分24秒     0        14         -      1.96      0.00  ksoftirqd/1
23时55分24秒     0         -        14      1.96      0.00  |__ksoftirqd/1
23时55分24秒     0        60         -      0.98      0.00  kworker/0:2
23时55分24秒     0         -        60      0.98      0.00  |__kworker/0:2
23时55分24秒     0       329         -      0.98      0.00  kworker/1:2
23时55分24秒     0         -       329      0.98      0.00  |__kworker/1:2
23时55分24秒     0       745         -     10.78      0.00  vmtoolsd
23时55分24秒     0         -       745     10.78      0.00  |__vmtoolsd
23时55分24秒     0         -      1559      0.98      0.00  |__tuned
23时55分24秒     0         -      1092      0.98      0.00  |__in:imjournal
23时55分24秒     0      1970         -      0.98      0.00  kworker/2:2
23时55分24秒     0         -      1970      0.98      0.00  |__kworker/2:2
23时55分24秒     0     15109         -      0.98      0.00  kworker/u256:0
23时55分24秒     0         -     15109      0.98      0.00  |__kworker/u256:0
23时55分24秒     0     27261         -      3.92      0.00  kworker/3:2
23时55分24秒     0         -     27261      3.92      0.00  |__kworker/3:2
23时55分24秒     0     27888         -      0.98      0.00  kworker/3:0
23时55分24秒     0         -     27888      0.98      0.00  |__kworker/3:0
23时55分24秒     0     27915         -      0.98      0.98  pidstat
23时55分24秒     0         -     27915      0.98      0.98  |__pidstat

平均时间:   UID      TGID       TID   cswch/s nvcswch/s  Command
平均时间:     0         9         -     12.75      0.00  rcu_sched
平均时间:     0         -         9     12.75      0.00  |__rcu_sched
平均时间:     0        14         -      1.96      0.00  ksoftirqd/1
平均时间:     0         -        14      1.96      0.00  |__ksoftirqd/1
平均时间:     0        60         -      0.98      0.00  kworker/0:2
平均时间:     0         -        60      0.98      0.00  |__kworker/0:2
平均时间:     0       329         -      0.98      0.00  kworker/1:2
平均时间:     0         -       329      0.98      0.00  |__kworker/1:2
平均时间:     0       745         -     10.78      0.00  vmtoolsd
平均时间:     0         -       745     10.78      0.00  |__vmtoolsd
平均时间:     0         -      1559      0.98      0.00  |__tuned
平均时间:     0         -      1092      0.98      0.00  |__in:imjournal
平均时间:     0      1970         -      0.98      0.00  kworker/2:2
平均时间:     0         -      1970      0.98      0.00  |__kworker/2:2
平均时间:     0     15109         -      0.98      0.00  kworker/u256:0
平均时间:     0         -     15109      0.98      0.00  |__kworker/u256:0
平均时间:     0     27261         -      3.92      0.00  kworker/3:2
平均时间:     0         -     27261      3.92      0.00  |__kworker/3:2
平均时间:     0     27888         -      0.98      0.00  kworker/3:0
平均时间:     0         -     27888      0.98      0.00  |__kworker/3:0
平均时间:     0     27915         -      0.98      0.98  pidstat
平均时间:     0         -     27915      0.98      0.98  |__pidstat

查看某个进程的io信息
-d 展示I/O统计信息,-p指定进程id

[root@localhost ~]# pidstat -d -p 17 1 3
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年12月14日     _x86_64_    (4 CPU)

00时21分46秒   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
00时21分47秒     0        17      0.00      0.00      0.00  watchdog/2
00时21分48秒     0        17      0.00      0.00      0.00  watchdog/2
00时21分49秒     0        17      0.00      0.00      0.00  watchdog/2
平均时间:     0        17      0.00      0.00      0.00  watchdog/2

vmstat

可查看系统内存的使用情况,也可以看出cpu的上下文切换及中断次数

  • cs 是每秒上下文切换的次数
  • in 是每秒钟中断的次数
  • r 就绪队列的长度,也就是正在等待CPU的进程数
  • b 处于不可中断随眠状态的进程数
  • bi 块设备读取大小,linux的块大小为1kb,这里可以理解为多少kb/s
  • bo 块设备写入大小,linux的块大小为1kb,这里可以理解为多少kb/s
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 2755624   2116 904344    0    0     1     1   16   14  0  0 100  0  0

perf

可抓取一段时间内的性能信息,用于分析.
当出现大量程序exec类型的应用时,top类型的命令,不一定能捕获到这些细小的数据,怎么办呢?用perf捕获一段时间的数据进行分析
捕获数据

[root@localhost ~]# perf record
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.743 MB perf.data (11175 samples) ]
[root@localhost ~]# ls perf.data 
perf.data

回放数据

[root@localhost ~]# perf report

Samples: 11K of event 'cpu-clock', Event count (approx.): 2793750000            
Overhead  Command       Shared Object      Symbol                               
  99.89%  swapper       [kernel.kallsyms]  [k] native_safe_halt
   0.05%  kworker/0:1   [kernel.kallsyms]  [k] vmw_cmdbuf_header_submit
   0.03%  kworker/3:2   [kernel.kallsyms]  [k] _raw_spin_unlock_irqrestore
   0.01%  in:imjournal  [kernel.kallsyms]  [k] read_tsc
   0.01%  kworker/2:3   [kernel.kallsyms]  [k] _raw_spin_unlock_irqrestore
   0.01%  swapper       [kernel.kallsyms]  [k] _raw_spin_unlock_irqrestore

实时分析数据

[root@localhost ~]# perf top -g -p <进程id>

相关文章

网友评论

      本文标题:性能问题排查常用命令记录

      本文链接:https://www.haomeiwen.com/subject/lammhqtx.html