perf test: Add test for java symbol
v2 cover perf test: Add test for java symbol
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 x86_64 machine with mainline kernel, with the latest commit 62e64c9d2fd1 ("perf test: Add basic core_wide expression test").
Changes from v1:
- Added Ian's suggested tag;
- Added the search folder for the system lib libperf-jvmti.so;
- Skip the test if fail to find jvmti lib.
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 | 69 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 tools/perf/tests/shell/test_java_symbol.sh
Signature · 1 line
2.34.1
PATCH v2 1/2 perf subcmd: Set environment variable "PREFIX"
Set environment variable "PREFIX", it will be used by invoked shell script, e.g. the shell script uses it to find lib paths.
--- tools/lib/subcmd/exec-cmd.c | 3 +++ 1 file changed, 3 insertions(+)
tools/lib/subcmd/exec-cmd.c +3 -0
@@ -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) == '/')
Signature · 1 line
2.34.1
PATCH v2 2/2 perf test: Introduce script for java symbol testing
In reply to Leo YanThis commit introduces a script for testing java symbols.
The test records java program, inject samples with JIT samples, check specific JIT symbols in the report, the test will pass only when these two symbols are detected.
--- tools/perf/tests/shell/test_java_symbol.sh | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 tools/perf/tests/shell/test_java_symbol.sh
tools/perf/tests/shell/test_java_symbol.sh new file +69 -0
@@ -0,0 +1,69 @@ +#!/bin/bash +# Test java symbol + +# SPDX-License-Identifier: GPL-2.0 +# Leo Yan <[email protected]>, 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 +if [ -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 +else + echo "Fail to find libperf-jvmti.so" + # JVMTI is a build option, skip the test if fail to find lib + exit 2 +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
Signature · 1 line
2.34.1
Namhyung Kim
maintainerRe: [PATCH v2 2/2] perf test: Introduce script for java symbol testing
Hi Leo,
Quoted 37 lines · Leo Yan
This commit introduces a script for testing java symbols.
The test records java program, inject samples with JIT samples, check specific JIT symbols in the report, the test will pass only when these two symbols are detected.
Suggested-by Ian Rogers <[email protected]>Signed-off-by Leo Yan <[email protected]>--- tools/perf/tests/shell/test_java_symbol.sh | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 tools/perf/tests/shell/test_java_symbol.shtools/perf/tests/shell/test_java_symbol.sh new file +17
-0@@ -0,0 +1,69 @@ +#!/bin/bash +# Test java symbol + +# SPDX-License-Identifier: GPL-2.0 +# Leo Yan <[email protected]>, 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
tools/perf/tests/shell/test_java_symbol.sh line 27
Quoted 10 lines
tools/perf/tests/shell/test_java_symbol.sh new file +10
-0+ +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 +if [ -e "/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so" ]; then
s/if/elif/ ?
tools/perf/tests/shell/test_java_symbol.sh line 35
Quoted 8 lines
tools/perf/tests/shell/test_java_symbol.sh new file +8
-0+ LIBJVMTI=/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so +else + echo "Fail to find libperf-jvmti.so" + # JVMTI is a build option, skip the test if fail to find lib + exit 2 +fi + +cat <<EOF | perf record -k 1 -o $PERF_DATA jshell -s -J-agentpath:$LIBJVMTI
Wouldn't it check if jshell is available first?
Thanks,
Namhyung
Quoted 37 lines
tools/perf/tests/shell/test_java_symbol.sh new file +34
-1+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.34.1
Re: [PATCH v2 2/2] perf test: Introduce script for java symbol testing
Hi Namhyung,
On Tue, Sep 20, 2022 at 02:47:05PM -0700, Namhyung Kim wrote:
[...]
Quoted 11 lines
tools/perf/tests/shell/test_java_symbol.sh line 27
Quoted 9 lines
tools/perf/tests/shell/test_java_symbol.sh new file +9
-0+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 +if [ -e "/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so" ]; thens/if/elif/ ?
Ouch, will fix.
Quoted 10 lines
tools/perf/tests/shell/test_java_symbol.sh line 35
Quoted 8 lines
tools/perf/tests/shell/test_java_symbol.sh new file +8
-0+ LIBJVMTI=/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so +else + echo "Fail to find libperf-jvmti.so" + # JVMTI is a build option, skip the test if fail to find lib + exit 2 +fi + +cat <<EOF | perf record -k 1 -o $PERF_DATA jshell -s -J-agentpath:$LIBJVMTIWouldn't it check if jshell is available first?
Indeed. Will check jshell and skip the testing if jshell doesn't exist.
Thanks for reviewing.
Leo