From: Andi Kleen <ak@linux.intel.com>
To: namhyung@kernel.org
Cc: acme@kernel.org, linux-perf-users@vger.kernel.org,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH v2 4/4] perf tools: Add test for weight annotation
Date: Thu, 13 Aug 2026 14:10:10 -0700 [thread overview]
Message-ID: <20260813211109.240689-5-ak@linux.intel.com> (raw)
In-Reply-To: <20260813211109.240689-1-ak@linux.intel.com>
Add a test case to check if --stdio weight annotation works
Assisted-by: omp:GPT-5.6-Luna
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/tests/shell/annotate_weight.sh | 63 +++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100755 tools/perf/tests/shell/annotate_weight.sh
diff --git a/tools/perf/tests/shell/annotate_weight.sh b/tools/perf/tests/shell/annotate_weight.sh
new file mode 100755
index 000000000000..6b8c105c048b
--- /dev/null
+++ b/tools/perf/tests/shell/annotate_weight.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# perf annotate weight regression test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+shelldir=$(dirname "$0")
+# shellcheck source=tools/perf/tests/shell/lib/perf_has_symbol.sh
+. "${shelldir}"/lib/perf_has_symbol.sh
+
+testsym="test_loop"
+skip_test_missing_symbol "${testsym}"
+
+perfdata=$(mktemp /tmp/__perf_test.annotate_weight.XXXXX)
+record_log=$(mktemp /tmp/__perf_test.annotate_weight.XXXXX.log)
+report_out=$(mktemp /tmp/__perf_test.annotate_weight.XXXXX.report)
+annotate_out=$(mktemp /tmp/__perf_test.annotate_weight.XXXXX.annotate)
+
+cleanup() {
+ rm -f "${perfdata}" "${record_log}" "${report_out}" "${annotate_out}"
+ trap - EXIT TERM INT
+}
+
+trap 'cleanup; exit 1' TERM INT
+trap cleanup EXIT
+
+# mem-loads:pu requests a precise user PEBS event whose sample weight should
+# be populated by -W. Unsupported PEBS/weight PMUs are skipped below.
+if ! perf record -W -e mem-loads:pu -o "${perfdata}" -- perf test -w thloop \
+ > /dev/null 2> "${record_log}"; then
+ echo "[SKIP] precise PEBS weight sampling is unavailable"
+ exit 2
+fi
+
+# Confirm the PMU actually produced nonzero weights. A successful record alone
+# is insufficient: some PMUs accept the event but provide no weight payload.
+if ! perf report --stdio -i "${perfdata}" --fields=weight1,weight2,weight3,symbol --percent-limit 0 \
+ > "${report_out}" 2> "${record_log}"; then
+ echo "[SKIP] weighted samples cannot be decoded"
+ exit 2
+fi
+
+if ! awk '$1 ~ /^[0-9]/ && ($1 + 0) > 0 { found = 1 } END { exit !found }' \
+ "${report_out}"; then
+ echo "[SKIP] PEBS weight sampling produced no nonzero weights"
+ exit 2
+fi
+
+perf annotate --stdio -i "${perfdata}" --symbol "${testsym}" \
+ > "${annotate_out}" 2> "${record_log}"
+
+grep -q 'Percent Weight' "${annotate_out}"
+
+# The second numeric column is the rendered average weight. This assertion
+# fails on the original regression because calc_percent() left it at zero.
+if ! awk '$1 ~ /^[0-9]/ && $2 ~ /^[0-9]/ && ($2 + 0) > 0 { found = 1 } END { exit !found }' \
+ "${annotate_out}"; then
+ echo "Annotation output contained no nonzero weight"
+ cat "${annotate_out}"
+ exit 1
+fi
+
+echo "PEBS annotation weights: PASS"
--
2.55.0
prev parent reply other threads:[~2026-08-13 21:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 21:10 Updated patchkit to show weights in annotation Andi Kleen
2026-08-13 21:10 ` [PATCH v2 1/4] perf tools record: Modernize -W man page Andi Kleen
2026-08-13 21:10 ` [PATCH v2 2/4] perf tools top: Add --weight option Andi Kleen
2026-08-13 21:10 ` [PATCH v2 3/4] perf tools: Add support for displaying weights in annotate Andi Kleen
2026-08-13 21:10 ` Andi Kleen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260813211109.240689-5-ak@linux.intel.com \
--to=ak@linux.intel.com \
--cc=acme@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox