展开查看详情

1.Introducing Java Profiling via

Flame Graphs

Agustín Gallego

Support Engineer - Percona

2.Agenda

• What are Flame Graphs?

• What is the USE method?

• Setting up the environment

• Basic usage

• A case study

• There's even more to it! Advanced usage

!2

3.But First...

• Credit where credit is due!

• I'm basing on the work of Brendan Gregg, who has talked extensively on

this subject, and has a plethora of data on his website:

http://www.brendangregg.com/perf.html

http://www.brendangregg.com/perf.html#FlameGraphs

• Bear with me while I tangentially miss Java a bit...

!3

4.What Are Flame Graphs?

5.Introducing Flame Graphs

• Flame Graphs are a way to visualize data

• Provide an easy-to-understand interface for otherwise hard-to-read data

• They consume perf outputs (text)

• Generate outputs in .svg format (Scalable Vector Graphics)

• in technicolor!

• interactive

• supported by all modern browsers

!5

6.Introducing Flame Graphs

!6

7.Introducing Flame Graphs

• What can we say about the state of this server?

!7

8.Introducing Flame Graphs

• Since .svg files have many interactive features, let's switch to a web

browser window for a minute

!8

9.A Handy View of Resources

http://www.brendangregg.com/perf_events/perf_events_map.png

!9

10.What is the USE Method?

11.The USE method

• A systematic approach to performance analysis

• Why USE?

• Utilization

• Saturation

• Errors

• Why is it important?

• Flame Graphs are about context

• To have more data to base your collection and observations on

!11

12.A Quick Example

agustin@bm-support01 ~ $ vmstat 1 10

procs -----------memory-------------- ---swap-- -----io--- --system--- ------cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

5 0 21356 2722844 3344532 130780832 0 0 114 151 0 0 4 4 92 0 0

6 0 21356 2722532 3344532 130780992 0 0 0 584 31699 20073 1 22 78 0 0

5 0 21356 2722840 3344532 130780992 0 0 0 32 31417 20189 1 22 78 0 0

5 0 21356 2723148 3344532 130780992 0 0 0 200 31548 21719 1 22 78 0 0

5 0 21356 2723660 3344532 130780992 0 0 0 452 31272 20505 1 21 78 0 0

5 0 21356 2723904 3344532 130781040 0 0 0 661 31663 21971 1 22 77 0 0

5 0 21356 2706268 3344532 130780832 0 0 0 725 31492 21207 2 22 75 0 0

9 0 21356 2706428 3344532 130780840 0 0 0 96 31484 22362 2 22 76 0 0

7 0 21356 2714484 3344532 130780880 0 0 0 117 31349 22867 2 25 73 0 0

6 0 21356 2713240 3344532 130781696 0 0 0 60 31157 20429 2 25 74 0 0

!12

13.Setting up the Environment

14.Installing Packages

• Dependencies needed:

• perf_events (or just perf) - performance monitoring for Linux kernel

• yum install perf

• Flame Graphs project

• git clone https://github.com/brendangregg/FlameGraph.git

• perf support for Java JIT

• perf-map-agent

• and use -XX:+PreserveFramePointer JVM option (8u60+)

• symbols for any other code we want to profile

!14

15.Without perf-map-agent

• We will get the following message when trying to process perf record

output:

$ sudo perf script > perf.script.out

Failed to open /tmp/perf-38304.map, continuing without symbols

!15

16.Basic Usage

17.Basic Usage

• Record profile (use root / sudo):

perf record -F 99 -a -g -- sleep 10

• Make the recorded samples readable (use root / sudo):

perf script > perf.script.out

• Collapse stacks into a single line plus counters

stackcollapse-perf.pl perf.script.out > perf.folded.out

• Generate the svg Flame Graph file

flamegraph.pl perf.folded.out > perf.flamegraph.svg

!17

18.Basic Usage

• Let's go back to the Flame Graph

• explain the amount of samples it can actually aggregate

• why the different colors shown?

• why is it showing functions in alphabetical order (per level)?

• why is it not using time for X-axis?

• show how to search for functions (and see percentages for them)

• zoom in/out

!18

19.A Case Study

20.A Case Study

• We will do a short demo on a case study:

• (optional: initial approach via the USE method)

• capturing perf data

• generating Flame Graphs to help assess profiled data captured

• going back to the code to see how to improve it

!20

21.A Case Study

agustin@bm-support01 ps_5.7.25 $ time for i in {1..1000}; do \

{ ./use -e "SELECT 1;" test >/dev/null; } done

real 0m9.863s

user 0m4.603s

sys 0m5.163s

agustin@bm-support01 ps_5.7.25 $ time (for i in {1..1000}; do \

{ echo "SELECT 1;"; } done) | ./use test >/dev/null

real 0m0.074s

user 0m0.018s

sys 0m0.017s

!21

22.There's Even More to it! Advanced Usage

23.Advanced Usage

• Expanding our horizons:

• filtering by event type / subsystem

• perf record ... -e ''

• using coloring schemes for different applications

• --colors

• creating diffs between samples (differential flame graphs and color diffs)

• flamegraph.pl --cp sample1.folded.out >

perf.flamegraph.out

• flamegraph.pl --cp --colors blue sample2.folded.out

> perf.flamegraph.diff.out

!23

24.Advanced Usage

• Expanding our horizons:

• cleaning samples

• grep -v cpu_idle perf.folded.out

• sed -E 's/\+0x[0-9]+//g' < perf.folded.out >

perf.folded.nohexaddr.out

• icicle graphs (grouping top-down instead of bottom-up)

• --reverse --inverted

!24

25.Advanced Usage

• In more recent Linux versions, there is better support:

• 4.5 perf report has support for folding samples (more on it here)

• 4.8 stack frame limit extended

• 4.9 supports in-kernel aggregation, so it can be consumed directly by

the flamegraph.pl script

!25

26.Java Package Flame Graph

perf record -F 99 -a -- sleep 30; jmaps

perf script | pkgsplit-perf.pl | grep java > java_folded.out

flamegraph.pl java_folded.out > out.svg

• There is no need to collect stack traces (-g argument)

• No need to run Java with -XX:+PreserveFramePointer

• Useful to see how each individual package behaves

• Full flame graphs will contain times for the children, not only the function

itself, which may not be wanted/needed

!26

27.Thanks! Questions?

And just two more slides left...

28.Thank You to Our Sponsors

29.Rate My Session

!29

火焰课堂java_通过火焰图引入Java剖析相关推荐

  1. java 火焰_利用火焰图查找java耗时最长的方法

    原标题:利用火焰图查找java耗时最长的方法 众所周知java方法有两种,一种是纯粹的java方法,另外一种是jni,java调用c的,方法声明是java的,实现并不是. 现在通过jni实现一些效率的 ...

  2. 东华大学java_东华大学2020秋《Java程序设计》期末大作业

    东华大学继续教育学院 2020年秋季学期 远程学历教育<Java程序设计>期末大作业 一.选择题(本大题共10小题,每小题 1分, 共10分) 1.    下列哪个不是面向对象程序设计的基 ...

  3. 常见数据结构和算法实现(排序/查找/数组/链表/栈/队列/树/递归/海量数据处理/图/位图/Java版数据结构)

    常见数据结构和算法实现(排序/查找/数组/链表/栈/队列/树/递归/海量数据处理/图/位图/Java版数据结构) 数据结构和算法作为程序员的基本功,一定得稳扎稳打的学习,我们常见的框架底层就是各类数据 ...

  4. 火焰传感+蜂鸣器的火焰报警实验

    @火焰报警实验 火焰传感器,由各种燃烧生成物.中间物.高温气体.碳氢物质以及无机物质为主体的高温固体微粒构成的.火焰的热辐射具有离散光谱的气体辐射和连续光谱的固体辐射.不同燃烧物的火焰辐射强度.波长分 ...

  5. 将SVG 图引入到HTML页面

    将SVG图引入到HTML网页,目前只有三种办法,前两种很相似,第三种更简单. 下来介绍一下这是那种方法. 第一种: 使用<embed>标签: 这个是官方推荐的用法,但是这个官方是Adobe ...

  6. 一图胜千言,8 张图理解 Java

    一图胜千言,8 张图理解 Java 一图胜千言,下面图解均来自Program Creek 网站的Java教程,目前它们拥有最多的票选.如果图解没有阐明问题,那么你可以借助它的标题来一窥究竟. 1.字符 ...

  7. java思维导图源代码_如何使用思维导图解读java开源项目

    思维导图与java 思维导图是个很神奇的工具,它具有结构化.可视化.更接近人类大脑认知的特点. 我们在阅读项目的时候往往是无头无脑的随便看源码,其实这是种错误的学习的方法.学习得多注重积累,有输入就要 ...

  8. UML设计java程序_利用UML序列图设计Java应用程序详解

    [IT168 技术文章] Java应用程序由许多类所构成,是Java实现面向对象应用程序的核心.类图主要描述Java应用程序中各种类之间的相互静态关系,如类的继承.抽象.接口以及各种关联.要利用UML ...

  9. UML与Java-- UML类图于Java的基本实现

    类图是最常用的UML图,他可以清楚地表示程序中类的基本结构,类与类之间的结构关系,掌握UML类图对于了解系统的总体结构和设计模式有着重大的作用.下面我会介绍类图的基本知识以及类图在Java中的基本实现 ...

最新文章

  1. 面向对象概念及三大特点
  2. 07/11/08 资料整理
  3. zookeper安装_ZooKeeper安装和配置
  4. C语言已排序链表插入新节点保持排序状态(附完整源码)
  5. Maven入门详解与安装配置
  6. 警示2018:那些值得在年底彻查和回顾的数据库事件
  7. 卡巴斯基亚太区总经理:不做免费杀毒厂商
  8. uploadify动态改变参数
  9. 2020中国数字化转型优秀案例征集
  10. 关于内存的最后一个难点--the paged and the non-paged pool
  11. zoj[3868]gcd期望
  12. Java JDK中文帮助文档免费下载,百度网盘下载。
  13. Xcode 9有什么新功能?
  14. ★C语言期末课程设计★——教师工资管理系统(详细报告+源代码+详细注释)
  15. js获取浏览器的高度
  16. 用EXCEL分析房价
  17. 音频怎么转换成mp3格式
  18. ASP程序性能测试报告
  19. C语言 分解质因数。例如:输入90,打印出90=2*3*3*5。
  20. macOS Command - softwareupdate

热门文章

  1. 重庆专科计算机大学排名,重庆2017年专科大学排名一览表
  2. TikTok引领全球娱乐潮流,成为游戏出海营销新据点
  3. 电流检测电路公式推导
  4. 区块数据存储文件说明
  5. 太强了!Java毕业设计分享—基于Java开发的毕业设计实战项目(含源码+论文)
  6. C++第三次实验:税收计算
  7. 计算机中央处理单元是哪些,1.1.1-1.1.2 计算机系统硬件基本组成 - 中央处理单元...
  8. Java识别获取pdf中文字信息(此方法任意pdf的信息都可以拿到)
  9. 成功时间管理软件推荐-DesktopCal和GTD
  10. 易經大意(10) 三和 韓長庚 著