]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf annotate: Add --skip-empty option
authorNamhyung Kim <namhyung@kernel.org>
Sat, 3 Aug 2024 21:13:32 +0000 (14:13 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 5 Aug 2024 19:14:01 +0000 (16:14 -0300)
Like in 'perf report', we want to hide empty events in the 'perf annotate'
output.  This is consistent when the option is set in perf report.

For example, the following command would use 3 events including dummy.

  $ perf mem record -a -- perf test -w noploop

  $ perf evlist
  cpu/mem-loads,ldlat=30/P
  cpu/mem-stores/P
  dummy:u

Just using perf annotate with --group will show the all 3 events.

  $ perf annotate --group --stdio | head
   Percent                 | Source code & Disassembly of ...
  --------------------------------------------------------------
                           : 0     0xe060 <_dl_relocate_object>:
      0.00    0.00    0.00 :    e060:       pushq   %rbp
      0.00    0.00    0.00 :    e061:       movq    %rsp, %rbp
      0.00    0.00    0.00 :    e064:       pushq   %r15
      0.00    0.00    0.00 :    e066:       movq    %rdi, %r15
      0.00    0.00    0.00 :    e069:       pushq   %r14
      0.00    0.00    0.00 :    e06b:       pushq   %r13
      0.00    0.00    0.00 :    e06d:       movl    %edx, %r13d

Now with --skip-empty, it'll hide the last dummy event.

  $ perf annotate --group --stdio --skip-empty | head
   Percent         | Source code & Disassembly of ...
  ------------------------------------------------------
                   : 0     0xe060 <_dl_relocate_object>:
      0.00    0.00 :    e060:       pushq   %rbp
      0.00    0.00 :    e061:       movq    %rsp, %rbp
      0.00    0.00 :    e064:       pushq   %r15
      0.00    0.00 :    e066:       movq    %rdi, %r15
      0.00    0.00 :    e069:       pushq   %r14
      0.00    0.00 :    e06b:       pushq   %r13
      0.00    0.00 :    e06d:       movl    %edx, %r13d

Committer testing:

  root@x1:~# perf evlist
  cpu_atom/mem-loads,ldlat=30/P
  cpu_atom/mem-stores/P
  dummy:u
  root@x1:~#

Before:

  root@x1:~# perf annotate --group --stdio2 do_lookup_x | head -25
  Samples: 20  of events 'cpu_atom/mem-loads,ldlat=30/P, cpu_atom/mem-stores/P, dummy:u', 4000 Hz, Event count (approx.): 769079, [percent: local period]
  do_lookup_x() /usr/lib64/ld-linux-x86-64.so.2
  Percent                       0x9900 <do_lookup_x>:
                                  pushq      %rbp
                                  movq       %rsp,%rbp
                                  pushq      %r15
                                  pushq      %r14
                                  pushq      %r13
                                  pushq      %r12
                                  pushq      %rbx
                                  subq       $0x88,%rsp
                                  movq       %rdi,-0x50(%rbp)
                                  movl       8(%r9),%edi
                                  movq       0x10(%rbp),%r12
                                  movq       0x28(%rbp),%r10
                                  movq       %rdx,-0x70(%rbp)
                                  movq       %rcx,-0x58(%rbp)
                                  movq       %rdi,%r11
     0.00    5.73    0.00         movq       %r8,-0x68(%rbp)
                                  movq       (%r9),%r8
                                  movl       %esi,%eax
     8.30    0.00    0.00         movl       0x30(%rbp),%r9d
                                  movl       %esi,%r15d
                                  shrl       $6, %eax
                                  movq       %r8,%r13
  root@x1:~#

After:

  root@x1:~# perf annotate --group --skip-empty --stdio2 do_lookup_x | head -25
  Samples: 20  of events 'cpu_atom/mem-loads,ldlat=30/P, cpu_atom/mem-stores/P', 4000 Hz, Event count (approx.): 769079, [percent: local period]
  do_lookup_x() /usr/lib64/ld-linux-x86-64.so.2
  Percent               0x9900 <do_lookup_x>:
                          pushq      %rbp
                          movq       %rsp,%rbp
                          pushq      %r15
                          pushq      %r14
                          pushq      %r13
                          pushq      %r12
                          pushq      %rbx
                          subq       $0x88,%rsp
                          movq       %rdi,-0x50(%rbp)
                          movl       8(%r9),%edi
                          movq       0x10(%rbp),%r12
                          movq       0x28(%rbp),%r10
                          movq       %rdx,-0x70(%rbp)
                          movq       %rcx,-0x58(%rbp)
                          movq       %rdi,%r11
     0.00    5.73         movq       %r8,-0x68(%rbp)
                          movq       (%r9),%r8
                          movl       %esi,%eax
     8.30    0.00         movl       0x30(%rbp),%r9d
                          movl       %esi,%r15d
                          shrl       $6, %eax
                          movq       %r8,%r13
  root@x1:~#

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240803211332.1107222-6-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-annotate.txt
tools/perf/builtin-annotate.c
tools/perf/util/annotate.c

index b95524bea021eb2fccdfbb4bf49d465e574584b0..156c5f37b05141cab1bb9311e3282a3596e27118 100644 (file)
@@ -165,6 +165,9 @@ include::itrace.txt[]
 --type-stat::
        Show stats for the data type annotation.
 
+--skip-empty::
+       Do not display empty (or dummy) events.
+
 
 SEE ALSO
 --------
index cf60392b1c19aa215dd733983a4e0260c2e6bc56..efcadb7620b8c62309b742a501495c9c575d8864 100644 (file)
@@ -795,6 +795,8 @@ int cmd_annotate(int argc, const char **argv)
                    "Show stats for the data type annotation"),
        OPT_BOOLEAN(0, "insn-stat", &annotate.insn_stat,
                    "Show instruction stats for the data type annotation"),
+       OPT_BOOLEAN(0, "skip-empty", &symbol_conf.skip_empty,
+                   "Do not display empty (or dummy) events in the output"),
        OPT_END()
        };
        int ret;
index 917897fe44a283980afe38c28109d8c35d09622c..eafe8d65052e770c9d38e64007929472681fae58 100644 (file)
@@ -848,6 +848,10 @@ static void annotation__calc_percent(struct annotation *notes,
 
                        BUG_ON(i >= al->data_nr);
 
+                       if (symbol_conf.skip_empty &&
+                           evsel__hists(evsel)->stats.nr_samples == 0)
+                               continue;
+
                        data = &al->data[i++];
 
                        calc_percent(notes, evsel, data, al->offset, end);
@@ -901,7 +905,7 @@ int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
                .options        = &annotate_opts,
        };
        struct arch *arch = NULL;
-       int err;
+       int err, nr;
 
        err = evsel__get_arch(evsel, &arch);
        if (err < 0)
@@ -922,10 +926,18 @@ int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
                        return -1;
        }
 
-       if (evsel__is_group_event(evsel))
-               notes->src->nr_events = evsel->core.nr_members;
-       else
-               notes->src->nr_events = 1;
+       nr = 0;
+       if (evsel__is_group_event(evsel)) {
+               struct evsel *pos;
+
+               for_each_group_evsel(pos, evsel) {
+                       if (symbol_conf.skip_empty &&
+                           evsel__hists(pos)->stats.nr_samples == 0)
+                               continue;
+                       nr++;
+               }
+       }
+       notes->src->nr_events = nr ? nr : 1;
 
        if (annotate_opts.full_addr)
                notes->src->start = map__objdump_2mem(ms->map, ms->sym->start);