• Jin Yao's avatar
    perf report: Allow specifying event to be used as sort key in --group output · 429a5f9d
    Jin Yao authored
    When performing "perf report --group", it shows the event group
    information together. By default, the output is sorted by the first
    event in group.
    
    It would be nice for user to select any event for sorting. This patch
    introduces a new option "--group-sort-idx" to sort the output by the
    event at the index n in event group.
    
    For example,
    
    Before:
    
      # perf report --group --stdio
    
      # To display the perf.data header info, please use --header/--header-only options.
      #
      #
      # Total Lost Samples: 0
      #
      # Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, BR_MISP_RETIRED.ALL_BRANCHES:pp, cpu/event=0xc0,umask=1,cmask=1,
      # Event count (approx.): 6451235635
      #
      #                         Overhead  Command    Shared Object            Symbol
      # ................................  .........  .......................  ...................................
      #
          92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
           3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
           1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
           1.56%   0.01%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494ce
           1.56%   0.00%   0.00%   0.00%  mgen       [kernel.kallsyms]        [k] task_tick_fair
           0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
           0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
           0.00%   0.03%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] g_main_context_check
           0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] apic_timer_interrupt
           ...
    
    After:
    
      # perf report --group --stdio --group-sort-idx 3
    
      # To display the perf.data header info, please use --header/--header-only options.
      #
      #
      # Total Lost Samples: 0
      #
      # Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, BR_MISP_RETIRED.ALL_BRANCHES:pp, cpu/event=0xc0,umask=1,cmask=1,
      # Event count (approx.): 6451235635
      #
      #                         Overhead  Command    Shared Object            Symbol
      # ................................  .........  .......................  ...................................
      #
          92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
           0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
           3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
           0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
           1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
           0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
           0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
           0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
           0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
           0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se
           0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] scheduler_tick
    
    Now the output is sorted by the fourth event in group.
    
     v7:
     ---
     Rebase to latest perf/core, no other change.
    
     v4:
     ---
     1. Update Documentation/perf-report.txt to mention
        '--group-sort-idx' support multiple groups with different
        amount of events and it should be used on grouped events.
    
     2. Update __hpp__group_sort_idx(), just return when the
        idx is out of limit.
    
     3. Return failure on symbol_conf.group_sort_idx && !session->evlist->nr_groups.
        So now we don't need to use together with --group.
    
     v3:
     ---
     Refine the code in __hpp__group_sort_idx().
    
     Before:
       for (i = 1; i < nr_members; i++) {
            if (i == idx) {
                    ret = field_cmp(fields_a[i], fields_b[i]);
                    if (ret)
                            goto out;
            }
       }
    
     After:
       if (idx >= 1 && idx < nr_members) {
            ret = field_cmp(fields_a[idx], fields_b[idx]);
            if (ret)
                    goto out;
       }
    Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: http://lore.kernel.org/lkml/20200220013616.19916-2-yao.jin@linux.intel.com
    [ Renamed pair_fields_alloc() to hist_entry__new_pair() and combined decl + assignment of vars ]
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    429a5f9d
hist.c 20.6 KB