8.perf top系统性能分析工具

perf 是一个调查 Linux 中各种性能问题的有力工具。
# perf --help
 usage: perf [--version] [--help] COMMAND [ARGS]
 The most commonly used perf commands are:
   annotate        Read perf.data (created by perf record) and display annotated code
   archive         Create archive with object files with build-ids found in perf.data file
   bench           General framework for benchmark suites
   buildid-cache   Manage build-id cache.
   buildid-list    List the buildids in a perf.data file
   diff            Read two perf.data files and display the differential profile
   evlist          List the event names in a perf.data file
   inject          Filter to augment the events stream with additional information
   kmem            Tool to trace/measure kernel memory(slab) properties
   kvm             Tool to trace/measure kvm guest os
   list            List all symbolic event types
   lock            Analyze lock events
   record          Run a command and record its profile into perf.data
   report          Read perf.data (created by perf record) and display the profile
   sched           Tool to trace/measure scheduler properties (latencies)
   script          Read perf.data (created by perf record) and display trace output
   stat            Run a command and gather performance counter statistics
   test            Runs sanity tests.
   timechart       Tool to visualize total system behavior during a workload
   top             System profiling tool.
   trace           strace inspired tool
   probe           Define new dynamic tracepoints
 See 'perf help COMMAND' for more information on a specific command.

perf 包含了:perf-stat (perf stat), perf-top (perf top), perf-record (perf record), perf-list (perf list)

perf list 主要是用于列出有哪些可用的event,可以供 perf top -e eventname 来分析。
perf top -e xxx
上面的 perf list [hw|sw...] 可以知道所有的 tracepoint events, 接下来我们就可以使用 perf top -e tracepoint-event 来专门获得指定的tracepoint的信息:

perf top常用选项有:
-e <event>:指明要分析的性能事件。
-p <pid>:Profile events on existing Process ID (comma sperated list). 仅分析目标进程及其创建的线程。
-k <path>:Path to vmlinux. Required for annotation functionality. 带符号表的内核映像所在的路径。
-K:不显示属于内核或模块的符号。
-U:不显示属于用户态程序的符号。
-d <n>:界面的刷新周期,默认为2s,因为perf top默认每2s从mmap的内存区域读取一次性能数据。
-g:得到函数的调用关系图。
 

# perf top -p `pidof mysqld`
Samples: 221  of event 'cycles', Event count (approx.): 10810377, UID: mysql
 10.34%  mysqld            [.] my_strnncollsp_utf8                                                                                           
  5.70%  [kernel]          [k] _spin_lock_irqsave                                                                                            
  5.66%  libc-2.12.so      [.] __memset_sse2                                                                                                 
  5.55%  [kernel]          [k] remove_wait_queue                                                                                             
  5.16%  libc-2.12.so      [.] __GI___strcmp_ssse3                                                                                           
  4.36%  [kernel]          [k] __audit_syscall_exit                                                                                          
  3.39%  [kernel]          [k] lookup_ioctx                                                                                                  
  3.28%  [kernel]          [k] find_next_bit                                                                                                 
  3.22%  mysqld            [.] lex_one_token(YYSTYPE*, THD*)                                                                                 
  2.69%  mysqld            [.] Item::val_bool()                                                                                              
  2.60%  [kernel]          [k] __do_softirq                                                                                                  
  2.53%  mysqld            [.] Protocol::send_result_set_row(List<Item>*)                                                                    
  2.52%  [kernel]          [k] local_bh_enable_ip                                                                                            
  2.51%  mysqld            [.] my_strnncoll_binary                                                                                           
  2.51%  libc-2.12.so      [.] memcpy  
第一列:符号引发的性能事件的比例,默认指占用的cpu周期比例。
第二列:符号所在的DSO(Dynamic Shared Object),可以是应用程序、内核、动态链接库、模块。
第三列:DSO的类型。[.]表示此符号属于用户态的ELF文件,包括可执行文件与动态链接库)。[k]表述此符号属于内核或模块。
第四列:符号名。有些符号不能解析为函数名,只能用地址表示。
 

转载于:https://www.cnblogs.com/allenhu320/p/11284173.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值