[4/4] perf report: Do not show dummy events with --skip-empty

Message ID 20240213075256.1983638-5-namhyung@kernel.org
State New
Headers
Series perf report: Omit dummy events in the output (v1) |

Commit Message

Namhyung Kim Feb. 13, 2024, 7:52 a.m. UTC
  In system-wide mode, a dummy event was added during the perf record to
save various side-band events like FORK, MMAP and so on.  But this dummy
event doesn't have samples for itself so it just wastes the output with
all zero values.

When --skip-empty option is on (by default), it can skip those (dummy)
events without any samples by removing them from the evlist.  Users can
disable it using --no-skip-empty command line option or setting the
report.skip-empty config option to false.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/Documentation/perf-report.txt |  3 ++-
 tools/perf/builtin-report.c              | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
  

Patch

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index d8b863e01fe0..546af27d209c 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -609,7 +609,8 @@  include::itrace.txt[]
 	'Avg Cycles'      - block average sampled cycles
 
 --skip-empty::
-	Do not print 0 results in the --stat output.
+	Do not print 0 results in the output.  This means skipping dummy events
+	in the event list and the --stat output.
 
 include::callchain-overhead-calculation.txt[]
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 8e16fa261e6f..60e30f13c8f8 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -752,10 +752,22 @@  static int hists__resort_cb(struct hist_entry *he, void *arg)
 static void report__output_resort(struct report *rep)
 {
 	struct ui_progress prog;
-	struct evsel *pos;
+	struct evsel *pos, *tmp;
 
 	ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
 
+	if (rep->skip_empty) {
+		evlist__for_each_entry_safe(rep->session->evlist, tmp, pos) {
+			struct hists *hists = evsel__hists(pos);
+
+			if (hists->nr_entries != 0)
+				continue;
+
+			evlist__remove(rep->session->evlist, pos);
+			evsel__delete(pos);
+		}
+	}
+
 	evlist__for_each_entry(rep->session->evlist, pos) {
 		evsel__output_resort_cb(pos, &prog, hists__resort_cb, rep);
 	}