Skip to contentSkip to conversation

perf coverage: A harness for perf, and the fixes it found

PATCH New Arnaldo Carvalho de Melo 2 participants 21 messages Nov 23 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

v12 cover perf coverage: A harness for perf, and the fixes it found

From: Arnaldo Carvalho de Melo <[email protected]>

Hi,

Nothing measured how much of perf the test suite reaches. Patches 18-19 add coverage.sh, which builds perf with clang source based coverage, runs the full test suite and reports line and function coverage, and coverage-table.sh, which renders the biggest uncovered gaps over the whole tree, not only the files the tests already touch.

Patches 1-7 are the fixes the first runs found, 8-17 their tests and the test fixes. 1 is a build fix for the GTK UI, which the coverage build needs; 5 and 6 are parser changes, not regression fixes.

- The GTK UI was not linked with EXTRA_CFLAGS, so the coverage build never saw its counters (1).

- Absolute addressing was missing from the data type resolver (2); movabs was not parsed (6).

- --insn-stat was printed before the samples were accounted (3).

- FEATURE-DUMP did not record features checked outside FEATURE_TESTS

    (4).

- The flexible array member row showed 0.00% while the member said

    100.00% (7).

- Tests cover the x86 operand parser (8), DW_OP_addrx globals (9, test
only: fixed upstream by c3991e42f58a3650), the flexible array path (10), a struct pointer kept in a register at -O2 (11) and annotate stats (12).

- Intel PT virtual LBR, dlfilter zeroed IP and LBR inline unwinding

    test fixes (13-15).

The full root run used for this series, with clang DWARF 4 on this AMD host, measured 112185 of 236044 lines (47.53%), 86374 of 174097 in tools/perf/ (49.61%), 170 passed, 160 subtests, 27 skipped and one failure (21.2, the known Tracepoint event kernel regression). The total includes libbpf and the dlfilters; the Rust workload is built and run but is not instrumented.

That one failure makes the coverage target exit 1 after writing the report and the baseline; the data above is from that completed run.

On aarch64 (Raspberry Pi 4, Cortex-A72, clang 19), the full suite as root, run sequentially, measured 101119 of 232961 lines (43.41%), 75800 of 171070 in tools/perf/ (44.31%), 142 passed, 133 subtests, 47 skipped, two timed out and one failed (130, the stat test; 17 now selects an absent CPU instead of an online one). The parallel test mode starts every test at once and times out on the four cores, hence --sequential and --timeout (18).

The harness, the tests and the review fixes were developed with an AI coding assistant (OpenCode): it drafted the scripts and tests, ran the coverage probes, and proposed the fixes for the review findings. The latest edits were built and checked with the annotate stats test, its skip path and a coverage-prep run on toolbx.

What changed from v11:

- 12: skip the archs without operand extraction, whose insn-stat totals are zero by design; compare the bad counters numerically.

- 18: keep the built python extension so a second root run passes the python tests, purging only its setuptools object cache.

Best regards,

- Arnaldo

Arnaldo Carvalho de Melo (19):
perf build: Link the GTK UI with EXTRA_CFLAGS
perf annotate: Handle absolute addressing in data type profiling perf annotate: Print the stats after the annotations
perf build: Record the features checked outside FEATURE_TESTS perf annotate-x86: Record immediates in a 64-bit field perf annotate-x86: Parse movabs like a mov
perf annotate-data: Count flexible array accesses for the whole struct perf test: Exercise the x86 operand parser
perf test: Exercise DW_OP_addrx global variables
perf test: Exercise the flexible array member path
perf test: Exercise data type resolution from a register perf test: Exercise the annotate stats output
perf test: Fix the Intel PT virtual LBR check
perf test: Drop samples without an IP in the dlfilter test perf test: Skip the LBR inline unwinding check when unsupported perf test: Skip the trace summary BPF tests without kernel BTF perf test: Avoid online CPUs in the offline stat test
perf scripts: Add a coverage harness for perf
perf scripts: Add a coverage table

 tools/perf/.gitignore                         |   1 +
 tools/perf/Documentation/perf-annotate.txt    |   2 +-
 tools/perf/Makefile                           |  15 +-
 tools/perf/Makefile.config                    |   8 +
 tools/perf/Makefile.perf                      |  12 +-
 tools/perf/builtin-annotate.c                 |  20 +-
 tools/perf/scripts/coverage-table.sh          | 337 ++++++++++++
 tools/perf/scripts/coverage.sh                | 494 ++++++++++++++++++
 tools/perf/tests/Build                        |   1 +
 tools/perf/tests/annotate-ops.c               | 172 ++++++
 tools/perf/tests/builtin-test.c               |   4 +
 tools/perf/tests/shell/addr2line_inlines.sh   |  19 +-
 tools/perf/tests/shell/annotate_stats.sh      | 184 +++++++
 .../perf/tests/shell/data_type_flex_array.sh  | 135 +++++
 tools/perf/tests/shell/data_type_global.sh    |  73 +++
 tools/perf/tests/shell/data_type_register.sh  |  86 +++
 tools/perf/tests/shell/script_dlfilter.sh     |   2 +-
 tools/perf/tests/shell/stat.sh                |  21 +-
 tools/perf/tests/shell/test_intel_pt.sh       |  10 +-
 tools/perf/tests/shell/trace_summary.sh       |   9 +
 tools/perf/tests/tests.h                      |   4 +
 tools/perf/tests/workloads/Build              |   6 +
 tools/perf/tests/workloads/flex_array.c       |  71 +++
 tools/perf/tests/workloads/global_data.c      |  57 ++
 tools/perf/tests/workloads/regptr.c           |  60 +++
 tools/perf/ui/browsers/annotate-data.c        |   7 +-
 tools/perf/util/annotate-arch/annotate-x86.c  |  51 +-
 tools/perf/util/annotate-data.c               |  27 +-
 tools/perf/util/annotate-data.h               |   8 +
 tools/perf/util/annotate.c                    |  31 +-
 tools/perf/util/annotate.h                    |  13 +-
 31 files changed, 1894 insertions(+), 46 deletions(-)
 create mode 100755 tools/perf/scripts/coverage-table.sh
 create mode 100755 tools/perf/scripts/coverage.sh
 create mode 100644 tools/perf/tests/annotate-ops.c
 create mode 100755 tools/perf/tests/shell/annotate_stats.sh
 create mode 100755 tools/perf/tests/shell/data_type_flex_array.sh
 create mode 100755 tools/perf/tests/shell/data_type_global.sh
 create mode 100755 tools/perf/tests/shell/data_type_register.sh
 create mode 100644 tools/perf/tests/workloads/flex_array.c
 create mode 100644 tools/perf/tests/workloads/global_data.c
 create mode 100644 tools/perf/tests/workloads/regptr.c
Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH v12 1/19 perf build: Link the GTK UI with EXTRA_CFLAGS

From: Arnaldo Carvalho de Melo <[email protected]>

The GTK objects are compiled with EXTRA_CFLAGS but libperf-gtk.so is linked with LDFLAGS only, so flags with link-time parts never reach it. With -fprofile-instr-generate the profiler runtime is missing at link time. Pass EXTRA_CFLAGS at link time, as the dlfilter rule does.

---
 tools/perf/Makefile.perf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
index 1850ca2eeffe962a..d4b641925ab296db 100644
@@ -644,7 +644,7 @@ $(GTK_IN): FORCE prepare
 	$(Q)$(MAKE) $(build)=gtk
 
 $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS)
-	$(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS)
+	$(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(EXTRA_CFLAGS) $(filter %.o,$^) $(GTK_LIBS)
 
 $(SCRIPTS) : $(OUTPUT)% : %.sh
 	$(QUIET_GEN)$(INSTALL) '$<' '$@'
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH v12 2/19 perf annotate: Handle absolute addressing in data type profiling

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

x86 code accesses globals with absolute addresses, and 64-bit code also uses the same encoding for MMIO: the 64-bit kernel's __default_send_IPI_dest_field uses a disp32 the CPU sign extends, an absolute SIB with no base and no index. From an allmodconfig clang build, arch/x86/kernel/ipi.o:

  890:  8b 04 25 00 c3 5f ff    mov    0xffffffffff5fc300,%eax
  8b1:  89 3c 25 10 c3 5f ff    mov    %edi,0xffffffffff5fc310

These accesses are local APIC MMIO, but demonstrate the absolute SIB encoding. Absolute global accesses in 32-bit code can be resolved to types as well.

llvm-objdump prints the same displacements as -0xa03d00 and -0xa03cf0. The operand parser only recognized offset(reg), so the resolver skipped the access as not a memory reference.

Parse a bare hex number as an absolute memory operand, including the negative disp32 llvm-objdump prints, and use the address in the resolver. The displacement is sign extended for 64-bit objects and zero extended for 32-bit ones; values that do not fit, zero and relocatable addends are skipped.

An absolute global load records the type in the destination register, so the state is TSR_KIND_TYPE; a POINTER state records the address itself. Guard the comparisons that made a -1 frame base equal the -1 "no register" of an absolute operand. A no-register operand is not looked up as a variable, but the %gs:40 kernel stack canary is still recognized; other segment-relative operands are skipped.

---
 tools/perf/util/annotate-arch/annotate-x86.c | 37 ++++++++++++++++----
 tools/perf/util/annotate.c                   | 31 ++++++++++++++--
 tools/perf/util/annotate.h                   |  7 ++++
 3 files changed, 67 insertions(+), 8 deletions(-)
tools/perf/util/annotate-arch/annotate-x86.c +31 -6
index e38a4e7a54d5585c..a975c39c3d6ce008 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <string.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <linux/compiler.h>
 #include <linux/ctype.h>
 #include <linux/zalloc.h>
@@ -230,6 +231,11 @@ static bool vtable_get_rettype(Dwarf_Die *class_die, int offset,
 	return die_get_real_type(&func_die, type_die) != NULL;
 }
 
+static bool is_stack_or_fb_reg(struct type_state *state, int fbreg, int reg)
+{
+	return (fbreg != -1 && reg == fbreg) || reg == state->stack_reg;
+}
+
 static void update_insn_state_x86(struct type_state *state,
 				  struct data_loc_info *dloc, Dwarf_Die *cu_die,
 				  struct disasm_line *dl)
@@ -437,7 +443,7 @@ static void update_insn_state_x86(struct type_state *state,
 		invalidate_reg_state(tsr);
 
 		/* Case 1: Based on stack pointer or frame pointer */
-		if (sreg == fbreg || sreg == state->stack_reg) {
+		if (is_stack_or_fb_reg(state, fbreg, sreg)) {
 			struct type_state_stack *stack;
 			int offset = src->offset - fboff;
 
@@ -626,7 +632,7 @@ static void update_insn_state_x86(struct type_state *state,
 
 retry:
 		/* Check stack variables with offset */
-		if (sreg == fbreg || sreg == state->stack_reg) {
+		if (is_stack_or_fb_reg(state, fbreg, sreg)) {
 			struct type_state_stack *stack;
 			int offset = src->offset - fboff;
 
@@ -717,13 +723,17 @@ static void update_insn_state_x86(struct type_state *state,
 			pr_debug_type_name(&tsr->type, tsr->kind);
 		}
 		/* Or check if it's a global variable */
-		else if (sreg == DWARF_REG_PC) {
+		else if (sreg == DWARF_REG_PC ||
+			 annotated_op_loc__is_abs(src, map__dso(dloc->ms->map))) {
 			struct map_symbol *ms = dloc->ms;
 			u64 ip = ms->sym->start + dl->al.offset;
 			u64 addr;
 			int offset;
 
-			addr = annotate_calc_pcrel(ms, ip, src->offset, dl);
+			if (sreg == DWARF_REG_PC)
+				addr = annotate_calc_pcrel(ms, ip, src->offset, dl);
+			else
+				addr = annotated_op_loc__abs_addr(src, map__dso(ms->map));
 
 			if (!get_global_var_type(cu_die, dloc, ip, addr, &offset,
 						 &type_die) ||
@@ -737,7 +747,7 @@ static void update_insn_state_x86(struct type_state *state,
 			tsr->offset = 0;
 			tsr->ok = true;
 
-			pr_debug_dtp("mov [%x] global addr=%"PRIx64" -> reg%d",
+			pr_debug_dtp("mov [%x] global addr=%#"PRIx64" -> reg%d",
 				     insn_offset, addr, dst->reg1);
 			pr_debug_type_name(&type_die, tsr->kind);
 		}
@@ -827,7 +837,7 @@ static void update_insn_state_x86(struct type_state *state,
 	/* Case 3. register to memory transfers */
 	if (!src->mem_ref && dst->mem_ref) {
 		/* Check stack variables with offset */
-		if (dst->reg1 == fbreg || dst->reg1 == state->stack_reg) {
+		if (is_stack_or_fb_reg(state, fbreg, dst->reg1)) {
 			struct type_state_stack *stack;
 			int offset = dst->offset - fboff;
 
@@ -960,6 +970,21 @@ static void extract_op_location_x86(const struct arch *arch,
 			op_loc->offset = strtol(s + 1, &p, 0);
 			if (p && p != s + 1)
 				op_loc->imm = true;
+		} else if (*s == '-' || strstarts(s, "0x")) {
+			u64 offset = strtoull(s, NULL, 0);
+			bool exact;
+
+			/*
+			 * The offset is an int: a disp32 fits it as a u32 or,
+			 * sign extended, as an int, which is how the LLVM
+			 * disassembler prints one that does not fit an int.
+			 */
+			exact = (s64)(int)offset == (s64)offset;
+			if (offset != 0 && (offset <= UINT_MAX || exact)) {
+				/* An absolute address: 32-bit code, or a 64-bit disp32 */
+				op_loc->mem_ref = true;
+				op_loc->offset = offset;
+			}
 		}
 	}
 }
tools/perf/util/annotate.c +29 -2
index e270d16ce1778487..c41d23d97c005abc 100644
@@ -2755,6 +2755,21 @@ int arch__dwarf_regnum(const struct arch *arch, const char *str)
 	return reg < 0 ? -1 : reg;
 }
 
+/* A relocatable object's operand is an unrelocated addend, not an address */
+bool annotated_op_loc__is_abs(const struct annotated_op_loc *op_loc,
+			      const struct dso *dso)
+{
+	return !dso__rel(dso) && op_loc->mem_ref && op_loc->reg1 == -1 && op_loc->reg2 == -1 &&
+	       op_loc->segment == INSN_SEG_NONE && op_loc->offset != 0;
+}
+
+/* The disp32 of a 64-bit object is sign extended, a 32-bit one is not */
+u64 annotated_op_loc__abs_addr(const struct annotated_op_loc *op_loc,
+			       const struct dso *dso)
+{
+	return dso__is_64_bit(dso) ? (u64)(s64)op_loc->offset : (u32)op_loc->offset;
+}
+
 /**
  * annotate_get_insn_location - Get location of instruction
  * @arch: the architecture info
@@ -2772,7 +2787,7 @@ int arch__dwarf_regnum(const struct arch *arch, const char *str)
  *   mov  (%rax), %rcx   # src_reg1 = rax, src_mem = 1, src_offset = 0
  *                       # dst_reg1 = rcx, dst_mem = 0
  *
- *   mov  0x18, %r8      # src_reg1 = -1, src_mem = 0
+ *   mov  0x18, %r8      # src_reg1 = -1, src_mem = 1, src_offset = 0x18
  *                       # dst_reg1 = r8, dst_mem = 0
  *
  *   mov  %rsi, 8(%rbx,%rcx,4)  # src_reg1 = rsi, src_mem = 0, src_multi_regs = 0
@@ -3046,6 +3061,13 @@ __hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch,
 			dloc.var_addr = annotate_calc_pcrel(ms, dloc.ip,
 							    op_loc->offset, dl);
 		}
+		/* An absolute address: 32-bit code, or a 64-bit disp32 */
+		else if (annotated_op_loc__is_abs(op_loc, map__dso(ms->map))) {
+			struct dso *dso = map__dso(ms->map);
+
+			dloc.var_addr = annotated_op_loc__abs_addr(op_loc, dso);
+			op_loc->reg1 = DWARF_REG_PC;
+		}
 
 		/* This CPU access in kernel - pretend PC-relative addressing */
 		if (dso__kernel(map__dso(ms->map)) && arch__is_x86(arch) &&
@@ -3054,7 +3076,9 @@ __hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch,
 			op_loc->reg1 = DWARF_REG_PC;
 		}
 
-		mem_type = find_data_type(&dloc);
+		mem_type = NULL;
+		if (op_loc->reg1 != -1)
+			mem_type = find_data_type(&dloc);
 
 		if (mem_type == NULL && is_stack_canary(arch, op_loc)) {
 			istat->good++;
@@ -3062,6 +3086,9 @@ __hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch,
 			return &canary_type;
 		}
 
+		if (op_loc->reg1 == -1)
+			continue;
+
 		if (mem_type)
 			istat->good++;
 		else
tools/perf/util/annotate.h +7 -0
index e0fc48ec561225d9..58adf7f84146be5f 100644
@@ -18,6 +18,7 @@
 #include "branch.h"
 #include "evsel.h"
 
+struct dso;
 struct hist_browser_timer;
 struct hist_entry;
 struct map;
@@ -637,6 +638,12 @@ struct annotated_insn_loc {
 	     i < INSN_OP_MAX;						\
 	     i++, op_loc++)
 
+/* Bare number operand: an absolute address, as 32-bit code and the kernel use */
+bool annotated_op_loc__is_abs(const struct annotated_op_loc *op_loc,
+			      const struct dso *dso);
+u64 annotated_op_loc__abs_addr(const struct annotated_op_loc *op_loc,
+			       const struct dso *dso);
+
 /* Get detailed location info in the instruction */
 int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
 			       struct annotated_insn_loc *loc);
Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH v12 3/19 perf annotate: Print the stats after the annotations

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

With --code-with-type the instruction stats are printed from hists__find_annotations() before that event is annotated: the first event reports zeros and later events can report stale counts. The data type total is only counted in --data-type mode, so --type-stat without it is incomplete too.

Print the stats once after all events have been annotated, warning if --type-stat is used without --data-type. Leave the TUI's alternate screen before printing, so the stats remain on the terminal.

Fixes 58824fa0087e1cb7 ("perf annotate: Add --insn-stat option for debugging")
Fixes 61a9741e9f78c64c ("perf annotate: Add --type-stat option for debugging")
Cc Namhyung Kim <[email protected]>
---
 tools/perf/Documentation/perf-annotate.txt |  2 +-
 tools/perf/builtin-annotate.c              | 20 +++++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-annotate.txt +1 -1
index 1a90b09a12d5abb1..d27eff28ba4f6af0 100644
@@ -169,7 +169,7 @@ include::itrace.txt[]
 	all data types it finds.
 
 --type-stat::
-	Show stats for the data type annotation.
+	Show stats for the data type annotation (with --data-type).
 
 --skip-empty::
 	Do not display empty (or dummy) events.
tools/perf/builtin-annotate.c +15 -5
index 7cb7e03d9a21d81b..b7f71cc95c0cd4c0 100644
@@ -414,11 +414,6 @@ static void hists__find_annotations(struct hists *hists,
 	struct rb_node *nd = rb_first_cached(&hists->entries), *next;
 	int key = K_RIGHT;
 
-	if (ann->type_stat)
-		print_annotate_data_stat(&ann_data_stat);
-	if (ann->insn_stat)
-		print_annotate_item_stat(&ann_insn_stat, "Instruction");
-
 	while (nd) {
 		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
 		struct annotation *notes;
@@ -663,6 +658,21 @@ static int __cmd_annotate(struct perf_annotate *ann)
 		hists__find_annotations(hists, pos, ann);
 	}
 
+	if (use_browser == 1 && (ann->insn_stat || ann->type_stat)) {
+		/* Leave the alternate screen before printing to the terminal. */
+		ui__exit(false);
+		use_browser = 0;
+	}
+
+	/* Here use_browser is 0 in stdio and TUI mode, so pr_warning reaches the terminal */
+	if (ann->type_stat && !ann->data_type)
+		pr_warning("Warning: --type-stat needs --data-type\n");
+
+	if (ann->data_type && ann->type_stat)
+		print_annotate_data_stat(&ann_data_stat);
+	if (ann->insn_stat)
+		print_annotate_item_stat(&ann_insn_stat, "Instruction");
+
 	if (use_browser == 2) {
 		void (*show_annotations)(void);
 
Signature · 1 line
2.56.0
author maintainer
#4 lore raw

PATCH v12 4/19 perf build: Record the features checked outside FEATURE_TESTS

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

llvm-perf and rust are in FEATURE_DISPLAY but not in FEATURE_TESTS, and jvmti and jvmti-cmlr are in neither list: they can't be part of the test-all fast path, which sets every FEATURE_TESTS entry to 1 when test-all.c builds. Since FEATURE-DUMP is written from FEATURE_TESTS only, a FEATURES_DUMP= build, as used by build-test, never sees them and silently builds without libLLVM, the rust workloads and the jvmti agent.

Record these four in the dump after the regular feature checks have run, from a list of their own, so that customizing FEATURE_DISPLAY does not change what the dump carries.

Fixes 206dcfca1f5cfac3 ("perf build: Autodetect minimum required llvm-dev version")
Fixes 3f5dfa472ea6771c ("tools build: Fix rust feature detection")
Fixes d4dfdf00d43e017d ("perf jvmti: Plug compilation into perf build")
Fixes dd1d0044dd1c1bf8 ("perf jvmti: Separate jvmti cmlr check")
Cc James Clark <[email protected]>
---
 tools/perf/Makefile.config | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/Makefile.config +7 -0
index aed2e952c8f3710a..88b8bc13a578a24f 100644
@@ -1369,3 +1369,10 @@ endif
 # tests.
 $(shell rm -f $(FEATURE_DUMP_FILENAME))
 $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
+# Features checked outside FEATURE_TESTS aren't part of the test-all fast
+# path, so they have to be checked explicitly and recorded here too,
+# otherwise a FEATURES_DUMP= build silently disables them.
+FEATURE_DUMP_EXTRA := llvm-perf rust jvmti jvmti-cmlr
+ifeq ($(FEATURES_DUMP),)
+$(foreach feat,$(FEATURE_DUMP_EXTRA),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
+endif
Signature · 1 line
2.56.0
author maintainer
#5 lore raw

PATCH v12 5/19 perf annotate-x86: Record immediates in a 64-bit field

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

An x86 immediate is parsed into the int offset shared with displacements, so a constant wider than 32 bits is truncated to garbage that the register tracking then records as its value.

Add a s64 imm_value to struct annotated_op_loc, fill it in extract_op_location_x86() with strtoull() and read it in the three places of update_insn_state_x86() that take an immediate as a constant. The displacement and the ARM64 and x86 %gs: immediates, which fit in 32 bits, stay in offset, and pointer offset tracking is unchanged.

---
 tools/perf/util/annotate-arch/annotate-x86.c | 13 ++++++++-----
 tools/perf/util/annotate.h                   |  6 ++++--
 2 files changed, 12 insertions(+), 7 deletions(-)
tools/perf/util/annotate-arch/annotate-x86.c +8 -5
index a975c39c3d6ce008..94c45806029ee670 100644
@@ -341,7 +341,7 @@ static void update_insn_state_x86(struct type_state *state,
 		tsr->lifetime_end = 0;
 
 		if (src->imm)
-			imm_value = src->offset;
+			imm_value = src->imm_value;
 		else if (has_reg_type(state, src->reg1) &&
 			 state->regs[src->reg1].kind == TSR_KIND_CONST)
 			imm_value = state->regs[src->reg1].imm_value;
@@ -408,7 +408,7 @@ static void update_insn_state_x86(struct type_state *state,
 		tsr->lifetime_end = 0;
 
 		if (src->imm)
-			imm_value = src->offset;
+			imm_value = src->imm_value;
 		else if (has_reg_type(state, src->reg1) &&
 			 state->regs[src->reg1].kind == TSR_KIND_CONST)
 			imm_value = state->regs[src->reg1].imm_value;
@@ -589,7 +589,7 @@ static void update_insn_state_x86(struct type_state *state,
 
 		if (src->imm) {
 			tsr->kind = TSR_KIND_CONST;
-			tsr->imm_value = (s64)src->offset;
+			tsr->imm_value = src->imm_value;
 			tsr->offset = 0;
 			tsr->ok = true;
 
@@ -967,8 +967,11 @@ static void extract_op_location_x86(const struct arch *arch,
 		if (*s == arch->objdump.register_char) {
 			op_loc->reg1 = arch__dwarf_regnum(arch, s);
 		} else if (*s == arch->objdump.imm_char) {
-			op_loc->offset = strtol(s + 1, &p, 0);
-			if (p && p != s + 1)
+			const char *start = s + 1;
+			u64 imm = strtoull(start, &p, 0);
+
+			op_loc->imm_value = imm;
+			if (p && p != start)
 				op_loc->imm = true;
 		} else if (*s == '-' || strstarts(s, "0x")) {
 			u64 offset = strtoull(s, NULL, 0);
tools/perf/util/annotate.h +4 -2
index 58adf7f84146be5f..71a616b5ed1e1358 100644
@@ -530,7 +530,8 @@ int arch__dwarf_regnum(const struct arch *arch, const char *str);
  * struct annotated_op_loc - Location info of instruction operand
  * @reg1: First register in the operand
  * @reg2: Second register in the operand
- * @offset: Memory access offset in the operand
+ * @imm_value: Immediate value of an x86 operand
+ * @offset: Memory access offset, or an ARM64 or x86 %gs: immediate
  * @segment: Segment selector register
  * @addr_mode: Addressing mode, only valid if @mem_ref is true
  * @extend_type: Operand extension type (enum annotated_ext_type)
@@ -538,11 +539,12 @@ int arch__dwarf_regnum(const struct arch *arch, const char *str);
  * @amount: Number of bits to shift
  * @mem_ref: Whether the operand accesses memory
  * @multi_regs: Whether the second register is used
- * @imm: Whether the operand is an immediate value (in offset)
+ * @imm: Whether the operand is an immediate value
  */
 struct annotated_op_loc {
 	int reg1;
 	int reg2;
+	s64 imm_value;
 	int offset;
 	u8 segment;
 	u8 addr_mode;
Signature · 1 line
2.56.0
author maintainer
#6 lore raw

PATCH v12 6/19 perf annotate-x86: Parse movabs like a mov

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

x86__instructions[] has no movabs: ins__find() strips the size suffix of "movabsq" and still finds nothing, so mov__parse() never runs and the source and target operands of the instruction are not split. The data type tracking then sees nothing, where the same instruction as a plain mov sets the destination register.

The clang allmodconfig build has plenty, 282558 in vmlinux, all with an immediate, the KASAN shadow offset:

ffffffff81271e2b: movabsq $-0x2000040000000000, %r15

No movabs with a memory operand shows up in vmlinux or in any object of that build.

Add it as a mov; with the previous patch recording the immediate in 64 bits, both objdump spellings of the KASAN shadow offset track the same constant.

---
 tools/perf/util/annotate-arch/annotate-x86.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/annotate-arch/annotate-x86.c +1 -0
index 94c45806029ee670..0c74266cd4b99925 100644
@@ -85,6 +85,7 @@ static const struct ins x86__instructions[] = {
 	{ .name = "lea",	.ops = &mov_ops,  },
 	{ .name = "lock",	.ops = &lock_ops, },
 	{ .name = "mov",	.ops = &mov_ops,  },
+	{ .name = "movabs",	.ops = &mov_ops,  },
 	{ .name = "movapd",	.ops = &mov_ops,  },
 	{ .name = "movaps",	.ops = &mov_ops,  },
 	{ .name = "movdqa",	.ops = &mov_ops,  },
Signature · 1 line
2.56.0
author maintainer
#7 lore raw

PATCH v12 7/19 perf annotate-data: Count flexible array accesses for the whole struct

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The per-member percentage sums the histogram entries in the member's own [offset, offset + size) range. A flexible array member is resolved at or past the end of its struct, so the struct row only covered its declared size and showed 0.00% while the member row showed 100.00% and the header said N samples.

Take a member's extent as the end of its furthest child as well, so the struct counts what was resolved past it. Union members all start at offset 0, so a plain union keeps its size; a member that is itself a struct with a flexible array extends the union too. The TUI browser accounts the members the same way, use the extent there as well.

Fixes aaca646915a1bb53 ("perf annotate-data: Adjust type offset for flex-array")
Cc Namhyung Kim <[email protected]>
---
 tools/perf/ui/browsers/annotate-data.c |  7 +++----
 tools/perf/util/annotate-data.c        | 27 +++++++++++++++++++++++---
 tools/perf/util/annotate-data.h        |  8 ++++++++
 3 files changed, 35 insertions(+), 7 deletions(-)
tools/perf/ui/browsers/annotate-data.c +3 -4
index 0f778788df4a934b..e4047e97e8a943a4 100644
@@ -53,12 +53,11 @@ static int get_member_overhead(struct annotated_data_type *adt,
 			       struct evsel *leader)
 {
 	struct annotated_member *member = entry->data;
-	int i, k;
+	int i, k, end = annotated_member__extent(member);
 
-	for (i = 0; i < member->size; i++) {
+	for (i = member->offset; i < end; i++) {
 		struct type_hist *h;
 		struct evsel *evsel;
-		int offset = member->offset + i;
 
 		k = 0;
 		for_each_group_evsel(evsel, leader) {
@@ -69,7 +68,7 @@ static int get_member_overhead(struct annotated_data_type *adt,
 				continue;
 
 			h = &adt->histograms[evsel->core.idx];
-			if (hashmap__find(&h->samples, offset, &hist))
+			if (hashmap__find(&h->samples, i, &hist))
 				update_hist_entry(&entry->hists[k], hist);
 			k++;
 		}
tools/perf/util/annotate-data.c +24 -3
index 2332d465f9751ef3..c22fec349c47c495 100644
@@ -2011,7 +2011,7 @@ struct annotated_data_type *find_data_type(struct data_loc_info *dloc)
 	if (result == NULL)
 		return NULL;
 
-	if (result->flex_array && dloc->type_offset > result->self.size) {
+	if (result->flex_array && dloc->type_offset >= result->self.size) {
 		struct annotated_member *flex_array = get_flex_array_member(result);
 
 		if (flex_array && flex_array->size > 0) {
@@ -2208,6 +2208,26 @@ static void print_annotated_data_value(struct type_hist *h, u64 period, int nr_s
 		color_fprintf(stdout, color, " %7.2f", percent);
 }
 
+/*
+ * A flexible array member is resolved past the end of its parent, so the
+ * parent's samples are not bounded by its size.  A GNU extension non-last
+ * member with a flexible array can overlap the next member and double-count.
+ */
+int annotated_member__extent(struct annotated_member *member)
+{
+	struct annotated_member *child;
+	int end = member->offset + member->size;
+
+	list_for_each_entry(child, &member->children, node) {
+		int child_end = annotated_member__extent(child);
+
+		if (child_end > end)
+			end = child_end;
+	}
+
+	return end;
+}
+
 static void print_annotated_data_type(struct annotated_data_type *mem_type,
 				      struct annotated_member *member,
 				      struct evsel *evsel, int indent)
@@ -2215,6 +2235,7 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type,
 	struct annotated_member *child;
 	struct type_hist *h;
 	int i, nr_events = 0, samples = 0;
+	int end = annotated_member__extent(member);
 	u64 period = 0;
 	int width = symbol_conf.show_total_period ? 11 : 7;
 	struct evsel *pos;
@@ -2228,10 +2249,10 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type,
 
 		samples = 0;
 		period = 0;
-		for (i = 0; i < member->size; i++) {
+		for (i = member->offset; i < end; i++) {
 			struct type_hist_entry *entry;
 
-			if (!hashmap__find(&h->samples, member->offset + i, &entry))
+			if (!hashmap__find(&h->samples, i, &entry))
 				continue;
 
 			samples += entry->nr_samples;
tools/perf/util/annotate-data.h +8 -0
index 184262c7356213fa..6e0d410929651426 100644
@@ -260,6 +260,9 @@ void global_var_type__tree_delete(struct rb_root *root);
 /* Print data type annotation (including members) on stdout */
 int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evsel);
 
+/* End offset of a member, including a flexible array's children */
+int annotated_member__extent(struct annotated_member *member);
+
 /* Get name of member field at the given offset in the data type */
 int annotated_data_type__get_member_name(struct annotated_data_type *adt,
 					 char *buf, size_t sz, int member_offset);
@@ -316,6 +319,11 @@ static inline int hist_entry__annotate_data_tty(struct hist_entry *he __maybe_un
 	return -1;
 }
 
+static inline int annotated_member__extent(struct annotated_member *member)
+{
+	return member->offset + member->size;
+}
+
 static inline int annotated_data_type__get_member_name(struct annotated_data_type *adt __maybe_unused,
 						       char *buf __maybe_unused,
 						       size_t sz __maybe_unused,
Signature · 1 line
2.56.0
author maintainer
#8 lore raw

PATCH v12 8/19 perf test: Exercise the x86 operand parser

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Add a unit test for x86 operand parsing. The 64-bit absolute disp32 and movabs cases are from the allmodconfig clang build in the preceding changes. Also check a 32-bit absolute address, an immediate, and values that should not become absolute addresses. Both objdump spellings of the movabs instruction must yield the KASAN shadow offset.

---
 tools/perf/tests/Build          |   1 +
 tools/perf/tests/annotate-ops.c | 172 ++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |   1 +
 tools/perf/tests/tests.h        |   1 +
 4 files changed, 175 insertions(+)
 create mode 100644 tools/perf/tests/annotate-ops.c
tools/perf/tests/Build +1 -0
index 5eebb2ec5ddefcfd..c7edd8569bbccb06 100644
@@ -2,6 +2,7 @@
 
 perf-test-y += builtin-test.o
 perf-test-y += tests-scripts.o
+perf-test-y += annotate-ops.o
 perf-test-y += parse-events.o
 perf-test-y += uncore-event-sorting.o
 perf-test-y += dso-data.o
tools/perf/tests/annotate-ops.c new file +172 -0

172 lines not on this page · raw message

tools/perf/tests/builtin-test.c +1 -0
index 01c78ef20b97dec9..a27baf3a819ccf36 100644
@@ -117,6 +117,7 @@ static struct test_suite *generic_tests[] = {
 	&suite__openat_syscall_event_on_all_cpus,
 	&suite__basic_mmap,
 	&suite__mem,
+	&suite__annotate_ops,
 	&suite__parse_events,
 	&suite__uncore_event_sorting,
 	&suite__expr,
tools/perf/tests/tests.h +1 -0
index af822885890dda73..963cb34acd345153 100644
@@ -153,6 +153,7 @@ DECLARE_SUITE(sample_parsing);
 DECLARE_SUITE(keep_tracking);
 DECLARE_SUITE(parse_no_sample_id_all);
 DECLARE_SUITE(dwarf_unwind);
+DECLARE_SUITE(annotate_ops);
 DECLARE_SUITE(expr);
 DECLARE_SUITE(hists_filter);
 DECLARE_SUITE(mmap_thread_lookup);
Signature · 1 line
2.56.0
author maintainer
#9 lore raw

PATCH v12 9/19 perf test: Exercise DW_OP_addrx global variables

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

clang emits DW_AT_location with DW_OP_addrx for globals in DWARF 5, gcc emits DW_OP_addr. The global_data workload keeps a zero initialized struct in .bss: at run time it sits past the file backed mapping, where the by-name fallback through the thread maps cannot find it, so only the DWARF address lookup resolves it. The test checks that its three member accesses are annotated, so the DW_OP_addrx path is exercised when perf is built with clang and DWARF 5 (e.g. scripts/coverage.sh with DWARF_VERSION=5), and the DW_OP_addr one with gcc.

It skips on 32-bit PIE builds, which reach static globals relative to the GOT base register, and the resolver does not track that.

---
 tools/perf/tests/builtin-test.c            |  1 +
 tools/perf/tests/shell/data_type_global.sh | 73 ++++++++++++++++++++++
 tools/perf/tests/tests.h                   |  1 +
 tools/perf/tests/workloads/Build           |  2 +
 tools/perf/tests/workloads/global_data.c   | 57 +++++++++++++++++
 5 files changed, 134 insertions(+)
 create mode 100755 tools/perf/tests/shell/data_type_global.sh
 create mode 100644 tools/perf/tests/workloads/global_data.c
tools/perf/tests/builtin-test.c +1 -0
index a27baf3a819ccf36..42e85d1b1420f0a7 100644
@@ -214,6 +214,7 @@ static struct test_workload *workloads[] = {
 	&workload__deterministic,
 	&workload__callchain,
 	&workload__false_sharing,
+	&workload__global_data,
 
 #ifdef HAVE_RUST_SUPPORT
 	&workload__code_with_type,
tools/perf/tests/shell/data_type_global.sh new file +73 -0

73 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index 963cb34acd345153..63d49a960eab8f3c 100644
@@ -274,6 +274,7 @@ DECLARE_WORKLOAD(context_switch_loop);
 DECLARE_WORKLOAD(deterministic);
 DECLARE_WORKLOAD(callchain);
 DECLARE_WORKLOAD(false_sharing);
+DECLARE_WORKLOAD(global_data);
 
 #ifdef HAVE_RUST_SUPPORT
 DECLARE_WORKLOAD(code_with_type);
tools/perf/tests/workloads/Build +2 -0
index 43cc4da6fb0786de..03017aaaaa0bec32 100644
@@ -17,6 +17,7 @@ perf-test-y += context_switch_loop.o
 perf-test-y += deterministic.o
 perf-test-y += callchain.o
 perf-test-y += false_sharing.o
+perf-test-y += global_data.o
 
 ifeq ($(CONFIG_RUST_SUPPORT),y)
     perf-test-y += code_with_type.o
@@ -35,3 +36,4 @@ CFLAGS_deterministic.o    = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_named_threads.o    = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_callchain.o        = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_false_sharing.o    = -g -O0 -fno-inline -U_FORTIFY_SOURCE
+CFLAGS_global_data.o      = -g -O0 -fno-inline -U_FORTIFY_SOURCE
tools/perf/tests/workloads/global_data.c new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#10 lore raw

PATCH v12 10/19 perf test: Exercise the flexible array member path

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

No test covered find_flex_array() and get_flex_array_member(). Add a flex_array workload that keeps structs with trailing data[] members behind global pointers, and a test that checks accesses at and past the struct size are resolved and named after the flexible array member; find_data_type() folds offsets past the struct modulo the element size back to the member's offset (+0x4 for char data[] and +0xc for the padded int data[]). The test also checks that the
accesses count for the struct in the percent, samples and period columns. It skips on 32-bit PIE builds, which reach static globals relative to the GOT base register.

---
 tools/perf/tests/builtin-test.c               |   1 +
 .../perf/tests/shell/data_type_flex_array.sh  | 135 ++++++++++++++++++
 tools/perf/tests/tests.h                      |   1 +
 tools/perf/tests/workloads/Build              |   2 +
 tools/perf/tests/workloads/flex_array.c       |  71 +++++++++
 5 files changed, 210 insertions(+)
 create mode 100755 tools/perf/tests/shell/data_type_flex_array.sh
 create mode 100644 tools/perf/tests/workloads/flex_array.c
tools/perf/tests/builtin-test.c +1 -0
index 42e85d1b1420f0a7..d761758201a4b2f2 100644
@@ -215,6 +215,7 @@ static struct test_workload *workloads[] = {
 	&workload__callchain,
 	&workload__false_sharing,
 	&workload__global_data,
+	&workload__flex_array,
 
 #ifdef HAVE_RUST_SUPPORT
 	&workload__code_with_type,
tools/perf/tests/shell/data_type_flex_array.sh new file +135 -0

135 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index 63d49a960eab8f3c..8621ea345b5f06ff 100644
@@ -275,6 +275,7 @@ DECLARE_WORKLOAD(deterministic);
 DECLARE_WORKLOAD(callchain);
 DECLARE_WORKLOAD(false_sharing);
 DECLARE_WORKLOAD(global_data);
+DECLARE_WORKLOAD(flex_array);
 
 #ifdef HAVE_RUST_SUPPORT
 DECLARE_WORKLOAD(code_with_type);
tools/perf/tests/workloads/Build +2 -0
index 03017aaaaa0bec32..74a0cbe49dc93533 100644
@@ -18,6 +18,7 @@ perf-test-y += deterministic.o
 perf-test-y += callchain.o
 perf-test-y += false_sharing.o
 perf-test-y += global_data.o
+perf-test-y += flex_array.o
 
 ifeq ($(CONFIG_RUST_SUPPORT),y)
     perf-test-y += code_with_type.o
@@ -37,3 +38,4 @@ CFLAGS_named_threads.o    = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_callchain.o        = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_false_sharing.o    = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_global_data.o      = -g -O0 -fno-inline -U_FORTIFY_SOURCE
+CFLAGS_flex_array.o       = -g -O0 -fno-inline -U_FORTIFY_SOURCE
tools/perf/tests/workloads/flex_array.c new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#11 lore raw

PATCH v12 11/19 perf test: Exercise data type resolution from a register

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

At -O2 a struct pointer lives in a register (with DWARF describing it with a register location on register-argument ABIs), while the unoptimized workloads the data type tests profile keep their variables on the stack.

Add a regptr workload with a noinline function that takes the pointer from a volatile global, so the compiler cannot constant-propagate the object address, and check that its three member accesses are resolved from that register. The type statistics also verify that the instruction-tracking fallback did not resolve them. The test skips 32-bit x86, which has no register-argument ABI.

---
 tools/perf/tests/builtin-test.c              |  1 +
 tools/perf/tests/shell/data_type_register.sh | 86 ++++++++++++++++++++
 tools/perf/tests/tests.h                     |  1 +
 tools/perf/tests/workloads/Build             |  2 +
 tools/perf/tests/workloads/regptr.c          | 60 ++++++++++++++
 5 files changed, 150 insertions(+)
 create mode 100755 tools/perf/tests/shell/data_type_register.sh
 create mode 100644 tools/perf/tests/workloads/regptr.c
tools/perf/tests/builtin-test.c +1 -0
index d761758201a4b2f2..29068963b9d5bae0 100644
@@ -216,6 +216,7 @@ static struct test_workload *workloads[] = {
 	&workload__false_sharing,
 	&workload__global_data,
 	&workload__flex_array,
+	&workload__regptr,
 
 #ifdef HAVE_RUST_SUPPORT
 	&workload__code_with_type,
tools/perf/tests/shell/data_type_register.sh new file +86 -0

86 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index 8621ea345b5f06ff..6bfb30687e12eeb7 100644
@@ -276,6 +276,7 @@ DECLARE_WORKLOAD(callchain);
 DECLARE_WORKLOAD(false_sharing);
 DECLARE_WORKLOAD(global_data);
 DECLARE_WORKLOAD(flex_array);
+DECLARE_WORKLOAD(regptr);
 
 #ifdef HAVE_RUST_SUPPORT
 DECLARE_WORKLOAD(code_with_type);
tools/perf/tests/workloads/Build +2 -0
index 74a0cbe49dc93533..17189458032c0a17 100644
@@ -19,6 +19,7 @@ perf-test-y += callchain.o
 perf-test-y += false_sharing.o
 perf-test-y += global_data.o
 perf-test-y += flex_array.o
+perf-test-y += regptr.o
 
 ifeq ($(CONFIG_RUST_SUPPORT),y)
     perf-test-y += code_with_type.o
@@ -39,3 +40,4 @@ CFLAGS_callchain.o        = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_false_sharing.o    = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_global_data.o      = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_flex_array.o       = -g -O0 -fno-inline -U_FORTIFY_SOURCE
+CFLAGS_regptr.o           = -g -O2
tools/perf/tests/workloads/regptr.c new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#12 lore raw

PATCH v12 12/19 perf test: Exercise the annotate stats output

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Add a shell test for the --insn-stat and --type-stat output printed once, after the annotations, and for the warning when --type-stat is used without --data-type. The instruction stats run with one and with two events and are checked against the per-instruction rows, so a total that counts only the first event, or does not match the rows, fails; the data type total is checked against its counters. A repeated section also fails.

Operand extraction is implemented only for x86, arm64 and powerpc, so other architectures skip rather than fail on the zero totals it would leave. The bad counters check compares numerically: when every access resolves no counter line is printed, and awks that follow POSIX would then compare "0" to the unset sum as strings.

---
 tools/perf/tests/shell/annotate_stats.sh | 184 +++++++++++++++++++++++
 1 file changed, 184 insertions(+)
 create mode 100755 tools/perf/tests/shell/annotate_stats.sh
tools/perf/tests/shell/annotate_stats.sh new file +184 -0
new file mode 100755
index 0000000000000000..656a4c510a8d890f
@@ -0,0 +1,184 @@
+#!/bin/bash
+# perf annotate instruction stats test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+shelldir=$(dirname "$0")
+. "${shelldir}"/lib/perf_has_symbol.sh
+
+skip_test_missing_symbol datasym
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+perfone=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+perftwo=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
+perfout2=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
+perferr=$(mktemp /tmp/__perf_test.perf.err.XXXXX)
+
+cleanup()
+{
+	rm -f "$perfdata" "$perfone" "$perftwo" "$perfout" "$perfout2" "$perferr"
+	trap - EXIT TERM INT
+}
+
+trap_cleanup()
+{
+	echo "Unexpected signal in ${FUNCNAME[1]}"
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+if ! perf check feature -q dwarf; then
+	echo "Skip: no DWARF (libdw) support"
+	cleanup
+	exit 2
+fi
+
+# The instruction stats are counted by the data type resolver, whose
+# operand extraction is implemented only for x86, arm64 and powerpc;
+# elsewhere the totals are zero by design, not because of a bug.
+case "$(uname -m)" in
+	x86_64 | i[3456]86 | aarch64 | ppc64 | ppc64le) ;;
+	*)
+		echo "Skip: no instruction operand extraction for $(uname -m)"
+		cleanup
+		exit 2
+		;;
+esac
+
+if ! perf record -o "$perfone" -e cpu-clock -- perf test -w datasym \
+		> /dev/null 2>&1 ||
+   ! perf record -o "$perftwo" -e cpu-clock -e task-clock -- \
+		perf test -w datasym > /dev/null 2>&1; then
+	echo "FAIL: perf record"
+	cleanup
+	exit 1
+fi
+
+if ! perf annotate --code-with-type --insn-stat -i "$perfone" --stdio \
+		--percent-limit 1 datasym > "$perfout"; then
+	echo "FAIL: perf annotate"
+	cleanup
+	exit 1
+fi
+
+if ! perf annotate --code-with-type --insn-stat -i "$perftwo" --stdio \
+		--percent-limit 1 datasym > "$perfout2"; then
+	echo "FAIL: perf annotate"
+	cleanup
+	exit 1
+fi
+
+# The instruction stats are accounted while the instructions are
+# displayed; printing them before the display loop shows zeros.  A single
+# positive total would also accept a stale first event's total, so check
+# that the section is printed once, after the annotations.
+if ! awk '
+	/^Annotate Instruction stats/ { sections++ }
+	sections && /^[[:space:]]*[0-9]+\.[0-9]+ : / { late = 1 }
+	END { exit !(sections == 1 && !late) }
+' "$perfout2"; then
+	echo "FAIL: instruction stats not printed once after the annotations"
+	tail -n 30 "$perfout2"
+	cleanup
+	exit 1
+fi
+
+# Each event annotates the same instructions, so the two-event total is
+# twice the one-event total.
+one_total=$(awk '/^total / { t = $2; sub(/,/, "", t); print t; exit }' \
+	    "$perfout")
+two_total=$(awk '/^total / { t = $2; sub(/,/, "", t); print t; exit }' \
+	    "$perfout2")
+if [ -z "$one_total" ] || [ -z "$two_total" ] ||
+   [ "$two_total" -le 0 ] || [ "$two_total" -ne $((2 * one_total)) ]; then
+	echo "FAIL: instruction stats do not count every event" \
+	     "(one event: ${one_total:-none}, two events: ${two_total:-none})"
+	tail -n 30 "$perfout2"
+	cleanup
+	exit 1
+fi
+
+# The totals are the sums of the per-instruction rows.
+if ! awk '
+	/^total / {
+		t = $2; o = $4; b = $7
+		sub(/,/, "", t); sub(/,/, "", o); sub(/,/, "", b)
+		total = t; ok = o; bad = b; next
+	}
+	/^  .*: +[0-9]+ +[0-9]+$/ { good += $(NF - 1); bads += $NF }
+	END {
+		exit !(total > 0 && total == good + bads &&
+		       ok == good && bad == bads)
+	}
+' "$perfout2"; then
+	echo "FAIL: instruction stats do not add up"
+	tail -n 30 "$perfout2"
+	cleanup
+	exit 1
+fi
+
+# No point in recording the data type samples if the PMU cannot do memory
+# events.
+if ! perf mem record -o /dev/null -- true 2>/dev/null; then
+	echo "Skip: cannot record memory events on this PMU"
+	cleanup
+	exit 2
+fi
+
+if ! perf mem record -o "$perfdata" -- perf test -w datasym > /dev/null 2>&1; then
+	echo "FAIL: perf mem record"
+	cleanup
+	exit 1
+fi
+
+# The data type stats are only printed with --data-type, and must be
+# accounted like the instruction stats above.
+if ! perf annotate --data-type --type-stat -i "$perfdata" --stdio \
+		> "$perfout"; then
+	echo "FAIL: perf annotate --data-type --type-stat"
+	cleanup
+	exit 1
+fi
+
+if ! awk '
+	/^Annotate data type stats:/ { sections++ }
+	sections && /^Annotate type: / { late = 1 }
+	END { exit !(sections == 1 && !late) }
+' "$perfout"; then
+	echo "FAIL: data type stats not printed once after the annotations"
+	tail -n 30 "$perfout"
+	cleanup
+	exit 1
+fi
+
+# The total is the sum of the bad counters and of the good ones.
+if ! awk '
+	/^Annotate data type stats:/ { stats = 1; next }
+	!stats { next }
+	/^total / {
+		t = $2; o = $4; b = $7
+		sub(/,/, "", t); sub(/,/, "", o); sub(/,/, "", b)
+		total = t; ok = o; bad = b; next
+	}
+	/^[[:space:]]*[0-9]+ : / && $3 != "insn_track" { fields += $1 }
+	END { exit !(total > 0 && total == ok + bad && bad + 0 == fields + 0) }
+' "$perfout"; then
+	echo "FAIL: data type stats do not add up"
+	tail -n 30 "$perfout"
+	cleanup
+	exit 1
+fi
+
+if ! perf annotate --type-stat -i "$perfdata" --stdio > /dev/null 2> "$perferr" ||
+   ! grep -Fxq "Warning: --type-stat needs --data-type" "$perferr"; then
+	echo "FAIL: missing --type-stat warning"
+	tail -n 30 "$perferr"
+	cleanup
+	exit 1
+fi
+
+echo "instruction stats accounted"
+cleanup
Signature · 1 line
2.56.0
author maintainer
#13 lore raw

PATCH v12 13/19 perf test: Fix the Intel PT virtual LBR check

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

On an Intel host the virtual LBR check failed with:

Warning: Processed 29 samples and lost 100.00%

The record leaves the buffer sizes to the tool defaults: the data ring follows perf_event_mlock_kb, and the runner's small value left a single page, too small for the AUX samples. Pin 4 data and 64 AUX pages, so the test does not depend on the host sysctl, and give the AUX ring room instead of the single page the tool sizes to the 4 KiB snapshot. Both fit in the default mlock allowance regardless of the CPU count.

Also require the Python perf module to export session: a perf module without it, like the distro's python3-perf, made the check fail instead of skipping.

Fixes 915d6b14dc0c8971 ("perf test: Migrate Intel PT virtual LBR test to Python API")
Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
---
 tools/perf/tests/shell/test_intel_pt.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/perf/tests/shell/test_intel_pt.sh +6 -4
index c0ecece0a8255124..96f5c132cebf23e6 100755
@@ -384,13 +384,15 @@ test_virtual_lbr()
 	# shellcheck source=lib/setup_python.sh
 	. "${shelldir}"/lib/setup_python.sh
 
-	if ! "$PYTHON" -c 'import perf' > /dev/null 2>&1; then
-		echo "SKIP: Python perf module not found"
+	if ! "$PYTHON" -c 'import perf; perf.session' > /dev/null 2>&1; then
+		echo "SKIP: Python perf module with session support not found"
 		return 2
 	fi
 
-	# Check if virtual lbr is working
-	perf_record_no_bpf -o "${tmpfile}" --aux-sample \
+	# The default data ring follows perf_event_mlock_kb and can be too
+	# small for the AUX samples; pin 4 data and 64 AUX pages, which fit
+	# in the default allowance.
+	perf_record_no_bpf -m 4,64 -o "${tmpfile}" --aux-sample \
 		-e '{intel_pt//,cycles}:u' perf test -w brstack || return 1
 	perf inject --itrace=L -i "${tmpfile}" -o "${perfdatafile}" || return 1
 	output=$("$PYTHON" "${shelldir}/lib/perf_brstack_max.py" -i "${perfdatafile}") || return 1
Signature · 1 line
2.56.0
author maintainer
#14 lore raw

PATCH v12 14/19 perf test: Drop samples without an IP in the dlfilter test

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Since v7.3 the kernel zeroes PERF_SAMPLE_IP when a user-only event skids into kernel mode, so that kernel register state is not exposed to user
space: commit 166f10836a653dfa ("perf/core: Fix kernel register info leak via hardware skid").

The test records without an event modifier, which is user-only only when perf falls back to cycles:u for an unprivileged user, which is why root runs never saw it. The dlfilter keeps those ip 0 samples, and the check that nothing but test_loop survives then trips on their lines: the comm column reads "perf". Drop them, as everything except test_loop must be filtered out.

Fixes 199d5e872a9ce737 ("perf tests script dlfilter: Add a dlfilter test")
---
 tools/perf/tests/shell/script_dlfilter.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/script_dlfilter.sh +1 -1
index 88222280f6094fd0..797cd9ae84141f64 100755
@@ -46,7 +46,7 @@ int filter_event(void *data, const struct perf_dlfilter_sample *sample, void *ct
 	const struct perf_dlfilter_al *al;
 
 	if (!sample->ip)
-		return 0;
+		return 1;
 
 	al = perf_dlfilter_fns.resolve_ip(ctx);
 	if (!al || !al->sym || strcmp(al->sym, "test_loop"))
Signature · 1 line
2.56.0
author maintainer
#15 lore raw

PATCH v12 15/19 perf test: Skip the LBR inline unwinding check when unsupported

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The LBR check takes caps/branches as sufficient to record cycles with --call-graph lbr, but the file only says the PMU has an LBR: AMD LBRv2 rejects the call stack mode with EOPNOTSUPP, so the test fails on AMD instead of skipping.

Skip when perf says the branch stack mode is unsupported, so a record that fails for another reason still shows its error and fails the test.

Fixes 446c595dc0dd1759 ("perf test addr2line_inlines: Ensure inline information shows on LBR leaves")
Cc Ian Rogers <[email protected]>
---
 tools/perf/tests/shell/addr2line_inlines.sh | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
tools/perf/tests/shell/addr2line_inlines.sh +18 -1
index e8754ef2d7f21ac2..02a896c9d99cb2ac 100755
@@ -8,6 +8,7 @@ err=0
 test_dir=$(mktemp -d /tmp/perf-test-inline-addr2line.XXXXXXXXXX)
 perf_data="${test_dir}/perf.data"
 perf_script_txt="${test_dir}/perf_script.txt"
+perf_record_err="${test_dir}/perf_record.err"
 
 cleanup() {
     rm -rf "${test_dir}"
@@ -71,7 +72,23 @@ test_lbr() {
     fi
 
     # Record data. Currently only dwarf callchains support inlined functions.
-    perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf test -w inlineloop 1
+    # caps/branches does not mean the LBR call stack is supported: AMD LBRv2
+    # rejects it with EOPNOTSUPP.  Skip only when perf says the branch stack
+    # mode is unsupported, other record failures still fail the test.
+    if ! perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- \
+            perf test -w inlineloop 1 2> "${perf_record_err}"
+    then
+        if grep -q "doesn't support branch stack sampling" "${perf_record_err}"
+        then
+            echo "Skip: LBR call stack not supported by the PMU"
+        else
+            cat "${perf_record_err}"
+            echo "Inline unwinding lbr verification test [Failed to record]"
+            err=1
+        fi
+        return
+    fi
+    cat "${perf_record_err}"
 
     # Check output with inline (default) and srcline
     perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
Signature · 1 line
2.56.0
author maintainer
#16 lore raw

PATCH v12 16/19 perf test: Skip the trace summary BPF tests without kernel BTF

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The --bpf-summary tests need BTF in the running kernel; perf check feature bpf only tells whether perf was built with libbpf. Without CONFIG_DEBUG_INFO_BTF the skeleton fails to load and the test fails instead of skipping.

The /sys/kernel/btf/vmlinux file indicates that the running kernel has BTF available for the tp_btf programs. Do not use an on-disk vmlinux image for this check: it can be readable even when the running kernel has no BTF loaded.

Fixes 2d099ccaadf623d3 ("perf test: Add perf trace summary test")
Cc Ian Rogers <[email protected]>
---
 tools/perf/tests/shell/trace_summary.sh | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/tests/shell/trace_summary.sh +9 -0
index 0e603addb2a99d4d..154f85f16e6528f9 100755
@@ -63,6 +63,15 @@ if ! perf check feature -q bpf; then
     exit 2
 fi
 
+# The tp_btf programs need BTF in the running kernel.  A vmlinux image
+# on disk is not sufficient: it can be readable even when the kernel has
+# no BTF loaded.
+if [ ! -r /sys/kernel/btf/vmlinux ]; then
+    echo "Skip --bpf-summary tests as kernel BTF is missing"
+    rm -f ${OUTPUT}
+    exit 2
+fi
+
 # summary only for system wide - per-thread summary with BPF
 test_perf_trace "-as --summary-mode=thread --bpf-summary"
 
Signature · 1 line
2.56.0
author maintainer
#17 lore raw

PATCH v12 17/19 perf test: Avoid online CPUs in the offline stat test

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

find_offline_cpu() treats a missing cpuN/online file as an offline CPU, but kernels without CPU hotplug also lack it for online CPUs. The test then expects "No supported events found." from a working CPU.

Treat a present CPU as offline only if its online file reads 0. Keep the absent cpuN case to exercise an invalid CPU, and skip if neither exists.

Fixes 5123509628e1ebe7 ("perf tests stat: Add test for error for an offline CPU")
Cc Ian Rogers <[email protected]>
---
 tools/perf/tests/shell/stat.sh | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
tools/perf/tests/shell/stat.sh +14 -7
index ac9e031831daca9c..7cd9999fd526bbd6 100755
@@ -43,21 +43,28 @@ test_null_stat() {
 }
 
 find_offline_cpu() {
-  for i in $(seq 1 4096)
+  for i in $(seq 0 4096)
   do
-    if [[ ! -f /sys/devices/system/cpu/cpu$i/online || \
-          $(cat /sys/devices/system/cpu/cpu$i/online) == "0" ]]
+    if [[ ! -d /sys/devices/system/cpu/cpu$i ]]
     then
       echo $i
-      return
+      return 0
+    elif [[ -f /sys/devices/system/cpu/cpu$i/online && \
+            $(cat /sys/devices/system/cpu/cpu$i/online) == "0" ]]
+    then
+      echo $i
+      return 0
     fi
   done
-  echo "Failed to find offline CPU"
-  exit 1
+  return 1
 }
 
 test_offline_cpu_stat() {
-  cpu=$(find_offline_cpu)
+  if ! cpu=$(find_offline_cpu)
+  then
+    echo "Offline CPU stat command test [Skipped - no offline CPU]"
+    return
+  fi
   echo "Offline CPU stat command test (cpu $cpu)"
   if ! perf stat "-C$cpu" -e cycles true 2>&1 | grep -E -q "No supported events found."
   then
Signature · 1 line
2.56.0
author maintainer
#18 lore raw

PATCH v12 18/19 perf scripts: Add a coverage harness for perf

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Build perf with clang source based coverage, run the complete perf test suite, merge the raw profiles and report line and function coverage, optionally against a baseline. Wired as 'make -C tools/perf coverage' and 'coverage-prep'; coverage-prep builds the instrumented perf apart from the test run, for the root tests on the bare metal host while building in the development container.

The report covers every instrumented C and C++ source, not only the paths the tests walk; the Rust workload is built and exercised, but rustc does not get coverage flags. The static libbpf build inherits EXTRA_CFLAGS, the C++ sources get the same coverage flags through EXTRA_CXXFLAGS without dropping a CXXFLAGS from the environment, and the dlopened UI, jvmti, Python and dlfilter libraries are passed to llvm-cov as separate objects. The host tools are built with clang too, so the build does not need gcc. The test suite runs in parallel by default; --sequential runs one test at a time, and --timeout SECS raises the per-test timeout, for machines with few CPUs or slow storage. 'perf test' exits 0 even when tests fail and when the test filter matches nothing, so the status comes from its "Failed tests :" and "Timed out tests :" lines and a run with every count zero is an error. The dlfilter objects and shared libraries are rebuilt on each perf build, the python extension is dropped before a build and its setuptools object cache after it, as that cache keys on timestamps only. The built extension then stays in the build dir, so a second root run of the prepared build keeps passing the python tests.

---
 tools/perf/.gitignore          |   1 +
 tools/perf/Makefile            |  12 +-
 tools/perf/Makefile.config     |   1 +
 tools/perf/Makefile.perf       |   9 +-
 tools/perf/scripts/coverage.sh | 486 +++++++++++++++++++++++++++++++++
 5 files changed, 505 insertions(+), 4 deletions(-)
 create mode 100755 tools/perf/scripts/coverage.sh
tools/perf/.gitignore +1 -0
index 3b968c5158b822ce..d263877366ca1440 100644
@@ -27,6 +27,7 @@ stats-*.csv
 cscope*
 config.mak
 config.mak.autogen
+/cov/
 *-bison.*
 *-flex.*
 *.pyc
tools/perf/Makefile +11 -1
index 00baf90e5bda7123..d9ad8c0d796c2852 100644
@@ -140,6 +140,16 @@ check-headers:
 sync-headers:
 	@./scripts/sync-headers.sh $(SYNC_HEADERS_ARGS)
 
+coverage_o = $(if $(O),\
+$(if $(shell cd $(PWD); test -d $(O) || echo $(O)),\
+$(error O=$(O) does not exist),--build-dir=$(FULL_O)))
+
+coverage-prep:
+	@./scripts/coverage.sh --prep $(coverage_o) $(COVERAGE_ARGS)
+
+coverage:
+	@./scripts/coverage.sh $(coverage_o) $(COVERAGE_ARGS)
+
 #
 # All other targets get passed through:
 #
@@ -147,4 +157,4 @@ sync-headers:
 	$(print_msg)
 	$(make)
 
-.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers
+.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers coverage coverage-prep
tools/perf/Makefile.config +1 -0
index 88b8bc13a578a24f..11043520675d2c6a 100644
@@ -19,6 +19,7 @@ detected     = $(shell echo "$(1)=y"       >> $(OUTPUT).config-detected)
 detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
 
 CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
+CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS)
 HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
 
 # This is required because the kernel is built with this and some of the code
tools/perf/Makefile.perf +6 -3
index d4b641925ab296db..1b4efe6254fa0370 100644
@@ -779,13 +779,13 @@ $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-map.c
 	$(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
 endif
 
-$(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h
+$(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h FORCE
 	$(Q)$(MKDIR) -p $(OUTPUT)dlfilters
 	$(QUIET_CC)$(CC) -c -Iinclude $(EXTRA_CFLAGS) -o $@ -fpic $<
 
 .SECONDARY: $(DLFILTERS:.so=.o)
 
-$(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o
+$(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o FORCE
 	$(QUIET_LINK)$(CC) $(filter-out -static,$(LDFLAGS)) $(EXTRA_CFLAGS) -shared -o $@ $<
 
 ifndef NO_JVMTI
@@ -812,7 +812,7 @@ $(LIBAPI)-clean:
 $(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
 	$(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \
 		O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \
-		EXTRA_CFLAGS="-fPIC" $@ install_headers
+		EXTRA_CFLAGS="-fPIC $(EXTRA_CFLAGS)" $@ install_headers
 
 $(LIBBPF)-clean:
 	$(call QUIET_CLEAN, libbpf)
@@ -877,6 +877,9 @@ help:
 	@echo '  check-headers		- check which header copies are out of sync with the kernel'
 	@echo '  sync-headers		- sync those header copies with the kernel, creating commits'
 	@echo '			  (SYNC_HEADERS_ARGS="..." passes options to the script)'
+	@echo '  coverage-prep		- build perf with clang coverage, ready for a root test run'
+	@echo '  coverage		- build perf with clang coverage, run the tests and report'
+	@echo '			  (O=DIR uses an existing build dir; COVERAGE_ARGS="..." passes options)'
 
 
 DOC_TARGETS := doc man html info pdf
tools/perf/scripts/coverage.sh new file +486 -0

486 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#19 lore raw

PATCH v12 19/19 perf scripts: Add a coverage table

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Render the report of the last coverage run as a table of the files with the most uncovered lines, biggest gap first; --all lists every file and -f picks files explicitly, failing when a requested file has no coverage data. coverage.sh prints the table when a run finishes; it is also wired as 'make -C tools/perf coverage-table', to print just the table. It only reads coverage.sh's report.txt, so the measurement and the table are reviewed and changed separately.

For example, with --top 4 on a full test suite run:

    $ make -C tools/perf coverage-table O=/tmp/build/coverage \
          COVERAGE_ARGS="--top 4"
    tools/perf (no tests/ or bench/), 100+ executable lines:
    the 4 biggest uncovered gaps, start here when adding coverage tests.
    --all for every file: make -C tools/perf coverage-table O=/tmp/build/coverage COVERAGE_ARGS="--all"
    ┌──────────────────────────────────────────┬────────┬────────┬────────┬─────────────────────────────┬─────────────┬──────────┐
    │ File                                     │  Lines │    Hit │   Miss │        Line Coverage        │       Funcs │  FuncCov │
    ├──────────────────────────────────────────┼────────┼────────┼────────┼─────────────────────────────┼─────────────┼──────────┤
    │ util/intel-pt.c                          │   3237 │      0 │   3237 │ ░░░░░░░░░░░░░░░░░░░░   0.0% │     0/142   │    0.00% │
    │ util/intel-pt-decoder/intel-pt-decoder.c │   3208 │      0 │   3208 │ ░░░░░░░░░░░░░░░░░░░░   0.0% │     0/119   │    0.00% │
    │ ui/browsers/hists.c                      │   2742 │      0 │   2742 │ ░░░░░░░░░░░░░░░░░░░░   0.0% │     0/124   │    0.00% │
    │ builtin-sched.c                          │   3737 │   1543 │   2194 │ ████████░░░░░░░░░░░░  41.3% │    62/141   │   43.97% │
    ├──────────────────────────────────────────┼────────┼────────┼────────┼─────────────────────────────┼─────────────┼──────────┤
    │ TOTAL (perf)                             │ 174097 │  86374 │  87723 │ █████████░░░░░░░░░░░  49.6% │  5650/9358  │   60.38% │
    └──────────────────────────────────────────┴────────┴────────┴────────┴─────────────────────────────┴─────────────┴──────────┘
---
 tools/perf/Makefile                  |   5 +-
 tools/perf/Makefile.perf             |   3 +-
 tools/perf/scripts/coverage-table.sh | 337 +++++++++++++++++++++++++++
 tools/perf/scripts/coverage.sh       |  14 +-
 4 files changed, 354 insertions(+), 5 deletions(-)
 create mode 100755 tools/perf/scripts/coverage-table.sh
tools/perf/Makefile +4 -1
index d9ad8c0d796c2852..5da13faa1c18b510 100644
@@ -150,6 +150,9 @@ coverage-prep:
 coverage:
 	@./scripts/coverage.sh $(coverage_o) $(COVERAGE_ARGS)
 
+coverage-table:
+	@./scripts/coverage-table.sh $(coverage_o) $(COVERAGE_ARGS)
+
 #
 # All other targets get passed through:
 #
@@ -157,4 +160,4 @@ coverage:
 	$(print_msg)
 	$(make)
 
-.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers coverage coverage-prep
+.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers coverage coverage-prep coverage-table
tools/perf/Makefile.perf +2 -1
index 1b4efe6254fa0370..6427d3a012c465d1 100644
@@ -878,7 +878,8 @@ help:
 	@echo '  sync-headers		- sync those header copies with the kernel, creating commits'
 	@echo '			  (SYNC_HEADERS_ARGS="..." passes options to the script)'
 	@echo '  coverage-prep		- build perf with clang coverage, ready for a root test run'
-	@echo '  coverage		- build perf with clang coverage, run the tests and report'
+	@echo '  coverage		- build perf with clang coverage, run the tests, report and show the table'
+	@echo '  coverage-table	- print a text table of the last coverage run'
 	@echo '			  (O=DIR uses an existing build dir; COVERAGE_ARGS="..." passes options)'
 
 
tools/perf/scripts/coverage-table.sh new file +337 -0

337 lines not on this page · raw message

tools/perf/scripts/coverage.sh +11 -3
index e9a4cf807850e1c7..bb075c9a54e820cd 100755
@@ -3,8 +3,9 @@
 #
 # Copyright (C) 2026, Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]>
 #
-# Build perf with clang source based coverage, run the perf test suite and
-# report line coverage.
+# Build perf with clang source based coverage, run the perf test suite,
+# report line coverage and the table of the files with the most uncovered
+# lines.  coverage-table.sh renders that table from the last report alone.
 # The build goes into tools/perf and the profiles and report into
 # tools/perf/cov; -b and -c override them, following perf's O= layout.
 # --prep stops after the instrumented build, for running the tests later as
@@ -44,7 +45,9 @@ usage()
 Usage: scripts/coverage.sh [options] [test name fragment...]
 
 Builds perf with clang source based coverage, runs the complete perf test
-suite and reports line coverage.  Use -t to run a subset.
+suite, reports line coverage and the files with the most uncovered lines.
+Use -t to run a subset; scripts/coverage-table.sh renders the table again
+with other options.
 
 Options:
   -b, --build-dir DIR    existing perf build directory (default: $PERF_DIR)
@@ -64,6 +67,7 @@ Through make:
   make -C tools/perf coverage
   make -C tools/perf coverage-prep O=/tmp/build/perf-coverage
   sudo make -C tools/perf coverage O=/tmp/build/perf-coverage
+  make -C tools/perf coverage-table O=/tmp/build/perf-coverage
 EOF
 }
 
@@ -482,5 +486,9 @@ render_report
 print_summary
 update_baseline
 
+printf "\n"
+"$PERF_DIR/scripts/coverage-table.sh" --build-dir "$BUILD_DIR" \
+	--cov-dir "$COV_DIR" || warn "could not render the coverage table"
+
 printf "\nReport:  %s\n" "$REPORT"
 exit "$test_status"
Signature · 1 line
2.56.0