• Kan Liang's avatar
    perf diff: Support for different binaries · 94ba462d
    Kan Liang authored
    Currently, the perf diff only works with same binaries. That's because
    it compares the symbol start address. It doesn't work if the perf.data
    comes from different binaries. This patch matches the symbol names.
    
    Actually, perf diff once intended to compare the symbol names.  The
    commit as below can look for a pair by name.
    
    604c5c92 (perf diff: Change the default sort order to "dso,symbol")
    However, at that time, perf diff used a global list of dsos. That means
    the binaries which has same name can only be loaded once. That's a
    problem for comparing different binaries.
    
    For example, we have an old binary and an updated binary. They very
    likely have same name and most of the functions, so only dsos from old
    binary will be loaded. When processing the data from updated binary,
    perf still use the symbol information from old binary. That's wrong.
    
    Then the commit as below used IP to replace symbol name.
    9c443dfd ("perf diff: Fix support for all --sort combinations")
    >From that time, perf diff starts to compare the symbol address.
    
    The global dsos is discarded from a patch in 2010.
    a1645ce1 ("perf: 'perf kvm' tool for monitoring guest performance
    from host")
    However, at that time, perf diff already compared by address. So perf
    diff cannot work for different binaries as well.
    
    This patch actually rolls back the perf diff to original design. The
    document is also changed, so everybody knows the original design is to
    compare the symbol names.
    
    Here are some examples:
    
    The only difference between example_v1.c and example_v2.c is the
    location of f2 and f3. There is no change in behavior, but the previous
    perf diff display the wrong differential profile.
    
    example_v1.c
    noinline void f3(void)
    {
            volatile int i;
            for (i = 0; i < 10000;) {
    
                    if(i%2)
                            i++;
                    else
                            i++;
            }
    }
    
    noinline void f2(void)
    {
            volatile int a = 100, b, c;
            for (b = 0; b < 10000; b++)
                    c = a * b;
    
    }
    
    noinline void f1(void)
    {
                    f2();
                    f3();
    }
    
    int main()
    {
            int i;
            for (i = 0; i < 100000; i++)
                    f1();
    }
    
    example_v2.c
    noinline void f2(void)
    {
            volatile int a = 100, b, c;
            for (b = 0; b < 10000; b++)
                    c = a * b;
    }
    
    noinline void f3(void)
    {
            volatile int i;
            for (i = 0; i < 10000;) {
                    if(i%2)
                            i++;
                    else
                            i++;
            }
    }
    
    noinline void f1(void)
    {
                    f2();
                    f3();
    }
    
    int main()
    {
            int i;
            for (i = 0; i < 100000; i++)
                    f1();
    }
    
    [lk@localhost perf_diff]$ gcc example_v1.c -o example
    [lk@localhost perf_diff]$ perf record -o example_v1.data ./example
    [ perf record: Woken up 4 times to write data ]
    [ perf record: Captured and wrote 0.813 MB example_v1.data (~35522 samples) ]
    
    [lk@localhost perf_diff]$ gcc example_v2.c -o example
    [lk@localhost perf_diff]$ perf record -o example_v2.data ./example
    [ perf record: Woken up 4 times to write data ]
    [ perf record: Captured and wrote 0.824 MB example_v2.data (~36015 samples) ]
    
    Old perf diff result:
    
    [lk@localhost perf_diff]$ perf diff example_v1.data example_v2.data
     Event 'cycles'
     Baseline    Delta  Shared Object     Symbol
     ........  .......  ................  ...............................
    
                         [kernel.vmlinux]  [k] __perf_event_task_sched_out
         0.00%           [kernel.vmlinux]  [k] apic_timer_interrupt
                         [kernel.vmlinux]  [k] idle_cpu
                         [kernel.vmlinux]  [k] intel_pstate_timer_func
                         [kernel.vmlinux]  [k] native_read_msr_safe
         0.00%           [kernel.vmlinux]  [k] native_read_tsc
         0.00%           [kernel.vmlinux]  [k] native_write_msr_safe
                         [kernel.vmlinux]  [k] ntp_tick_length
         0.00%           [kernel.vmlinux]  [k] rb_erase
         0.00%           [kernel.vmlinux]  [k] tick_sched_timer
         0.00%           [kernel.vmlinux]  [k] unmap_single_vma
         0.00%           [kernel.vmlinux]  [k] update_wall_time
         0.00%           example           [.] f1
        46.24%           example           [.] f2
        53.71%   -7.55%  example           [.] f3
                +53.81%  example           [.] f3
         0.02%           example           [.] main
    
    New perf diff result:
    
    [lk@localhost perf_diff]$ perf diff example_v1.data example_v2.data
                         [kernel.vmlinux]  [k] __perf_event_task_sched_out
         0.00%           [kernel.vmlinux]  [k] apic_timer_interrupt
                         [kernel.vmlinux]  [k] idle_cpu
                         [kernel.vmlinux]  [k] intel_pstate_timer_func
                         [kernel.vmlinux]  [k] native_read_msr_safe
         0.00%           [kernel.vmlinux]  [k] native_read_tsc
         0.00%           [kernel.vmlinux]  [k] native_write_msr_safe
                         [kernel.vmlinux]  [k] ntp_tick_length
         0.00%           [kernel.vmlinux]  [k] rb_erase
         0.00%           [kernel.vmlinux]  [k] tick_sched_timer
         0.00%           [kernel.vmlinux]  [k] unmap_single_vma
         0.00%           [kernel.vmlinux]  [k] update_wall_time
         0.00%           example           [.] f1
        46.24%   -0.08%  example           [.] f2
        53.71%   +0.11%  example           [.] f3
         0.02%           example           [.] main
    Signed-off-by: default avatarKan Liang <kan.liang@intel.com>
    Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
    Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
    Cc: Andi Kleen <ak@linux.intel.com>
    Link: http://lkml.kernel.org/r/1423460384-11645-1-git-send-email-kan.liang@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    94ba462d
sort.c 43.1 KB