• Jin Yao's avatar
    perf top: Support hotkey to change sort order · 2605af0f
    Jin Yao authored
    It would be nice if we can use a hotkey in perf top browser to select a
    event for sorting.
    
    For example:
    
      perf top --group -e cycles,instructions,cache-misses
    
      Samples
                      Overhead  Shared Object             Symbol
        40.03%  45.71%   0.03%  div                       [.] main
        20.46%  14.67%   0.21%  libc-2.27.so              [.] __random_r
        20.01%  19.54%   0.02%  libc-2.27.so              [.] __random
         9.68%  10.68%   0.00%  div                       [.] compute_flag
         4.32%   4.70%   0.00%  libc-2.27.so              [.] rand
         3.84%   3.43%   0.00%  div                       [.] rand@plt
         0.05%   0.05%   2.33%  libc-2.27.so              [.] __strcmp_sse2_unaligned
         0.04%   0.08%   2.43%  perf                      [.] perf_hpp__is_dynamic_en
         0.04%   0.02%   6.64%  perf                      [.] rb_next
         0.04%   0.01%   3.87%  perf                      [.] dso__find_symbol
         0.04%   0.04%   1.77%  perf                      [.] sort__dso_cmp
    
    When user press hotkey '2' (event index, starting from 0), it indicates
    to sort output by the third event in group (cache-misses).
    
      Samples
                      Overhead  Shared Object               Symbol
         4.07%   1.28%   6.68%  perf                        [.] rb_next
         3.57%   3.98%   4.11%  perf                        [.] __hists__insert_output
         3.67%  11.24%   3.60%  perf                        [.] perf_hpp__is_dynamic_e
         3.67%   3.20%   3.20%  perf                        [.] hpp__sort_overhead
         0.81%   0.06%   3.01%  perf                        [.] dso__find_symbol
         1.62%   5.47%   2.51%  perf                        [.] hists__match
         2.70%   1.86%   2.47%  libc-2.27.so                [.] _int_malloc
         0.19%   0.00%   2.29%  [kernel]                    [k] copy_page
         0.41%   0.32%   1.98%  perf                        [.] hists__decay_entries
         1.84%   3.67%   1.68%  perf                        [.] sort__dso_cmp
         0.16%   0.00%   1.63%  [kernel]                    [k] clear_page_erms
    
    Now the output is sorted by cache-misses.
    
     v2:
     ---
     Zero the history if hotkey is pressed.
    Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
    Suggested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Jin Yao <yao.jin@intel.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: http://lore.kernel.org/lkml/20200324220711.6025-2-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    2605af0f
builtin-top.c 46.5 KB