如何使用linux perf工具生成"Off-CPU"?轮廓 [英] How to use linux `perf` tool to generate "Off-CPU" profile

查看:697
本文介绍了如何使用linux perf工具生成"Off-CPU"?轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Brendan D. Gregg(DTrace书的作者)有一个有趣的概要分析变体:"Off-CPU"配置文件(和非CPU火焰图;

Brendan D. Gregg (author of DTrace book) has interesting variant of profiling: the "Off-CPU" profiling (and Off-CPU Flame Graph; slides 2013, p112-137) to see, where the thread or application were blocked (was not executed by CPU, but waiting for I/O, pagefault handler, or descheduled due short of CPU resources):

这一次显示出在CPU以外时哪些代码路径被阻塞并等待,以及确切的时间长度.这与传统的分析不同,传统的分析通常在给定的时间间隔内对线程的活动进行采样,并且(通常)仅在线程正在CPU上执行工作时才对其进行检查.

This time reveals which code-paths are blocked and waiting while off-CPU, and for how long exactly. This differs from traditional profiling which often samples the activity of threads at a given interval, and (usually) only examine threads if they are executing work on-CPU.

他还可以将CPU外配置文件数据和CPU上配置文件组合在一起: http://www.brendangregg.com/FlameGraphs/hotcoldflamegraphs.html

He also can combine Off-CPU profile data and On-CPU profile together: http://www.brendangregg.com/FlameGraphs/hotcoldflamegraphs.html

Gregg给出的示例是使用dtrace制作的,在Linux OS中通常不可用.但是有一些类似的工具(ktap,systemtap,perf)和perf,因为我认为安装范围最广.通常perf生成CPU上的配置文件(这些功能在CPU上执行得更多).

The examples given by Gregg are made using dtrace, which is not usually available in Linux OS. But there are some similar tools (ktap, systemtap, perf) and the perf as I think has widest installed base. Usually perf generated On-CPU profiles (which functions were executed more often on CPU).

  • 如何将Gregg的Off-CPU示例转换为Linux中的perf分析工具?
  • How can I translate Gregg's Off-CPU examples to perf profiling tool in Linux?

PS:在来自LISA13的幻灯片中,有指向非CPU火焰图的systemtap变体的链接. ,p124 :" Yichun Zhang创建了这些文件,并一直在Linux和SystemTap上使用它们来收集配置文件数据.请参阅:•(CloudFlare 2013年8月23日的啤酒会议)

PS: There is link to systemtap variant of Off-CPU flamegraphs in the slides from LISA13, p124: "Yichun Zhang created these, and has been using them on Linux with SystemTap to collect the profile data. See: • http://agentzh.org/misc/slides/off-cpu-flame-graphs.pdf"" (CloudFlare Beer Meeting on 23 August 2013)

推荐答案

我发布的perf技术[1]是一种高开销的解决方法,直到perf对此具有BPF支持为止.

The perf technique I published[1] was a high-overhead workaround, until perf has BPF support for doing this.

目前,在Linux上生成CPU外火焰图的成本最低的方法是在4.6+内核(具有BPF堆栈跟踪支持)以及bcc/BPF上.我为此编写了一个工具offcputime [2],可以使用-f选项来运行折叠输出",适合将其输入flamegraph.pl.这个offcputime工具对内核内容中的所有内容进行计时和堆栈计数,并转储报告,然后用符号打印.

Right now, the lowest cost way of generating an off-CPU flame graph on Linux is on a 4.6+ kernel (which has BPF stack trace support), and with bcc/BPF. I wrote a tool for it, offcputime[2], which can be run with a -f option for "folded output", suitable for feeding into flamegraph.pl. This offcputime tool does the timing and stack counting all in kernel content, and dumps a report that is then printed with symbols.

有一天,我希望perf本身也能够做到这一点:运行一个BPF程序,该程序执行内核内计数和报告转储.

One day, I expect that perf itself will be able to do this as well: run a BPF program that does the in-kernel counting, and dumping of a report.

在此期间,我们可以使用密件抄送/BPF.如果由于某种原因不能使用bcc,则可以立即使用该offcputime程序并将其用C编写.Linux源代码中提供了一个更复杂的版本,如samples/bpf/offwaketime *.有了Linux上的新BPF功能,只要有意愿,就有办法.

In the meantime, we can use bcc/BPF. If for some reason you can't use bcc, you can, right now, take that offcputime program and write it in C. A more complicated version is available in the Linux source, as samples/bpf/offwaketime*. With the new BPF features on Linux, if there's a will, there's a way.

[1] http ://www.brendangregg.com/blog/2015-02-26/linux-perf-off-cpu-flame-graph.html

[2] https://github.com/iovisor/bcc /blob/master/tools/offcputime_example.txt

这篇关于如何使用linux perf工具生成"Off-CPU"?轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆