目录

perf stat 对全局性能进程统计

perf top 显示最多的函数或指令

perf record 精确到函数

火焰图FlameGraph


perf是Linux性能分析工具

perf工具学习链接

perf stat 对全局性能进程统计

(base) root@ubuntu:/home/wy# perf stat ls
anaconda3  Desktop  Documents  Downloads  examples.desktop  misc  Music  network  Pictures  process  Public  PycharmProjects  qt_code  snap  Templates  video1.avi  Videos  visual-studio-code  vm_testPerformance counter stats for 'ls':0.68 msec task-clock                #    0.142 CPUs utilized          1      context-switches          #    0.001 M/sec                  0      cpu-migrations            #    0.000 K/sec                  97      page-faults               #    0.143 M/sec                  <not supported>      cycles                                                      <not supported>      instructions                                                <not supported>      branches                                                    <not supported>      branch-misses                                               0.004774876 seconds time elapsed0.000957000 seconds user0.000000000 seconds sys
  • task-clock:任务占用的CPU时间
  • context-switches:上下文切换次数
  • cpu-migrations:CPU迁移次数
  • page-faults:缺页异常的次数
  • cycles:消耗CPU周期数
  • instructions:执行指令数
  • branches:遇到的分支指令数量
  • branches-misses:预测错误的分支指令数

perf top 显示最多的函数或指令

perf top主要用于实时分析每个函数在某个性能事件上的热度,能够快速定位函数(应用程序函数、模块函数、内核函数)

  • 第一列:符号引发的性能事件的比例,默认情况占用CPU周期比例
  • 第二列:符号引发的BSO,可以是内核,动态链接库、模块、应用程序;
  • 第三列:BSO的类型,(. 符号属于用户态的ELF文件,k符号属于内核或模块)
  • 第四列:有些符号不能解析为函数名,只用地址表示

perf record 精确到函数

perf record -a -g ./test2

选项

  • -a 获取所有CPU事件
  • -p 获取指定PID进程事件
  • -o 指定获取保存数据的文件名称
  • -g 函数调用功能图
sudo perf report -i perf.data > perf.txt

函数调用情况,CPU大部分花在 test2  for_loop函数上

# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 52K of event 'cpu-clock:pppH'
# Event count (approx.): 13062750000
#
# Children      Self  Command  Shared Object      Symbol
# ........  ........  .......  .................  ..............................................
#100.00%     1.70%  test2    test2              [.] for_loop|          |--98.30%--for_loop|          |          |          |--50.78%--__cos_fma|          |          |          |          |          |--41.69%--do_sincos_1 (inlined)|          |          |          |          |          |          |          |--13.04%--do_cos (inlined)|          |          |          |          |          |          |          |--11.27%--do_sin (inlined)|          |          |          |          |          |          |          |--4.19%--__copysign (inlined)|          |          |          |          |          |          |          |--1.13%--sloww1 (inlined)|          |          |          |          |          |          |          |          |           --0.83%--do_sin_slow (inlined)|          |          |          |          |          |          |           --0.76%--sloww2 (inlined)|          |          |          |          |          |--2.28%--libc_feholdsetround_sse_ctx (inlined)|          |          |          |          |           --1.24%--reduce_sincos_1 (inlined)|          |          |          |--46.72%--__sin_fma|          |          |          |          |          |--36.81%--do_sincos_1 (inlined)|          |          |          |          |          |          |          |--12.48%--do_cos (inlined)|          |          |          |          |          |          |          |--11.13%--do_sin (inlined)|          |          |          |          |          |          |          |--3.17%--__copysign (inlined)|          |          |          |          |          |          |           --0.55%--sloww1 (inlined)|          |          |          |          |          |--2.00%--reduce_sincos_1 (inlined)|          |          |          |          |           --1.59%--libc_feholdsetround_sse_ctx (inlined)|          |          |           --0.56%--sin@plt|          --1.70%--_start__libc_start_mainmain|          --1.41%--loop_bigfor_loop

火焰图FlameGraph

用于展示 CPU 的调用栈

需要下载FlameGraph, 并需要perf.data文件

#生成折叠后的调用栈
perf script -i perf.data &> perf.unfold#生成火焰图
./FlameGraph/stackcollapse-perf.pl perf.unfold &> perf.folded#生成SVG图
./FlameGraph/flamegraph.pl  perf.folded >perf.svg

纵向表示调用栈的深度,横向表示消耗的时间. 一个格子的越大越说明其可能是瓶颈,颜色则没有含义。


Linux perf Examples

linux性能优化perf相关推荐

  1. linux性能优化--cpu篇

    linux性能优化--cpu篇 前言 负载 CPU使用率 proc perf 一些链接 `perf list` 比较有用的event `perf stat` `perf record` Profili ...

  2. Linux 性能优化全景指南

    大家好 我是坤哥 之前一些朋友觉得奇怪,说你主要做 Java 的,公号怎么时不时地也推送一些 Linux 文章,其实不管你是哪个 xx 语言的工程师,要想进阶,Linux 性能优化是必备知识,举个例子 ...

  3. Linux 性能优化的全景指南,都在这一篇里了,建议收藏~

    Linux 性能优化 性能优化 性能指标 高并发和响应快对应着性能优化的两个核心指标:吞吐和延时 应用负载角度:直接影响了产品终端的用户体验 系统资源角度:资源使用率.饱和度等 性能问题的本质就是系统 ...

  4. Linux性能优化实战学习笔记:第十讲==中断

    Linux性能优化实战学习笔记:第十讲 一.坏境准备 1.拓扑图 2.安装包 在第9节的基础上 在VM2上安装hping3依奈包 ? 1 2 3 4 5 6 7 wget http://www.tcp ...

  5. Linux 性能优化实战(倪朋飞)---CPU 使用率

    查看 CPU 使用率 对于 CPU 使用率,top 默认 3 秒时间间隔:ps 使用的是进程的整个生命周期. top 显示系统总体的 CPU 和内存使用情况,及各个进程的资源使用情况:ps 只显示每隔 ...

  6. Linux 性能优化实战(倪朋飞)---系统中出现大量不可中断进程和僵尸进程怎么办?

    进程状态 可通过 top 或 ps 查看进程状态. $ topPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4480 yjp 20 0 6 ...

  7. 学习Linux性能优化实战-1

    文章目录 前言 平均负载 命令 进程调度 命令 相关文件 CPU使用率 perf 软中断 测试工具 前言 最近在极客时间上面发现了倪鹏飞老师的Linux性能优化实战,自己感觉讲得很好,有兴趣的朋友可以 ...

  8. linux的相关优化技术,Linux性能优化及跟踪.md

    # Linux性能优化及跟踪 # 说明: * 图例.术语及内容很多来源于互联网,尤其是[Brendan Gredd' Blog](http://www.brendangregg.com/).[leez ...

  9. 【Linux 性能优化系列】Linux 性能优化 -- CPU 性能篇(一) 平均负载、上下文切换、CPU 使用率

    [Linux 性能优化系列]Linux 性能优化 -- CPU 性能篇(一) 平均负载.上下文切换.CPU 使用率 [1]相关概念 [1.1]平均负载 平均负载是指单位时间内,系统处于可运行状态和不可 ...

最新文章

  1. 重磅发布!Google语义分割新数据集来啦!又一个分割SOTA模型
  2. python 多进程管道 消息式通信
  3. 论文笔记:[ICLR 2020] Tips for prospective and early-stage PhD students
  4. 02.Teams组成概述及使用分享
  5. Windows系统下查看某一进程下所有线程的dos命令
  6. python的父类和子类的继承关系和super()的使用
  7. Halcon学习路线——Blob分析(1)
  8. TatukGIS - GisDefs - CanonicalSQLName 函数
  9. 使用Luyten工具反编译jar包
  10. cp: cannot create regular file ‘/root/queues.conf’: No space left on devic
  11. div网页布局(做一个简单网页界面为例)
  12. 瑞吉外卖项目学习笔记01
  13. 自学c语言困难吗,你觉得这4块是C语言最难学的部分吗?
  14. 2017_SIGIR_Item Silk Road: Recommending Items from Information Domains to Social Users
  15. 导师一般会帮自己的博士生推荐工作吗?
  16. C语言入门(九)>>>循环 - while循环
  17. 实现一边录音一边转化为文字的功能
  18. 软件工程实践——结对作业一
  19. 优酷路由宝YK-L1刷小米路由固件
  20. 《动手学深度学习》(四) -- LeNet、AlexNet、VGG、NiN、GoogLeNet、ResNet、DenseNet 实现

热门文章

  1. 铁血联盟2源码学习笔记--Makefile边看边学3
  2. 基于bootstrap的富文本框——wangEditor【欢迎加入开发】
  3. streamlit使用altair画图并保存png图片
  4. MaxCompute表操作
  5. 100道经典算法题(76-100)
  6. 2004·网络安全圈
  7. Java多种方式解决生产者消费者问题(十分详细)
  8. 白帽子讲Web安全(第 7 章 注入攻击)
  9. NOI / 1.1编程基础之输入输出 10:超级玛丽游戏
  10. 资源提取码没给我?教你下载忘给密码的网盘资源