• Mark Santaniello's avatar
    perf script: Support -F brstack,dso and brstacksym,dso · 55b9b508
    Mark Santaniello authored
    Perf script can report the dso for "addr" and "ip" fields.
    
    This adds the same support for the "brstack" and "brstacksym" fields.
    This can be helpful for AutoFDO: we can ignore LBR entries unless the
    source and target address are both in the target module we are about to
    build.
    
    I built a small test akin to "while(1) { do_nothing(); }" where the
    do_nothing function is loaded from a dso:
    
      $ cat burncpu.cpp
      #include <dlfcn.h>
    
      int main() {
        void* handle = dlopen("./dso.so", RTLD_LAZY);
        if (!handle) return -1;
    
        typedef void (*fp)();
        fp do_nothing = (fp) dlsym(handle, "do_nothing");
    
        while(1) {
          do_nothing();
        }
      }
    
      $ cat dso.cpp
      extern "C" void do_nothing() {}
    
      $ cat build.sh
      #!/bin/bash
      g++ -shared dso.cpp -o dso.so
      g++ burncpu.cpp -o burncpu -ldl
    
    I sampled the execution with perf record -b.  Using the new perf script
    functionality I can easily find cases where there was a transition from one
    dso to another:
    
      $ perf record -a -b -- sleep 5
      [ perf record: Woken up 55 times to write data ]
      [ perf record: Captured and wrote 18.815 MB perf.data (43593 samples) ]
    
      $ perf script -F brstack,dso | sed 's/\/0 /\/0\n/g' | grep burncpu | grep dso.so | head -n 1
      0x7f967139b6aa(/tmp/burncpu/dso.so)/0x4006b1(/tmp/burncpu/exe)/P/-/-/0
    
      $ perf script -F brstacksym,dso | sed 's/\/0 /\/0\n/g' | grep burncpu | grep dso.so | head -n 1
      do_nothing+0x5(/tmp/burncpu/dso.so)/main+0x44(/tmp/burncpu/exe)/P/-/-/0
    Signed-off-by: default avatarMark Santaniello <marksan@fb.com>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: http://lkml.kernel.org/r/20170619163825.2012979-1-marksan@fb.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    55b9b508
builtin-script.c 72.3 KB