• perf使用


    参考:
        IBM    Perf -- Linux下的系统性能调优工具,第 1 部分   https://www.ibm.com/developerworks/cn/linux/l-cn-perf1/
    1. perf list
    – 查看当前软硬件环境支持的性能事件.
    – 性能事件与 CPU 及内核版本相关 
    1. Develop>perf list
    2. List of pre-defined events (to be used in -e):
    3. cpu-cycles OR cycles [Hardware event]
    4. instructions [Hardware event]
    5. cache-references [Hardware event]
    6. cache-misses [Hardware event]
    7. branch-instructions OR branches [Hardware event]
    8. branch-misses [Hardware event]
    9. bus-cycles [Hardware event]
    10. ref-cycles [Hardware event]
    11. cpu-clock [Software event]
    12. task-clock [Software event]
    13. page-faults OR faults [Software event]
    14. context-switches OR cs [Software event]
    15. cpu-migrations OR migrations [Software event]
    16. minor-faults [Software event]
    17. major-faults [Software event]
    18. alignment-faults [Software event]
    19. emulation-faults [Software event]
    20. dummy [Software event]
    21. L1-dcache-loads [Hardware cache event]
    22. L1-dcache-stores [Hardware cache event]
    23. L1-icache-loads [Hardware cache event]
    24. L1-icache-load-misses [Hardware cache event]
    25. LLC-loads [Hardware cache event]
    26. LLC-load-misses [Hardware cache event]
    27. LLC-stores [Hardware cache event]
    28. LLC-store-misses [Hardware cache event]
    29. dTLB-loads [Hardware cache event]
    30. dTLB-load-misses [Hardware cache event]
    31. dTLB-stores [Hardware cache event]
    32. dTLB-store-misses [Hardware cache event]
    33. iTLB-loads [Hardware cache event]
    34. iTLB-load-misses [Hardware cache event]
    35. branch-loads [Hardware cache event]
    36. branch-load-misses [Hardware cache event]
    37. branch-instructions OR cpu/branch-instructions/[Kernel PMU event]
    38. branch-misses OR cpu/branch-misses/[Kernel PMU event]
    39. bus-cycles OR cpu/bus-cycles/[Kernel PMU event]
    40. cache-misses OR cpu/cache-misses/[Kernel PMU event]
    41. cache-references OR cpu/cache-references/[Kernel PMU event]
    42. cpu-cycles OR cpu/cpu-cycles/[Kernel PMU event]
    43. instructions OR cpu/instructions/[Kernel PMU event]
    44. ref-cycles OR cpu/ref-cycles/[Kernel PMU event]
    45. rNNN [Raw hardware event descriptor]
    46. cpu/t1=v1[,t2=v2,t3 ...]/modifier [Raw hardware event descriptor]
    47. (see 'man perf-list' on how to encode it)
    48. mem:<addr>[:access][Hardware breakpoint]
    49. [Tracepoints not available:No such file or directory ]
     
    1. task-clock:目标任务真真占用处理器的时间,单位是毫秒,我们称之为任务执行时间,
    2. 后面是任务的处理器占用率(执行时间和持续时间的比值)
    3. 持续时间值从任务提交到任务结束的总时间(总时间在stat结束之后会打印出来)。
    4. context-switches:上下文切换次数,前半部分是切换次数,后面是平均每秒发生次数(M106次方)。
    5. cpu-migrations:处理器迁移,linux为了位置各个处理器的负载均衡,
    6. 会在特定的条件下将某个任务从一个处理器迁往另外一个处理器,此时便是发生了一次处理器迁移。
    7. page-fault:缺页异常,linux内存管理子系统采用了分页机制,
    8. 当应用程序请求的页面尚未建立、请求的页面不在内存中或者请求的页面虽在在内存中,
    9. 但是尚未建立物理地址和虚拟地址的映射关系是,会触发一次缺页异常。
    10. cycles:任务消耗的处理器周期数
    11. instructions:任务执行期间产生的处理器指令数,IPCinstructions perf cycle
    12. IPC是评价处理器与应用程序性能的重要指标。(很多指令需要多个处理周期才能执行完毕),
    13. IPC越大越好,说明程序充分利用了处理器的特征。
    14. branches:程序在执行期间遇到的分支指令数。
    15. branch-misses:预测错误的分支指令数
    16. cache-missescache时效的次数
    17. cache-referencescache的命中次数



    1. perf stat ./a.out
    分析程序的整体性能。
    ‘-e’: 指定性能事件
    ‘-p’: 指定待分析进程的 PID
    ‘-t’: 指定待分析线程的 TID 
    ‘-r N’: 连续分析 
    ‘-d’: 全面性能分析,采用更多的性能事件 
     
    1. Develop>perf stat -d -p 6371
    2. ^C
    3. Performance counter stats for process id '6371':
    4. 12179.626710 task-clock (msec)# 1.248 CPUs utilized [100.00%]
    5. 96673 context-switches # 0.008 M/sec [100.00%]
    6. 0 cpu-migrations # 0.000 K/sec [100.00%]
    7. 32 page-faults # 0.003 K/sec
    8. 20442151906 cycles # 1.678 GHz [29.64%]
    9. <not supported> stalled-cycles-frontend
    10. <not supported> stalled-cycles-backend
    11. 7297770919 instructions # 0.36 insns per cycle [44.12%]
    12. 1236856463 branches # 101.551 M/sec [43.73%]
    13. 61040864 branch-misses # 4.94% of all branches [42.98%] //分支预测失效数。
    14. 3268288054 L1-dcache-loads # 268.341 M/sec [27.91%]
    15. <not supported> L1-dcache-load-misses
    16. 105416823 LLC-loads # 8.655 M/sec [27.47%]
    17. 6321634 LLC-load-misses # 6.00% of all LL-cache hits [28.42%]
    18. 9.758418636 seconds time elapsed //表示采集的时间
     
    对于长驻的进程,可以按Ctrl+C,结束perf,会自动打印信息

    perf top 
    实时显示系统 进程的性能统计信息 
     
    ‘-e’: 指定性能事件 ( 默认事件: cycles)
    ‘-p’: 指定待分析进程的 PID
    ‘-t’: 指定待分析线程的 TID  
    ‘-a’: 分析整个系统的性能( Default 
    ‘-c’: 事件的采样周期
    ‘-d’: 界面的刷新周期( Default : 2s 
    ‘-E’: 显示的函数条数
    ‘-r <priority>’: 将 perf top 作为实时任务,优先级为<priority>
    – '-K': 不显示内核符号
    – '-U': 不显示用户符号 
     
    1. perf top -p 6371-K
    1. PerfTop:7027 irqs/sec kernel:30.8% exact:0.0%[4000Hz cycles],(target_pid:6371)
    2. -----------------------------------------------------------------------------------------------------------------------
    3. 34.03% server [.] dpdk::run_dp_thread(void*)
    4. 16.35% server [.] dpdk::capture::dp_process_cycle()
    5. 10.61% server [.] dpdk::Interface::send_burst()
    6. 9.45% server [.]CQdiscHtb::Dequeue()
    7. 4.34% server [.] update_cconfig_thread_readflag()
    8. 4.33% server [.] update_cconfig_thread_vsys_readflag(unsigned short)
    9. 4.02% server [.] _ZN4dpdk7capture10dp_processEv.clone.47
    10. 3.10% server [.] dpdk::Interface::recv_burst()
    11. 3.08%[vdso][.] __vdso_clock_gettime
    12. 2.65% server [.]CQdiscCtrl::Qos_Stream_Control(rte_mbuf*)
    13. 2.24% server [.] eth_em_recv_scattered_pkts
    14. 1.77% librt-2.15.so [.] clock_gettime
    15. 1.21% server [.] ipflow_new::flow_ha::dequeue()
    16. 0.88% server [.] DP_update_vsys_read_flag()
     

    perf record 
    记录一段时间内系统/进程的性能事件。
    1. –# perf record [options][<command>]
    2. –# perf record [options]--<command>[options]
    1. –‘-e’:指定性能事件(默认事件: cycles)
    2. –‘-p’:指定待分析进程的 PID
    3. –‘-t’:指定待分析线程的 TID
    4. –‘-a’:分析整个系统的性能(Default
    5. –‘-c’:事件的采样周期
    6. –‘-o’:指定输出文件(Default: perf.data
    7. –‘-g’:记录函数间的调用关系
    8. –‘-r <priority>’: perf top 作为实时任务,优先级为
    9. <priority>
    10. –‘-u <uid>’:只分析用户<uid>创建的进程
     
     
     
    默认在当前目录下生成数据文件:perf.data
     
    1. perf record -g -e cpu-clock ./a.out
    或者
    1. perf record -g -e cpu-clock -p 6371

    perf report 
    读取 perf record 生成的 perf.data 文件,并显示分析数据 .
    1. # perf report [-i <file> | --input=file]
    1. –‘-i’:输入文件名
    2. –‘-v’:显示每个符号的地址
    3. –‘-d <dso>’:只显示指定 dso 的符号
    4. ‘-n’:显示每个符号对应的事件数
    5. ‘-v’:显示每个符号的地址
    6. ‘--comms=<comm>’只显示指定 comm 的信息
    7. ‘-S <symbol name>’只考虑指定符号
    8. ‘-U只显示已解析的符号
    9. ‘-g [type,min]’按照[type,min]指定的方式显示函数调用图
    10. ‘-g [type,min]’ 按照 [type,min] 指定的方式显示函数
      调用图
      type : flat - 线性展开所有调用链
      graph – 显示调用树,并显示每个调用树对应
      的绝对开销率
      fractal – 显示调用树,并显示每个调用树对应
      的相对开销率
      min :只显示开销率大于 min 的符号 
     
    例如:
        
    1. perf report -g fractal -i perf.data
    1. # To display the perf.data header info, please use --header/--header-only options.
    2. #
    3. # Samples: 20K of event 'cpu-clock'
    4. # Event count (approx.): 5111500000
    5. #
    6. # Children Self Command Shared Object Symbol
    7. # ........ ........ ....... ................. ............................
    8. #
    9. 100.00%0.00% a.out libc-2.15.so [.] __libc_start_main
    10. |
    11. --- __libc_start_main
    12. 100.00%0.00% a.out a.out [.] main
    13. |
    14. --- main
    15. __libc_start_main
    16. 100.00%99.99% a.out a.out [.] test
    17. |
    18. --- test
    19. main
    20. __libc_start_main
    21. 0.00%0.00% a.out [unknown][.]0xec81485354415541
    22. |
    23. ---0xec81485354415541
    24. 0.00%0.00% a.out ld-2.15.so [.]0x0000000000014092
    25. |
    26. ---0x7fd281be9092
    27. 0xec81485354415541
    28. 0.00%0.00% a.out ld-2.15.so [.]0x000000000000325a
    29. |
    30. ---0x7fd281bd825a
    31. 0x7fd281be9092
    32. 0xec81485354415541
    33. 0.00%0.00% a.out [kernel.kallsyms][k]0x0000000000813c8a
    34. |
    35. ---0xffffffff82613c8a
    36. test
    37. main
    38. __libc_start_main
    39. 0.00%0.00% a.out ld-2.15.so [.]0x0000000000016897
    40. |
    41. ---0x7fd281beb897
    42. 0x7fd281bd825a
    43. 0x7fd281be9092
    44. 0xec81485354415541
    45. 0.00%0.00% a.out [kernel.kallsyms][k] smp_apic_timer_interrupt
    46. |
    47. --- smp_apic_timer_interrupt
    48. 0xffffffff82613c8a
    49. test
    50. main
    51. __libc_start_main
    52. 0.00%0.00% a.out [kernel.kallsyms][k]0x0000000000813152
     
    对应测试程序:
    1. #include<stdlib.h>
    2. int test(){
    3. unsignedint i=0;
    4. while(1)
    5. i++;
    6. }
    7. int main(){
    8. test();
    9. }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     





  • 相关阅读:
    使用ASP.Net WebAPI构建REST服务(一)——简单的示例
    SQL Server 自定义字符串分割函数
    [转]JSP中EL表达式三元运算符的使用
    [转]JSP页面的动态包含和静态包含示例及介绍
    jstl报错:Property 'name' not found on type java.lang.String
    [转]Extjs中的迭代方法
    eclipse mars 4.5.1 自定义工具栏
    [转]Commons IO 官方文档
    【转】eclipse运行 Ant报错Could not find the main class: org.eclipse.ant.internal.launching.remote.InternalAntRunner. Program
    【转】亲测plsql Developer配置免安装oralce客户端步骤
  • 原文地址:https://www.cnblogs.com/yml435/p/6914467.html
Copyright © 2020-2023  润新知