All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Guilherme Amadio <amadio@gentoo.org>,
	acme@kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: perf test for inet_pton probe fails to match stacktrace
Date: Tue, 26 Nov 2024 10:27:05 +0000	[thread overview]
Message-ID: <20241126102705.GA15252@e132581.arm.com> (raw)
In-Reply-To: <Z0VXvySyHm4q4r2c@google.com>

On Mon, Nov 25, 2024 at 09:08:15PM -0800, Namhyung Kim wrote:

[...]

> > Using nm $libc in both cases, and increasing max-stack to 4 allows the test to pass:
> >
> > $ sudo ./perf test -vF pton
> > --- start ---
> > ping 1237113 [000] 18561.204983: probe_libc:inet_pton: (7f7c34d38eb7)
> > 7f7c34d38eb7 __GI___inet_pton+0x0 (/usr/lib64/libc.so.6)
> > 7f7c34d4b517 gaih_inet+0x112 (/usr/lib64/libc.so.6)
> > 7f7c34d4cb73 getaddrinfo+0x133 (/usr/lib64/libc.so.6)
> > 55680ac46518 [unknown] (/usr/bin/ping)
> > ---- end ----
> >  86: probe libc's inet_pton & backtrace it with ping                 : Ok
> 
> I think it's very fragile as it depends on specific entries in the call
> stack.  As we want to test if perf probe (for uprobes) and perf record
> working correctly, maybe it can just check the number of samples only.
> 
> Arnaldo, what do you think?

Though this question is asking Arnaldo, I have a different idea for
fixing the test ;)

The middle entries in the callchain are varied on different archs and
distro.  E.g. Guilherme reported back the '-D' option is not needed but
at my side it is required on Arm64 machine with Ubuntu distro.

However, the three entries in the callchain are existed consistently:

  ping 1237113 [000] 18561.204983: probe_libc:inet_pton: (7f7c34d38eb7)
  7f7c34d38eb7 __GI___inet_pton+0x0 (/usr/lib64/libc.so.6)
  ...
  55680ac46518 [unknown] (/usr/bin/ping)

We can change the code to only matching these three entries.  The
change is as below.  We can consolidate the code for all archs
(I am not 100% sure for x390x so I leave it).

Please let me know if this makes sense for you?

Thanks,
Leo

---8<---

diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
index 47a26f25db9f..6ef58aedf2d8 100755
--- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
@@ -43,17 +43,8 @@ trace_libc_inet_pton_backtrace() {
 		echo "((__GI_)?getaddrinfo|text_to_binary_address)\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
 		echo "(gaih_inet|main)\+0x[[:xdigit:]]+[[:space:]]\(inlined|.*/bin/ping.*\)$" >> $expected
 		;;
-	ppc64|ppc64le)
-		eventattr='max-stack=4'
-		# Add gaih_inet to expected backtrace only if it is part of libc.
-		if nm $libc | grep -F -q gaih_inet.; then
-			echo "gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
-		fi
-		echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
-		echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected
-		;;
 	*)
-		eventattr='max-stack=3'
+		eventattr='max-stack=4'
 		echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected
 		;;
 	esac
@@ -76,14 +67,23 @@ trace_libc_inet_pton_backtrace() {
 	fi
 	perf script -i $perf_data | tac | grep -m1 ^ping -B9 | tac > $perf_script
 
-	exec 3<$perf_script
 	exec 4<$expected
-	while read line <&3 && read -r pattern <&4; do
+	while read -r pattern <&4; do
+		echo "pattern: $pattern"
 		[ -z "$pattern" ] && break
-		echo $line
-		echo "$line" | grep -E -q "$pattern"
-		if [ $? -ne 0 ] ; then
-			printf "FAIL: expected backtrace entry \"%s\" got \"%s\"\n" "$pattern" "$line"
+
+		exec 3<$perf_script
+		while read line <&3; do
+			[ -z "$line" ] && break
+			echo "line: $line"
+			echo "$line" | grep -E -q "$pattern"
+			found=$?
+			echo "found=$found"
+			[ $found -eq 0 ] && break
+		done
+
+		if [ $found -ne 0 ] ; then
+			printf "FAIL: unfound the expected backtrace entry \"%s\"\n" "$pattern"
 			return 1
 		fi
 	done

  reply	other threads:[~2024-11-26 10:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-22 21:35 perf test for inet_pton probe fails to match stacktrace Guilherme Amadio
2024-11-24 10:50 ` Leo Yan
2024-11-25 13:12   ` Guilherme Amadio
2024-11-26  5:08     ` Namhyung Kim
2024-11-26 10:27       ` Leo Yan [this message]
2024-11-26 16:39         ` Arnaldo Carvalho de Melo
2024-11-26 18:27           ` Leo Yan
2024-11-26 16:27       ` Arnaldo Carvalho de Melo

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=20241126102705.GA15252@e132581.arm.com \
    --to=leo.yan@arm.com \
    --cc=acme@kernel.org \
    --cc=amadio@gentoo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.