Skip to contentSkip to conversation

perf test: Replace grep perl regexp with awk

PATCH Applied Chun-Tse Shao 3 participants 4 messages Jun 20, 2025 – Jun 25, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf test: Replace grep perl regexp with awk

perl is not universal on all machines and should be replaced with awk, which is much more common.

Before:

  $ perf test "probe libc's inet_pton & backtrace it with ping" -v
  --- start ---
  test child forked, pid 145431
  grep: Perl matching not supported in a --disable-perl-regexp build

FAIL: could not add event
---- end(-1) ----
121: probe libc's inet_pton & backtrace it with ping : FAILED!
After:

  $ perf test "probe libc's inet_pton & backtrace it with ping" -v
  121: probe libc's inet_pton & backtrace it with ping                 : Ok
---
 tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/record+probe_libc_inet_pton.sh +2 -1
index c4bab5b5cc59..aaa5ee06ae18 100755
@@ -23,7 +23,8 @@ event_pattern='probe_libc:inet_pton(\_[[:digit:]]+)?'
 add_libc_inet_pton_event() {
 
 	event_name=$(perf probe -f -x $libc -a inet_pton 2>&1 | tail -n +2 | head -n -5 | \
-			grep -P -o "$event_pattern(?=[[:space:]]\(on inet_pton in $libc\))")
+			awk -v ep="$event_pattern" -v l="$libc" '$0 ~ ep && $0 ~ \
+			("\\(on inet_pton in " l "\\)") {print $1}')
 
 	if [ $? -ne 0 ] || [ -z "$event_name" ] ; then
 		printf "FAIL: could not add event\n"

--
2.50.0.rc2.701.gf1e915cc24-goog

reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Chun-Tse Shao

perl is not universal on all machines and should be replaced with awk, which is much more common.

Before:

   $ perf test "probe libc's inet_pton & backtrace it with ping" -v
   --- start ---
   test child forked, pid 145431
   grep: Perl matching not supported in a --disable-perl-regexp build

FAIL: could not add event
---- end(-1) ----
121: probe libc's inet_pton & backtrace it with ping : FAILED!
After:

   $ perf test "probe libc's inet_pton & backtrace it with ping" -v
   121: probe libc's inet_pton & backtrace it with ping                 : Ok
---
  tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/record+probe_libc_inet_pton.sh +2 -2
index c4bab5b5cc59..aaa5ee06ae18 100755
@@ -23,7 +23,8 @@ event_pattern='probe_libc:inet_pton(\_[[:digit:]]+)?'
  add_libc_inet_pton_event() {
 
  	event_name=$(perf probe -f -x $libc -a inet_pton 2>&1 | tail -n +2 | head -n -5 | \
-			grep -P -o "$event_pattern(?=[[:space:]]\(on inet_pton in $libc\))")
+			awk -v ep="$event_pattern" -v l="$libc" '$0 ~ ep && $0 ~ \
+			("\\(on inet_pton in " l "\\)") {print $1}')
 
  	if [ $? -ne 0 ] || [ -z "$event_name" ] ; then
  		printf "FAIL: could not add event\n"
--
Quoted 2 lines

2.50.0.rc2.701.gf1e915cc24-goog

Minor nit: the underscore in event_pattern (not shown in the diff) never needed to be escaped.

But now we're using awk it gives a warning so we should remove it in case anyone is searching through the output:

awk: warning: escape sequence \_' treated as plain _'

maintainer
#2 lore raw

Hello,

Quoted 46 lines · James Clark
Quoted 37 lines · Chun-Tse Shao

perl is not universal on all machines and should be replaced with awk, which is much more common.

Before:

   $ perf test "probe libc's inet_pton & backtrace it with ping" -v
   --- start ---
   test child forked, pid 145431
   grep: Perl matching not supported in a --disable-perl-regexp build

FAIL: could not add event
---- end(-1) ----
121: probe libc's inet_pton & backtrace it with ping : FAILED!
After:

   $ perf test "probe libc's inet_pton & backtrace it with ping" -v
   121: probe libc's inet_pton & backtrace it with ping                 : Ok
---
  tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/record+probe_libc_inet_pton.sh +2 -2
index c4bab5b5cc59..aaa5ee06ae18 100755
@@ -23,7 +23,8 @@ event_pattern='probe_libc:inet_pton(\_[[:digit:]]+)?'
  add_libc_inet_pton_event() {
 
  	event_name=$(perf probe -f -x $libc -a inet_pton 2>&1 | tail -n +2 | head -n -5 | \
-			grep -P -o "$event_pattern(?=[[:space:]]\(on inet_pton in $libc\))")
+			awk -v ep="$event_pattern" -v l="$libc" '$0 ~ ep && $0 ~ \
+			("\\(on inet_pton in " l "\\)") {print $1}')
 
  	if [ $? -ne 0 ] || [ -z "$event_name" ] ; then
  		printf "FAIL: could not add event\n"
--
Quoted 2 lines

2.50.0.rc2.701.gf1e915cc24-goog

Minor nit: the underscore in event_pattern (not shown in the diff) never needed to be escaped.

Quoted 6 lines

But now we're using awk it gives a warning so we should remove it in case anyone is searching through the output:

awk: warning: escape sequence \_' treated as plain _'

Thanks for your review. I'll fold the below change.

---8<---

tools/perf/tests/shell/record+probe_libc_inet_pton.sh +1 -1
index aaa5ee06ae1833de..9bdf47aabe9d738b 100755
@@ -18,7 +18,7 @@
 libc=$(grep -w libc /proc/self/maps | head -1 | sed -r 's/.*[[:space:]](\/.*)/\1/g')
 nm -Dg $libc 2>/dev/null | grep -F -q inet_pton || exit 254
 
-event_pattern='probe_libc:inet_pton(\_[[:digit:]]+)?'
+event_pattern='probe_libc:inet_pton(_[[:digit:]]+)?'
 
 add_libc_inet_pton_event() {
 
maintainer Applied
#3 lore raw
In reply to Chun-Tse Shao
Quoted 10 lines · Chun-Tse Shao

perl is not universal on all machines and should be replaced with awk, which is much more common.

Before:

  $ perf test "probe libc's inet_pton & backtrace it with ping" -v
  --- start ---
  test child forked, pid 145431
  grep: Perl matching not supported in a --disable-perl-regexp build

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung