11dc86fc7SLeo Yan#!/bin/bash 21dc86fc7SLeo Yan# Test java symbol 31dc86fc7SLeo Yan 41dc86fc7SLeo Yan# SPDX-License-Identifier: GPL-2.0 51dc86fc7SLeo Yan# Leo Yan <leo.yan@linaro.org>, 2022 61dc86fc7SLeo Yan 71dc86fc7SLeo Yan# skip if there's no jshell 81dc86fc7SLeo Yanif ! [ -x "$(command -v jshell)" ]; then 91dc86fc7SLeo Yan echo "skip: no jshell, install JDK" 101dc86fc7SLeo Yan exit 2 111dc86fc7SLeo Yanfi 121dc86fc7SLeo Yan 131dc86fc7SLeo YanPERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX) 141dc86fc7SLeo YanPERF_INJ_DATA=$(mktemp /tmp/__perf_test.perf.data.inj.XXXXX) 151dc86fc7SLeo Yan 161dc86fc7SLeo Yancleanup_files() 171dc86fc7SLeo Yan{ 181dc86fc7SLeo Yan echo "Cleaning up files..." 191dc86fc7SLeo Yan rm -f ${PERF_DATA} 201dc86fc7SLeo Yan rm -f ${PERF_INJ_DATA} 211dc86fc7SLeo Yan} 221dc86fc7SLeo Yan 231dc86fc7SLeo Yantrap cleanup_files exit term int 241dc86fc7SLeo Yan 251dc86fc7SLeo Yanif [ -e "$PWD/tools/perf/libperf-jvmti.so" ]; then 261dc86fc7SLeo Yan LIBJVMTI=$PWD/tools/perf/libperf-jvmti.so 271dc86fc7SLeo Yanelif [ -e "$PWD/libperf-jvmti.so" ]; then 281dc86fc7SLeo Yan LIBJVMTI=$PWD/libperf-jvmti.so 291dc86fc7SLeo Yanelif [ -e "$PREFIX/lib64/libperf-jvmti.so" ]; then 301dc86fc7SLeo Yan LIBJVMTI=$PREFIX/lib64/libperf-jvmti.so 311dc86fc7SLeo Yanelif [ -e "$PREFIX/lib/libperf-jvmti.so" ]; then 321dc86fc7SLeo Yan LIBJVMTI=$PREFIX/lib/libperf-jvmti.so 331dc86fc7SLeo Yanelif [ -e "/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so" ]; then 341dc86fc7SLeo Yan LIBJVMTI=/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so 351dc86fc7SLeo Yanelse 361dc86fc7SLeo Yan echo "Fail to find libperf-jvmti.so" 371dc86fc7SLeo Yan # JVMTI is a build option, skip the test if fail to find lib 381dc86fc7SLeo Yan exit 2 391dc86fc7SLeo Yanfi 401dc86fc7SLeo Yan 411dc86fc7SLeo Yancat <<EOF | perf record -k 1 -o $PERF_DATA jshell -s -J-agentpath:$LIBJVMTI 421dc86fc7SLeo Yanint fib(int x) { 431dc86fc7SLeo Yan return x > 1 ? fib(x - 2) + fib(x - 1) : 1; 441dc86fc7SLeo Yan} 451dc86fc7SLeo Yan 461dc86fc7SLeo Yanint q = 0; 471dc86fc7SLeo Yan 481dc86fc7SLeo Yanfor (int i = 0; i < 10; i++) 491dc86fc7SLeo Yan q += fib(i); 501dc86fc7SLeo Yan 511dc86fc7SLeo YanSystem.out.println(q); 521dc86fc7SLeo YanEOF 531dc86fc7SLeo Yan 541dc86fc7SLeo Yanif [ $? -ne 0 ]; then 551dc86fc7SLeo Yan echo "Fail to record for java program" 561dc86fc7SLeo Yan exit 1 571dc86fc7SLeo Yanfi 581dc86fc7SLeo Yan 59*5f0b89e6SThomas Richterif ! DEBUGINFOD_URLS='' perf inject -i $PERF_DATA -o $PERF_INJ_DATA -j; then 601dc86fc7SLeo Yan echo "Fail to inject samples" 611dc86fc7SLeo Yan exit 1 621dc86fc7SLeo Yanfi 631dc86fc7SLeo Yan 641dc86fc7SLeo Yan# Below is an example of the instruction samples reporting: 651dc86fc7SLeo Yan# 8.18% jshell jitted-50116-29.so [.] Interpreter 661dc86fc7SLeo Yan# 0.75% Thread-1 jitted-83602-1670.so [.] jdk.internal.jimage.BasicImageReader.getString(int) 671dc86fc7SLeo Yanperf report --stdio -i ${PERF_INJ_DATA} 2>&1 | \ 68818448e9STiezhu Yang grep -E " +[0-9]+\.[0-9]+% .* (Interpreter|jdk\.internal).*" > /dev/null 2>&1 691dc86fc7SLeo Yan 701dc86fc7SLeo Yanif [ $? -ne 0 ]; then 711dc86fc7SLeo Yan echo "Fail to find java symbols" 721dc86fc7SLeo Yan exit 1 731dc86fc7SLeo Yanfi 741dc86fc7SLeo Yan 751dc86fc7SLeo Yanexit 0 76