All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] perf test: Add test for java symbol
@ 2022-08-06  3:34 Leo Yan
  2022-08-06  3:34 ` [PATCH 1/2] perf subcmd: Set environment variable "PREFIX" Leo Yan
  2022-08-06  3:34 ` [PATCH 2/2] perf test: Introduce script for java symbol testing Leo Yan
  0 siblings, 2 replies; 5+ messages in thread
From: Leo Yan @ 2022-08-06  3:34 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Peter Zijlstra,
	Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, linux-perf-users
  Cc: Leo Yan

This patch set is to add a test for java symbol.

To allow a shell script to know the installed lib path, we need to
export the environment variable "PREFIX" in the C code.  We use the
first patch for this purpose.  The second patch introduces the java
symbol testing.

The test has been verified on my x86_64 machine with mainline kernel.


Leo Yan (2):
  perf subcmd: Set environment variable "PREFIX"
  perf test: Introduce script for java symbol testing

 tools/lib/subcmd/exec-cmd.c                |  3 +
 tools/perf/tests/shell/test_java_symbol.sh | 66 ++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_java_symbol.sh

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] perf subcmd: Set environment variable "PREFIX"
  2022-08-06  3:34 [PATCH 0/2] perf test: Add test for java symbol Leo Yan
@ 2022-08-06  3:34 ` Leo Yan
  2022-08-06  3:34 ` [PATCH 2/2] perf test: Introduce script for java symbol testing Leo Yan
  1 sibling, 0 replies; 5+ messages in thread
From: Leo Yan @ 2022-08-06  3:34 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Peter Zijlstra,
	Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, linux-perf-users
  Cc: Leo Yan

Set environment variable "PREFIX", it will be used by invoked shell
script, e.g. the shell script uses it to find lib paths.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/lib/subcmd/exec-cmd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/lib/subcmd/exec-cmd.c b/tools/lib/subcmd/exec-cmd.c
index 33e94fb83986..5dbea456973e 100644
--- a/tools/lib/subcmd/exec-cmd.c
+++ b/tools/lib/subcmd/exec-cmd.c
@@ -24,6 +24,9 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 	subcmd_config.prefix		= prefix;
 	subcmd_config.exec_path		= exec_path;
 	subcmd_config.exec_path_env	= exec_path_env;
+
+	/* Setup environment variable for invoked shell script. */
+	setenv("PREFIX", prefix, 1);
 }
 
 #define is_dir_sep(c) ((c) == '/')
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] perf test: Introduce script for java symbol testing
  2022-08-06  3:34 [PATCH 0/2] perf test: Add test for java symbol Leo Yan
  2022-08-06  3:34 ` [PATCH 1/2] perf subcmd: Set environment variable "PREFIX" Leo Yan
@ 2022-08-06  3:34 ` Leo Yan
  2022-08-12 19:47   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 5+ messages in thread
From: Leo Yan @ 2022-08-06  3:34 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Peter Zijlstra,
	Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, linux-perf-users
  Cc: Leo Yan

This commit introduces a script for testing java symbols.

The test records for java program, inject samples with JIT samples, then
check specific words "Interpreter" and "jdk.internal" in the report, the
test will pass if these two symbols are detected.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/tests/shell/test_java_symbol.sh | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_java_symbol.sh

diff --git a/tools/perf/tests/shell/test_java_symbol.sh b/tools/perf/tests/shell/test_java_symbol.sh
new file mode 100755
index 000000000000..45d42a9fdca5
--- /dev/null
+++ b/tools/perf/tests/shell/test_java_symbol.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+# Test java symbol
+
+# SPDX-License-Identifier: GPL-2.0
+# Leo Yan <leo.yan@linaro.org>, 2022
+
+PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+PERF_INJ_DATA=$(mktemp /tmp/__perf_test.perf.data.inj.XXXXX)
+
+cleanup_files()
+{
+	echo "Cleaning up files..."
+	rm -f ${PERF_DATA}
+	rm -f ${PERF_INJ_DATA}
+}
+
+trap cleanup_files exit term int
+
+if [ -e "$PWD/tools/perf/libperf-jvmti.so" ]; then
+	LIBJVMTI=$PWD/tools/perf/libperf-jvmti.so
+elif [ -e "$PWD/libperf-jvmti.so" ]; then
+	LIBJVMTI=$PWD/libperf-jvmti.so
+elif [ -e "$PREFIX/lib64/libperf-jvmti.so" ]; then
+	LIBJVMTI=$PREFIX/lib64/libperf-jvmti.so
+elif [ -e "$PREFIX/lib/libperf-jvmti.so" ]; then
+	LIBJVMTI=$PREFIX/lib/libperf-jvmti.so
+else
+	echo "Fail to find libperf-jvmti.so"
+	exit 1
+fi
+
+cat <<EOF | perf record -k 1 -o $PERF_DATA jshell -s -J-agentpath:$LIBJVMTI
+int fib(int x) {
+	return x > 1 ? fib(x - 2) + fib(x - 1) : 1;
+}
+
+int q = 0;
+
+for (int i = 0; i < 10; i++)
+	q += fib(i);
+
+System.out.println(q);
+EOF
+
+if [ $? -ne 0 ]; then
+	echo "Fail to record for java program"
+	exit 1
+fi
+
+if ! perf inject -i $PERF_DATA -o $PERF_INJ_DATA -j; then
+	echo "Fail to inject samples"
+	exit 1
+fi
+
+# Below is an example of the instruction samples reporting:
+#   8.18%  jshell           jitted-50116-29.so    [.] Interpreter
+#   0.75%  Thread-1         jitted-83602-1670.so  [.] jdk.internal.jimage.BasicImageReader.getString(int)
+perf report --stdio -i ${PERF_INJ_DATA} 2>&1 | \
+	egrep " +[0-9]+\.[0-9]+% .* (Interpreter|jdk\.internal).*" > /dev/null 2>&1
+
+if [ $? -ne 0 ]; then
+	echo "Fail to find java symbols"
+	exit 1
+fi
+
+exit 0
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] perf test: Introduce script for java symbol testing
  2022-08-06  3:34 ` [PATCH 2/2] perf test: Introduce script for java symbol testing Leo Yan
@ 2022-08-12 19:47   ` Arnaldo Carvalho de Melo
       [not found]     ` <CAP-5=fUJxMz0C61Y1qwptc+M6rT=J3ztvguB+9bJBaQrYEQZ3w@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-08-12 19:47 UTC (permalink / raw)
  To: Leo Yan
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-kernel,
	linux-perf-users

Em Sat, Aug 06, 2022 at 11:34:34AM +0800, Leo Yan escreveu:
> This commit introduces a script for testing java symbols.
> 
> The test records for java program, inject samples with JIT samples, then
> check specific words "Interpreter" and "jdk.internal" in the report, the
> test will pass if these two symbols are detected.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/tests/shell/test_java_symbol.sh | 66 ++++++++++++++++++++++
>  1 file changed, 66 insertions(+)
>  create mode 100755 tools/perf/tests/shell/test_java_symbol.sh
> 
> diff --git a/tools/perf/tests/shell/test_java_symbol.sh b/tools/perf/tests/shell/test_java_symbol.sh
> new file mode 100755
> index 000000000000..45d42a9fdca5
> --- /dev/null
> +++ b/tools/perf/tests/shell/test_java_symbol.sh
> @@ -0,0 +1,66 @@
> +#!/bin/bash
> +# Test java symbol
> +
> +# SPDX-License-Identifier: GPL-2.0
> +# Leo Yan <leo.yan@linaro.org>, 2022
> +
> +PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +PERF_INJ_DATA=$(mktemp /tmp/__perf_test.perf.data.inj.XXXXX)
> +
> +cleanup_files()
> +{
> +	echo "Cleaning up files..."
> +	rm -f ${PERF_DATA}
> +	rm -f ${PERF_INJ_DATA}
> +}
> +
> +trap cleanup_files exit term int
> +
> +if [ -e "$PWD/tools/perf/libperf-jvmti.so" ]; then
> +	LIBJVMTI=$PWD/tools/perf/libperf-jvmti.so


Will this only work if we do a:

make -C tools/perf

?

> +elif [ -e "$PWD/libperf-jvmti.so" ]; then
> +	LIBJVMTI=$PWD/libperf-jvmti.so
> +elif [ -e "$PREFIX/lib64/libperf-jvmti.so" ]; then
> +	LIBJVMTI=$PREFIX/lib64/libperf-jvmti.so
> +elif [ -e "$PREFIX/lib/libperf-jvmti.so" ]; then
> +	LIBJVMTI=$PREFIX/lib/libperf-jvmti.so
> +else
> +	echo "Fail to find libperf-jvmti.so"
> +	exit 1
> +fi
> +
> +cat <<EOF | perf record -k 1 -o $PERF_DATA jshell -s -J-agentpath:$LIBJVMTI
> +int fib(int x) {
> +	return x > 1 ? fib(x - 2) + fib(x - 1) : 1;
> +}
> +
> +int q = 0;
> +
> +for (int i = 0; i < 10; i++)
> +	q += fib(i);
> +
> +System.out.println(q);
> +EOF
> +
> +if [ $? -ne 0 ]; then
> +	echo "Fail to record for java program"
> +	exit 1
> +fi
> +
> +if ! perf inject -i $PERF_DATA -o $PERF_INJ_DATA -j; then
> +	echo "Fail to inject samples"
> +	exit 1
> +fi
> +
> +# Below is an example of the instruction samples reporting:
> +#   8.18%  jshell           jitted-50116-29.so    [.] Interpreter
> +#   0.75%  Thread-1         jitted-83602-1670.so  [.] jdk.internal.jimage.BasicImageReader.getString(int)
> +perf report --stdio -i ${PERF_INJ_DATA} 2>&1 | \
> +	egrep " +[0-9]+\.[0-9]+% .* (Interpreter|jdk\.internal).*" > /dev/null 2>&1
> +
> +if [ $? -ne 0 ]; then
> +	echo "Fail to find java symbols"
> +	exit 1
> +fi
> +
> +exit 0
> -- 
> 2.25.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] perf test: Introduce script for java symbol testing
       [not found]     ` <CAP-5=fUJxMz0C61Y1qwptc+M6rT=J3ztvguB+9bJBaQrYEQZ3w@mail.gmail.com>
@ 2022-08-13  3:08       ` Leo Yan
  0 siblings, 0 replies; 5+ messages in thread
From: Leo Yan @ 2022-08-13  3:08 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-kernel, linux-perf-users

On Fri, Aug 12, 2022 at 02:08:43PM -0700, Ian Rogers wrote:

[...]

> > > +if [ -e "$PWD/tools/perf/libperf-jvmti.so" ]; then
> > > +     LIBJVMTI=$PWD/tools/perf/libperf-jvmti.so
> >
> >
> > Will this only work if we do a:
> >
> > make -C tools/perf

Yes, I think so.

> >
> > ?
> 
> Perhaps, I'm not sure on the correct way to detect the install location.
> The only similar example I know of is:
> https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/tests/builtin-test.c?h=perf/core#n308

Yes, I refered the code in this link.

If user works under Linux source folder, the test will search lib in
the folder $LINUX or $LINUX/tools/perf; and it searchs the installed
libperf-jvmti.so in the folder "$PREFIX/lib64" or "$PREFIX/lib".

I think I can add a more path for searching system lib (e.g. the
libperf-jvmti.so is under /usr/lib/linux-tools-xxx/):

  elif [ -e "/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so" ]; then
       LIBJVMTI= /usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so

> > +elif [ -e "$PWD/libperf-jvmti.so" ]; then
> > > +     LIBJVMTI=$PWD/libperf-jvmti.so
> > > +elif [ -e "$PREFIX/lib64/libperf-jvmti.so" ]; then
> > > +     LIBJVMTI=$PREFIX/lib64/libperf-jvmti.so
> > > +elif [ -e "$PREFIX/lib/libperf-jvmti.so" ]; then
> > > +     LIBJVMTI=$PREFIX/lib/libperf-jvmti.so
> > > +else
> > > +     echo "Fail to find libperf-jvmti.so"
> > > +     exit 1
> >
> 
> JVMTI is a build option so this should probably be "exit 2" for skip.

Sure, will fix.

Thanks,
Leo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-13  3:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-06  3:34 [PATCH 0/2] perf test: Add test for java symbol Leo Yan
2022-08-06  3:34 ` [PATCH 1/2] perf subcmd: Set environment variable "PREFIX" Leo Yan
2022-08-06  3:34 ` [PATCH 2/2] perf test: Introduce script for java symbol testing Leo Yan
2022-08-12 19:47   ` Arnaldo Carvalho de Melo
     [not found]     ` <CAP-5=fUJxMz0C61Y1qwptc+M6rT=J3ztvguB+9bJBaQrYEQZ3w@mail.gmail.com>
2022-08-13  3:08       ` Leo Yan

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.