简体   繁体   English

如何摆脱性能中的“未知”部分

[英]how to get rid of the “unknown” section in the perf

what I did is:我所做的是:

1. sudo rm -rf /root/.debug/
2. compile program with -g -O2 -fno-omit-frame-pointer
3. run the program and get the pid
4. sudo perf record -F 2000 -a -s -g -p $pid sleep 15
5. sudo perf report

then I get a tiny part of "unknown", like然后我得到一小部分“未知”,比如

-    2.50%     0.00%  postgres  [unknown]            [k] 0000000000000000                                                                                                                                  
   - 0                                                                                                                                                                                                     
        1.12% _int_malloc                                                                                                                                                                                  ▒
        0.79% _IO_vsnprintf

looks this is due to libc 'malloc' call.看起来这是由于 libc 'malloc' 调用。 then I write a program on the same machine to test it.然后我在同一台机器上编写一个程序来测试它。

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>

int main(int argc, char *argv[])
{
    while(1) {
        printf("perf record -g -p %d -- sleep 5; perf report\n", getpid());
        sleep(1);
        void *p = malloc(10);
        memset(p, 0, 10);
        free(p);
    }
    return 0;
}

then I did the same thing as above, there is no "unknown" section.然后我做了和上面一样的事情,没有“未知”部分。

how to explain/fix this?如何解释/解决这个问题?

The [unknown] block in the perf report output refers to the name of the dynamic shared object ( DSO ).性能perf report output 中的[unknown]块指的是动态共享 object ( DSO ) 的名称。 perf report could not resolve the DSO path and hence it prints [unknown] . perf report无法解析DSO路径,因此打印[unknown] Per the latest kernel source code tree (which is 5.3.9 at the time of writing), you can see this here .根据最新的 kernel 源代码树(撰写本文时为 5.3.9),您可以在此处查看

It is important to know that the determination of the DSO symbols happen with the help of the sampled event address.重要的是要知道 DSO 符号的确定是在采样事件地址的帮助下发生的。 The function thread__resolve is responsible for doing exactly that. function thread__resolve负责执行此操作。 In older kernels, the thread__resolve method had another name - perf_event__preprocess_sample_addr .在较旧的内核中, thread__resolve方法有另一个名称 - perf_event__preprocess_sample_addr

Given the snapshot of your output, it looks like the address of the event that was sampled during perf record , is 0. This means that the address could not be resolved at all.鉴于您的 output 的快照,看起来在perf record期间采样的事件的地址为 0。这意味着该地址根本无法解析。 It is an address in the kernel space (looking at the symbol [k] 0000000000000000 ) and perf in your case, could not resolve it.它是perf空间中的地址(查看符号[k] 0000000000000000 ),在您的情况下,性能无法解决。

The comments highlight setting perf_event_paranoid to a suitable value so that you can probe both kernel and user-space events successfully.注释突出显示将perf_event_paranoid设置为合适的值,以便您可以成功探测 kernel 和用户空间事件。 Setting perf_event_paranoid to a value that allows you to correctly probe events in the kernel space should "be a step" towards correctly resolving the address.perf_event_paranoid设置为允许您正确探测 kernel 空间中的事件的值应该是正确解析地址的“一步”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM