Ubuntu 16.04 LTS - 如何为perf工具启用符号

时间:2023-02-05 23:40:13

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

我正在尝试为我的应用程序收集一些分析数据,然后运行perf工具和Flame Graphs。

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

我指的是这个幻灯片中提供的说明: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?

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

我做了一些在线浏览并尝试安装调试包,如下所述:https://gist.github.com/NLKNguyen/2fd920e2a50fd4b9701f

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

但是,当我运行“sudo apt-get update”时,它最终无法说“无法获取......”

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

谁能弄明白这里发生了什么?为了正确安装调试符号包,我需要做什么?

EDIT: 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:

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

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

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

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

1 个解决方案

#1


2  

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.

无法打开/tmp/perf-9931.map消息不是关于不正确的debuginfo - 它是关于由JIT生成的分析代码(并且Java通常使用JIT从类文件生成机器代码),当与性能分析不兼容时代理运行。

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:

在http://www.brendangregg.com/perf.html#JIT_Symbols中,建议“Java可以使用perf-map-agent”来使用https://github.com/jvm-profiling-tools/perf-map -agent将为perf生成地图文件:

Architecture

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.

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

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.

perf-map-agent是一个代理,它将为Java应用程序生成这样的映射文件。它由一个编写C的Java代理和一个小型Java引导应用程序组成,该应用程序将代理程序附加到正在运行的Java进程。

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.

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

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.

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

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".

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

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

从幻灯片41开始,Gregg讨论了/tmp/perf-*.map文件:

Fixing Symbols

 • 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

•对于JIT代码,Linux perf已经查找外部提供的符号文件:/tmp/perf-PID.map,并警告它是否不存在•此文件可以由Java代理创建

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

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

(也“请参阅lkml for”perf:添加对分析jitted代码的支持“” - https://lwn.net/Articles/633846/等)

#1


2  

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.

无法打开/tmp/perf-9931.map消息不是关于不正确的debuginfo - 它是关于由JIT生成的分析代码(并且Java通常使用JIT从类文件生成机器代码),当与性能分析不兼容时代理运行。

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:

在http://www.brendangregg.com/perf.html#JIT_Symbols中,建议“Java可以使用perf-map-agent”来使用https://github.com/jvm-profiling-tools/perf-map -agent将为perf生成地图文件:

Architecture

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.

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

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.

perf-map-agent是一个代理,它将为Java应用程序生成这样的映射文件。它由一个编写C的Java代理和一个小型Java引导应用程序组成,该应用程序将代理程序附加到正在运行的Java进程。

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.

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

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.

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

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".

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

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

从幻灯片41开始,Gregg讨论了/tmp/perf-*.map文件:

Fixing Symbols

 • 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

•对于JIT代码,Linux perf已经查找外部提供的符号文件:/tmp/perf-PID.map,并警告它是否不存在•此文件可以由Java代理创建

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

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

(也“请参阅lkml for”perf:添加对分析jitted代码的支持“” - https://lwn.net/Articles/633846/等)