All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Chaitanya S Prakash <ChaitanyaS.Prakash@arm.com>,
	linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com,
	james.clark@arm.com
Subject: Re: [PATCH V2 8/8] perf test: Check output of the probe ... --funcs command
Date: Wed, 17 Apr 2024 15:26:19 -0300	[thread overview]
Message-ID: <ZiAUSxRYTty5uh6m@x1> (raw)
In-Reply-To: <20240409080902.6f2ccd1239c64ca49861d6d6@kernel.org>

On Tue, Apr 09, 2024 at 08:09:02AM +0900, Masami Hiramatsu wrote:
> On Mon,  8 Apr 2024 11:52:30 +0530
> Chaitanya S Prakash <ChaitanyaS.Prakash@arm.com> wrote:
> 
> > From: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
> > 
> > Test "perf probe of function from different CU" only checks if the perf
> > command has failed and doesn't test the --funcs output. In the issue
> > reported in the previous commit, the garbage output of the --funcs
> > command was being ignored by the test when it could have been caught.
> > 
> > An additional check to grep for "foo" has been added to test the --funcs
> > output.
> 
> Looks good to me.
> 
> Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

> > +++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
> > @@ -77,7 +77,7 @@ gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o
> >  gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o
> >  gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o
> >  
> > -perf probe -x ${temp_dir}/testfile --funcs foo
> > +perf probe -x ${temp_dir}/testfile --funcs foo | grep "foo"
> >  perf probe -x ${temp_dir}/testfile foo

Have you tested this?

Because:

root@x1:~# perf probe -x /lib64/libc.so.6 malloc | grep malloc || echo failure
Added new event:
  probe_libc:malloc    (on malloc in /usr/lib64/libc.so.6)

You can now use it in all perf tools, such as:

	perf record -e probe_libc:malloc -aR sleep 1

failure
root@x1:~# perf probe -d *:*
Removed event: probe_libc:malloc
root@x1:~# perf probe -x /lib64/libc.so.6 malloc |& grep malloc || echo failure
  probe_libc:malloc    (on malloc in /usr/lib64/libc.so.6)
	perf record -e probe_libc:malloc -aR sleep 1
root@x1:~#


that plain '| grep "foo"' isn't enough, will always fail, as the output
isn't sent to stdout, but to stderr, so, with your patch:

root@x1:~# perf test different
121: test perf probe of function from different CU                   : FAILED!
root@x1:~# set -o vi
root@x1:~# perf test -v different
121: test perf probe of function from different CU:
--- start ---
test child forked, pid 938178
--- Cleaning up ---
"foo" does not hit any event.
  Error: Failed to delete events.
---- end(-1) ----
121: test perf probe of function from different CU                   : FAILED!
root@x1:~# 


We need to use '|&' to grep in both stdout and stderr, see how 'perf
probe' uses stderr:

root@x1:~# perf probe -d *:*
Removed event: probe_libc:malloc
root@x1:~# perf probe -x /lib64/libc.so.6 malloc > /dev/null
Added new event:
  probe_libc:malloc    (on malloc in /usr/lib64/libc.so.6)

You can now use it in all perf tools, such as:

	perf record -e probe_libc:malloc -aR sleep 1

root@x1:~


Using '|&' to grep:

diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
index 82bc774a078a15d5..af8b1fa639f3daa4 100755
--- a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
+++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
@@ -77,7 +77,7 @@ gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o
 gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o
 gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o
 
-perf probe -x ${temp_dir}/testfile --funcs foo | grep "foo"
+perf probe -x ${temp_dir}/testfile --funcs foo |& grep "foo"
 perf probe -x ${temp_dir}/testfile foo
 
 cleanup
⬢[acme@toolbox perf-tools-next]$

root@x1:~# perf test different
121: test perf probe of function from different CU                   : Ok
root@x1:~# set -o vi
root@x1:~# perf test -v different
121: test perf probe of function from different CU                   : Ok
root@x1:~# perf test -vv different
121: test perf probe of function from different CU:
--- start ---
test child forked, pid 1048947
Added new event:
  probe_testfile:foo   (on foo in /tmp/perf-uprobe-different-cu-sh.5qg9UX2dUJ/testfile)

You can now use it in all perf tools, such as:

	perf record -e probe_testfile:foo -aR sleep 1

--- Cleaning up ---
Removed event: probe_testfile:foo
---- end(0) ----
121: test perf probe of function from different CU                   : Ok
root@x1:~#

I'm amending the patch with this fix.


Thanks,

- Arnaldo

  parent reply	other threads:[~2024-04-17 18:26 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  6:22 [PATCH V2 0/8] perf tools: Fix test "perf probe of function from different CU" Chaitanya S Prakash
2024-04-08  6:22 ` Chaitanya S Prakash
2024-04-08  6:22 ` [PATCH V2 1/8] tools lib: adopt str_has_suffix() from bpftool/gen.c Chaitanya S Prakash
2024-04-08 23:32   ` Masami Hiramatsu
2024-04-11 12:15     ` Chaitanya S Prakash
2024-04-11 15:41       ` Arnaldo Carvalho de Melo
2024-04-08  6:22 ` [PATCH V2 2/8] perf util: Delete ends_with() and replace its use with str_has_suffix() Chaitanya S Prakash
2024-04-08  6:22 ` [PATCH V2 3/8] perf util: Replace an instance of strtailcmp() by str_has_suffix() Chaitanya S Prakash
2024-04-08 23:20   ` Masami Hiramatsu
2024-04-08  6:22 ` [PATCH V2 4/8] tools lib: Adopt str_has_prefix() from kernel Chaitanya S Prakash
2024-04-08 23:33   ` Masami Hiramatsu
2024-04-08  6:22 ` [PATCH V2 5/8] tools: Delete strstarts() and replace its usage with str_has_prefix() Chaitanya S Prakash
2024-04-08  6:22 ` [PATCH V2 6/8] perf tools: Enable configs required for test_uprobe_from_different_cu.sh Chaitanya S Prakash
2024-04-08 23:11   ` Masami Hiramatsu
2024-04-16 21:19     ` Arnaldo Carvalho de Melo
2024-04-08  6:22 ` [PATCH V2 7/8] perf tools: Only treat files as map files when they have the extension .map Chaitanya S Prakash
2024-04-09 10:21   ` James Clark
2024-04-08  6:22 ` [PATCH V2 8/8] perf test: Check output of the probe ... --funcs command Chaitanya S Prakash
2024-04-08 23:09   ` Masami Hiramatsu
2024-04-16 21:22     ` Arnaldo Carvalho de Melo
2024-04-17 18:26     ` Arnaldo Carvalho de Melo [this message]
2024-04-23 11:53       ` Chaitanya S Prakash
2024-04-09  5:32 ` [PATCH V2 0/8] perf tools: Fix test "perf probe of function from different CU" Alexey Dobriyan
2024-04-09  5:32   ` Alexey Dobriyan
2024-04-11 12:10   ` Chaitanya S Prakash
2024-04-11 12:10     ` Chaitanya S Prakash
2024-04-14 11:41     ` Alexey Dobriyan
2024-04-14 11:41       ` Alexey Dobriyan
2024-04-17 13:24       ` James Clark
2024-04-17 13:24         ` James Clark
2024-04-17 13:39         ` Arnaldo Carvalho de Melo
2024-04-17 13:39           ` Arnaldo Carvalho de Melo
2024-04-10  3:34 ` Chaitanya S Prakash
2024-04-10  3:34   ` Chaitanya S Prakash
2024-04-11 18:49 ` Arnaldo Carvalho de Melo
2024-04-11 18:49   ` Arnaldo Carvalho de Melo
  -- strict thread matches above, loose matches on Subject: below --
2024-04-17  4:19 [PATCH V2 5/8] tools: Delete strstarts() and replace its usage with str_has_prefix() kernel test robot
2024-04-18  7:32 ` kernel test robot

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=ZiAUSxRYTty5uh6m@x1 \
    --to=acme@kernel.org \
    --cc=ChaitanyaS.Prakash@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=james.clark@arm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mhiramat@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.