Question

you may have read this question: how can i get perf to find symbols in my program

1)my question is:

when I use perf report , it gives a result like this:

    # 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

That is: the perf can find symbol in kernel but cannot find symbol in my program.

my program is here:

     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)I have compile the program like:

gcc test.c -g -o test

My env: os:ubuntu kernel:3.10.9

Was it helpful?

Solution

Today, when I run perf test, I got a message saying vmlinux symtab matches kallsyms: Failed.

When I was looking for the reason, I found that the reason is that the value of /proc/sys/kernel/kptr_restrict is 1. When we set it to 0, we will get the symbol in our program.

OTHER TIPS

There are 2 possible sources of the problem:

  • Your perf tool was compiled without elfutils support.
  • Your perf tool cannot find libelf.so library on your target.

I ran into the same problem, and found out the reason is that the dwarf feature of my perf was not turned on.

A simple solution is to recompile perf:

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

This enables perf to find all symbols!

If it still do not work for you, please refer to this link, how to compile a Linux perf tool with all features.

Huh, i just tried this and to me it works as it should, afaik. Enviroment is ubuntu 13.04 (with gcc 4.7.3).

If it still does not work for you, you might want to check out that the debug symbols are otherwise fine, with say 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)
#
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top