linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Benjamin Peterson <benjamin@engflow.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	"Liang, Kan" <kan.liang@linux.intel.com>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:PERFORMANCE EVENTS SUBSYSTEM"
	<linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH 2/2] perf tests: add test for trace output loss
Date: Thu, 14 Nov 2024 14:43:46 -0300	[thread overview]
Message-ID: <ZzY20vZluj44w1Gt@x1> (raw)
In-Reply-To: <ZzY1bPtoyRH-nRIV@x1>

On Thu, Nov 14, 2024 at 02:37:52PM -0300, Arnaldo Carvalho de Melo wrote:
> On Wed, Nov 06, 2024 at 11:45:18PM +0000, Benjamin Peterson wrote:
> > Add a test that checks that trace output is not lost to races. This is
> > accomplished by tracing the exit_group syscall of "true" multiple times and
> > checking for correct output.
> > 
> > Conveniently, this test also serves as a regression test for 5fb8e56542a3 ("perf
> > trace: avoid garbage when not printing a trace event's arguments") because
> > exit_group triggers the previously buggy printing behavior.
> > 
> > Signed-off-by: Benjamin Peterson <benjamin@engflow.com>
> > ---
> >  tools/perf/tests/shell/trace_exit_race.sh | 31 +++++++++++++++++++++++
> >  1 file changed, 31 insertions(+)
> >  create mode 100755 tools/perf/tests/shell/trace_exit_race.sh
> > 
> > diff --git a/tools/perf/tests/shell/trace_exit_race.sh b/tools/perf/tests/shell/trace_exit_race.sh
> > new file mode 100755
> > index 000000000000..8b70324bc5b4
> > --- /dev/null
> > +++ b/tools/perf/tests/shell/trace_exit_race.sh
> > @@ -0,0 +1,31 @@
> > +#!/bin/sh
> > +# perf trace exit race
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +# Check that the last events of a perf trace'd subprocess are not
> > +# lost. Specifically, trace the exiting syscall of "true" 100 times and ensure
> > +# the output contains 100 correct lines.
> > +
> > +# shellcheck source=lib/probe.sh
> > +. "$(dirname $0)"/lib/probe.sh
> > +
> > +skip_if_no_perf_trace || exit 2
> > +
> > +trace_shutdown_race() {
> > +	for i in $(seq 100); do
> > +		perf trace -e syscalls:sys_enter_exit_group true 2>>$file
> > +	done
> > +	[ $(grep -c -E " +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$" $file) = "100" ]
> > +}
> > +
> > +
> > +file=$(mktemp /tmp/temporary_file.XXXXX)
> > +
> > +# Do not use whatever ~/.perfconfig file, it may change the output
> > +# via trace.{show_timestamp,show_prefix,etc}
> > +export PERF_CONFIG=/dev/null
> > +
> > +trace_shutdown_race
> > +err=$?
> > +rm -f ${file}
> > +exit $err
> > -- 
> 
> Its failing with shellcheck, I'm trying to fix it:
> 
>   CC      /tmp/build/perf-tools-next/builtin-trace.o
>   TEST    /tmp/build/perf-tools-next/tests/shell/trace_exit_race.sh.shellcheck_log
> 
> In tests/shell/trace_exit_race.sh line 15:
> 	for i in $(seq 100); do
>         ^-^ SC2034 (warning): i appears unused. Verify use (or export if used externally).
> 
> 
> In tests/shell/trace_exit_race.sh line 18:
> 	[ $(grep -c -E " +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$" $file) = "100" ]
>           ^-- SC2046 (warning): Quote this to prevent word splitting.
> 
> For more information:
>   https://www.shellcheck.net/wiki/SC2034 -- i appears unused. Verify use (or ...
>   https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
> make[4]: *** [tests/Build:91: /tmp/build/perf-tools-next/tests/shell/trace_exit_race.sh.shellcheck_log] Error 1
> make[3]: *** [/home/acme/git/perf-tools-next/tools/build/Makefile.build:158: tests] Error 2
> make[2]: *** [Makefile.perf:777: /tmp/build/perf-tools-next/perf-test-in.o] Error 2
> make[2]: *** Waiting for unfinished jobs....

I've read the links provided by ShellCheck and folded this to satisfy
it, please consider installing ShellCheck, the perf build process will
use it when avaiable.

- Arnaldo

diff --git a/tools/perf/tests/shell/trace_exit_race.sh b/tools/perf/tests/shell/trace_exit_race.sh
index 8b70324bc5b4fb4c..c37ed6bb9f7e8fab 100755
--- a/tools/perf/tests/shell/trace_exit_race.sh
+++ b/tools/perf/tests/shell/trace_exit_race.sh
@@ -12,10 +12,10 @@
 skip_if_no_perf_trace || exit 2
 
 trace_shutdown_race() {
-	for i in $(seq 100); do
+	for _ in $(seq 100); do
 		perf trace -e syscalls:sys_enter_exit_group true 2>>$file
 	done
-	[ $(grep -c -E " +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$" $file) = "100" ]
+	[ "$(grep -c -E ' +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$' $file)" = "100" ]
 }
 
 

  reply	other threads:[~2024-11-14 17:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06 23:45 [PATCH 1/2] perf trace: do not lose last events in a race Benjamin Peterson
2024-11-06 23:45 ` [PATCH 2/2] perf tests: add test for trace output loss Benjamin Peterson
2024-11-07 22:06   ` Howard Chu
2024-11-07 23:17     ` Benjamin Peterson
2024-11-08 16:20       ` Howard Chu
2024-11-08 16:59         ` Benjamin Peterson
2024-11-14 17:37   ` Arnaldo Carvalho de Melo
2024-11-14 17:43     ` Arnaldo Carvalho de Melo [this message]
2024-11-14 17:44       ` Benjamin Peterson
2024-11-14 20:09         ` Arnaldo Carvalho de Melo
2024-11-14 20:16           ` Howard Chu
2024-11-14 21:03             ` Arnaldo Carvalho de Melo
2024-11-14 20:50           ` Arnaldo Carvalho de Melo
2024-11-07 21:46 ` [PATCH 1/2] perf trace: do not lose last events in a race Howard Chu

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=ZzY20vZluj44w1Gt@x1 \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=benjamin@engflow.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).