【问题标题】:perf can find symbol in the kernel ,but can not find symbol in my program. How to fix it?perf 可以在内核中找到符号,但在我的程序中找不到符号。如何解决?
【发布时间】:2013-08-29 07:25:35
【问题描述】:

您可能已经阅读过这个问题: how can i get perf to find symbols in my program

1)我的问题是:

当我使用 perf report 时,它会给出如下结果:

    # Overhead  Command      Shared Object                    Symbol
    #   .  .  
    #
        99.59%     test  test               [.] 0x000003d4          
         0.21%     test  [kernel.kallsyms]  [k] __do_fault          
         0.10%     test  [kernel.kallsyms]  [k] run_timer_softirq   
         0.10%     test  [kernel.kallsyms]  [k] __update_cpu_load   
         0.01%     test  [kernel.kallsyms]  [k] set_task_comm       
         0.00%     test  [kernel.kallsyms]  [k] intel_pmu_enable_all

即:perf 可以在内核中找到符号,但在我的程序中找不到符号。

我的程序在这里:

     void longa() 
      { 
         int i,j; 
         for(i = 0; i < 1000000; i++) 
        j=i; //am I silly or crazy? I feel boring and desperate. 
      } 


     void foo2() 
     { 
       int i; 
       for(i=0 ; i < 10; i++) 
        longa(); 
     } 

     void foo1() 
     { 
       int i; 
       for(i = 0; i< 100; i++) 
          longa(); 
     } 

    int main(void) 
     { 
       foo1(); 
       foo2(); 
     } 

2)我已经编译了这样的程序:

gcc test.c -g -o 测试

我的环境:os:ubuntu kernel:3.10.9

【问题讨论】:

  • 你解决了吗?我也遇到过类似的问题,就是它没有正确清理 obj 文件。
  • 我还没有解决这个问题。您的意思是“清理 obj 文件后它可以工作”吗?没有我的obj文件,只有elf和c文件。
  • 我已经解决了这个问题。您可以通过 yzark 看到下面的解决方案

标签: linux performance perf


【解决方案1】:

今天,当我运行perf test 时,我收到一条消息说vmlinux symtab matches kallsyms: Failed

我在找原因的时候,发现原因是/proc/sys/kernel/kptr_restrict的值是1。当我们把它设置为0时,就会在我们的程序中得到这个符号。

【讨论】:

    【解决方案2】:

    有两个可能的问题来源:

    • 您的 perf 工具是在没有 elfutils 支持的情况下编译的。
    • 您的 perf 工具无法在您的目标上找到 libelf.so 库。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,发现原因是我的perfdwarf功能没有打开。

      一个简单的解决办法是重新编译perf

      % sudo apt-get install libdw-dev
      % cd /path/to/perf/source/
      % sudo make
      % sudo make install
      

      这使 perf 能够找到所有符号!

      如果它仍然不适合您,请参考此链接, how to compile a Linux perf tool with all features.

      【讨论】:

        【解决方案4】:

        嗯,我刚试过这个,对我来说它可以正常工作,afaik。环境是 ubuntu 13.04(使用 gcc 4.7.3)。

        如果它仍然不适合您,您可能需要检查调试符号是否正常,比如 gdb。

         % gcc test.c -g -o test
        XXX@YYY
         % perf record ./test
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.060 MB perf.data (~2620 samples) ]
        XXX@YYY
         % perf report --stdio
        # ========
        # captured on: Wed Oct 16 11:58:40 2013
        # hostname : sundberg-office-antec
        # os release : 3.8.0-31-generic
        # perf version : 3.8.13.8
        # arch : x86_64
        # nrcpus online : 2
        # nrcpus avail : 2
        # cpudesc : AMD Phenom(tm) II X2 555 Processor
        # cpuid : AuthenticAMD,16,4,3
        # total memory : 16434276 kB
        # cmdline : /usr/bin/perf_3.8.0-31 record ./test 
        # event : name = cycles, type = 0, config = 0x0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern = 0, excl_host = 0, excl_guest = 1, precise_ip = 0, id = { 671, 672 }
        # HEADER_CPU_TOPOLOGY info available, use -I to display
        # HEADER_NUMA_TOPOLOGY info available, use -I to display
        # pmu mappings: cpu = 4, software = 1, tracepoint = 2, ibs_fetch = 6, ibs_op = 7, breakpoint = 5
        # ========
        #
        # Samples: 1K of event 'cycles'
        # Event count (approx.): 1071717616
        #
        # Overhead  Command      Shared Object                     Symbol
        # ........  .......  .................  .........................
        #
            99.85%     test  test               [.] longa                
             0.08%     test  [kernel.kallsyms]  [k] call_timer_fn        
             0.08%     test  [kernel.kallsyms]  [k] task_work_run        
             0.00%     test  [kernel.kallsyms]  [k] clear_page_c         
             0.00%     test  [kernel.kallsyms]  [k] native_write_msr_safe
        
        
        #
        # (For a higher level overview, try: perf report --sort comm,dso)
        #
        

        【讨论】:

        • 谢谢。可能是我自己编译内核的原因,如果你在一个典型的内核上使用perf,就不会出现这个问题。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-15
        • 1970-01-01
        • 2013-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多