Ubuntu 16.04 LTS - 如何为 perf 工具启用符号 [英] Ubuntu 16.04 LTS - How to enable symbols for the perf tool

查看:239
本文介绍了Ubuntu 16.04 LTS - 如何为 perf 工具启用符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用收集一些分析数据,并为此运行 perf 工具和 Flame Graphs.

I'm trying to gather some profiling data for my app and I run the perf tool and Flame Graphs for that.

我指的是本幻灯片中提供的说明:https://www.slideshare.net/brendangregg/java-performance-analysis-on-linux-with-flame-graphs

I'm referring the instructions provided in this slideshare: https://www.slideshare.net/brendangregg/java-performance-analysis-on-linux-with-flame-graphs

以下是我正在运行的命令:

Below are the commands that I'm running:

1. sudo perf record -F 997 -a -g
2. sudo perf script > out.stacks01

当我运行第二个命令时,它显示以下消息:

When I run the second command, it displays below messages:

Failed to open /tmp/perf-9931.map, continuing without symbols.
no symbols found in <some path>, maybe install a debug package?

我做了一些在线浏览并尝试安装这里提到的调试包:https://gist.github.com/NLKNguyen/2fd920e2a50fd4b9701f

I did some online browsing and tried installing the debug packages as as mentioned here: https://gist.github.com/NLKNguyen/2fd920e2a50fd4b9701f

但是,当我运行sudo apt-get update"时,它最终失败并说无法获取......"

However, when I run "sudo apt-get update", it eventually fails saying "Failed to fetch......"

有人能弄清楚这里发生了什么吗?我需要做什么才能正确安装调试符号包?

Could anybody figure out what's going on here? What do I need to do in order to install the debug symbols package correctly?

我的关键问题是我生成的火焰图中没有 Java 符号,因此我最终专注于上述错误/消息.下面接受的答案为我的原始帖子提供了很好的解释.但是,我可以通过运行 jmaps 来解决我的问题,如下所示:

My key problem was that the flame graph I was generating didn't have Java symbols in it and hence I ended up focusing on above errors/messages. The below accepted answer provides a very good explanation for my original post. However, I was able to resolve my issue by running jmaps as shown below:

sudo perf record -F 997 -a -g -- sleep 300; jmaps 

上面共享的幻灯片共享链接中的说明中记录了这一点.

This is documented in instructions in the slide share link shared above.

推荐答案

Failed to open/tmp/perf-9931.map 消息不是关于错误的调试信息 - 它是关于分析生成的代码由 JIT(Java 通常使用 JIT 从类文件生成机器代码),当与运行的性能分析代理不兼容时.

Failed to open /tmp/perf-9931.map message is not about incorrect debuginfo - it is about profiling code which was generated by JIT (and Java usually generate machine code from class files with JIT), when there was no compatible with perf profiling agent running.

http://www.brendangregg.com/perf.html#JIT_Symbols 建议使用Java can do this with perf-map-agent"来使用 https://github.com/jvm-profiling-tools/perf-map-agent 将为 perf 生成地图文件:

In http://www.brendangregg.com/perf.html#JIT_Symbols there is recommendation "Java can do this with perf-map-agent" to use https://github.com/jvm-profiling-tools/perf-map-agent which will generate map files for perf:

架构

Linux perf 工具将期望从未知执行的代码的符号/tmp/perf-.map 中的内存区域.这允许运行时动态生成代码以提供要使用的动态符号映射使用 perf 工具套件.

Linux perf tools will expect symbols for code executed from unknown memory regions at /tmp/perf-.map. This allows runtimes that generate code on the fly to supply dynamic symbol mappings to be used with the perf suite of tools.

perf-map-agent 是一个代理,它将为Java 应用程序.它由一个用 C 语言编写的 Java 代理和一个小的将代理附加到正在运行的 Java 的 Java 引导程序应用程序过程.

perf-map-agent is an agent that will generate such a mapping file for Java applications. It consists of a Java agent written C and a small Java bootstrap application which attaches the agent to a running Java process.

当附加代理时,它会指示 JVM 报告代码 blob由 JVM 在运行时出于各种目的而生成.最多重要的是,这包括 JIT 编译的方法,但也包括各种动态生成的基础设施部分,如动态为虚拟调度创建了解释器、适配器和跳转表(参见 vtable 和 itable 条目).代理创建一个/tmp/perf-.map 文件,每个代码 blob 填充一行将内存位置映射到代码 blob 名称.

When the agent is attached it instructs the JVM to report code blobs generated by the JVM at runtime for various purposes. Most importantly, this includes JIT-compiled methods but also various dynamically-generated infrastructure parts like the dynamically created interpreter, adaptors, and jump tables for virtual dispatch (see vtable and itable entries). The agent creates a /tmp/perf-.map file which it fills with one line per code blob that maps a memory location to a code blob name.

Java 应用程序将 Java 进程的 PID 作为参数和任意数量的附加参数,它传递给代理人.然后它附加到目标进程并指示它加载代理库.

The Java application takes the PID of a Java process as an argument and an arbitrary number of additional arguments which it passes to the agent. It then attaches to the target process and instructs it to load the agent library.

https://www.slideshare.net/brendangregg/java-performance-analysis-on-linux-with-flame-graphs Gregg 使用了 OpenJDK 的特殊黑客版本 - 幻灯片 36 - "-XX:+PreserveFramePointer• 我破解了 OpenJDK x86_64 以支持帧指针".

And in https://www.slideshare.net/brendangregg/java-performance-analysis-on-linux-with-flame-graphs Gregg used special hacked build of OpenJDK - slide 36 - "-XX:+PreserveFramePointer •  I hacked OpenJDK x86_64 to support frame pointers".

从幻灯片 41 Gregg 谈到 /tmp/perf-*.map 文件:

And from slide 41 Gregg talks about /tmp/perf-*.map files:

固定符号

• 对于 JIT 代码,Linux perf 已经在寻找外部提供的符号文件:/tmp/perf-PID.map,如果它不存在就会发出警告• 此文件可由 Java 代理创建

 • For JIT'd code, Linux perf already looks for an externally provided symbol file: /tmp/perf-PID.map, and warns if it doesn't exist •  This file can be created by a Java agent

# perf script 
Failed to open /tmp/perf-8131.map, continuing without symbols

(还有参见 lkml 以了解perf:添加对分析即时代码的支持""- https://lwn.net/Articles/633846/ 和其他)

(also "See lkml for "perf: add support for profiling jitted code"" - https://lwn.net/Articles/633846/ and other)

这篇关于Ubuntu 16.04 LTS - 如何为 perf 工具启用符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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