Linux perf 命令示例

安装perf

 yum install perf -y

命令示例

查看所有进程的压力perf top

Samples: 2K of event 'cycles', Event count (approx.): 1113901234                                                                                                                             
Overhead  Shared Object         Symbol                                                                                                                                                       
   4.73%  perf                  [.] rb_next
   3.15%  perf                  [.] __symbols__insert
   1.96%  [kernel]              [k] module_get_kallsym
   1.58%  [kernel]              [k] kallsyms_expand_symbol.constprop.1
   1.55%  prometheus2           [.] github.com/prometheus/tsdb/chunkenc.(*bstream).readByte
   1.34%  prometheus2           [.] github.com/prometheus/tsdb/chunkenc.(*xorIterator).readValue

查看所有进程的压力,从大到小排列:perf top --sort comm,dso

Samples: 271K of event 'cycles', Event count (approx.): 110876431070                                                                                                                         
Overhead  Command          Shared Object                                                                                                                                                     
  27.59%  mysqld           mysqld
  10.24%  CPU 0/KVM        [kernel]
   8.52%  swapper          [kernel]
   8.08%  java             perf-47037.map
   7.23%  prometheus2      prometheus2
   6.12%  CPU 3/KVM        [kernel]
   6.04%  CPU 2/KVM        [kernel]
   5.56%  zsn-agent        [kernel]
   3.68%  vhost-8837       [kernel]
   2.54%  mysqld           [kernel]
   2.14%  vhost-2561       [kernel]
   1.22%  CPU 1/KVM        [kernel]
   1.19%  java             [kernel]
   1.09%  mysqld           libc-2.17.so
   0.86%  perf             perf
   0.86%  collectd_export  collectd_exporter
   0.83%  zsn-agent        zsn-agent (deleted)
   0.68%  CPU 2/KVM        libpthread-2.17.so
   0.66%  CPU 3/KVM        libpthread-2.17.so

先用top 命令查看系统压力:

[root@dell-emc36-172-24-0-103 ~]# top
top - 20:44:03 up 23 days,  4:39,  5 users,  load average: 14.84, 18.75, 20.44
Tasks: 853 total,   1 running, 476 sleeping,   0 stopped,   0 zombie
%Cpu(s):  9.1 us,  8.0 sy,  0.0 ni, 81.6 id,  1.2 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem : 79105868+total, 17245459+free, 15466398+used, 46394016+buff/cache
KiB Swap:        0 total,        0 free,        0 used. 62571686+avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                 
 8837 root      20   0 5103944 1.296g  22460 S 224.8  0.2  60590:41 qemu-kvm                                                                                                                
48935 root      20   0 7919108 5.926g  22996 S 160.3  0.8  59:08.75 qemu-kvm                                                                                                                
51265 root      20   0 7916908 5.597g  23004 S 137.7  0.7  70:10.98 qemu-kvm                                                                                                                
12640 root      20   0 8115684 6.458g  23344 S 124.5  0.9 158:11.78 qemu-kvm                                                                                                                
63927 root      20   0 2696888 2.026g   8924 S 100.3  0.3 418:13.65 zsn-agent                                                                                                               
45249 root      20   0  128216  69148  10120 S  88.1  0.0  56:17.21 node_exporter                                                                                                           
61557 root      20   0 13.812g 8.934g  41208 S  45.7  1.2 583:17.91 prometheus2                                                                                                             
43633 root      20   0 7927984 6.453g  23032 S  29.1  0.9  62:29.10 qemu-kvm                                                                                                                
47412 root      20   0 9431284 7.942g  23120 S  22.5  1.1  10:16.63 qemu-kvm                                                                                                                
65068 mysql     20   0 23.114g 2.922g  15484 S  19.5  0.4   2731:38 mysqld                                                                                                                  
45058 root      20   0   47992  34268   7000 S  13.9  0.0  26:23.77 collectd_export                                                                                                         
42307 root      20   0 9423412 7.942g  23132 S  13.6  1.1   9:45.67 qemu-kvm                                                                                                                
37193 root      20   0 13.054g 9.231g  23096 S  10.6  1.2  17:57.15 qemu-kvm                                                                                                                
52104 root      20   0 13.111g 1.215g  22988 S   9.3  0.2   0:40.13 qemu-kvm                                                                                                                
 8846 root      20   0       0      0      0 S   7.6  0.0   4530:38 vhost-8837                                                                                                              
44072 root      20   0 2149980  48512  21236 S   7.6  0.0  12:33.94 libvirtd               

查看某个进程的信息:perf top -p 2742

Samples: 2K of event 'cycles', Event count (approx.): 284064238                                                                                                                              
Overhead  Shared O  Symbol                                                                                                                                                                   
  12.93%  [kernel]  [k] ipt_do_table
   7.67%  [kernel]  [k] copy_user_enhanced_fast_string
   5.03%  [kernel]  [k] ebt_do_table
   3.81%  [kernel]  [k] vhost_get_vq_desc
   3.19%  [kernel]  [k] update_load_avg
   1.84%  [kernel]  [k] update_curr
   1.78%  [kernel]  [k] vhost_worker
   1.75%  [kernel]  [k] copy_user_generic_unrolled
   1.53%  [kernel]  [k] vhost_notify.isra.39
   1.53%  [kernel]  [k] _raw_read_lock_bh
   1.35%  [kernel]  [k] copy_page_to_iter

你可能感兴趣的:(Linux perf 命令示例)