Record a Hack workload with HHVM's jitdump enabled and compare the decode matches the expected order of execution.
Signed-off-by: James Clark james.clark@linaro.org --- tools/perf/tests/shell/coresight/hhvm-jit.sh | 89 ++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
diff --git a/tools/perf/tests/shell/coresight/hhvm-jit.sh b/tools/perf/tests/shell/coresight/hhvm-jit.sh new file mode 100755 index 000000000000..cde8725519e6 --- /dev/null +++ b/tools/perf/tests/shell/coresight/hhvm-jit.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# CoreSight HHVM JIT call stacks (exclusive) +# SPDX-License-Identifier: GPL-2.0 + +set -e +set -o pipefail + +perf list pmu | grep cs_etm > /dev/null || exit 2 +# Require TRBE so that the trace always has virtual timestamps. +if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then + echo "No TRBE sinks, skipping" + exit 2 +fi +command -v hhvm > /dev/null || { echo "SKIP: missing hhvm"; exit 2; } + +tmpdir=$(mktemp -d /tmp/__perf_test.coresight_hhvm_jit.XXXXX) +trap '[ "$?" -eq 0 ] && rm -rf "$tmpdir" || echo "HHVM JIT test files retained in $tmpdir"' EXIT +trap 'exit 1' TERM INT + +# Use the control pipe to only trace the two call stacks rather than all of HHVM's startup. +# Run stacks() twice to test hot and cold versions. +cat > "$tmpdir/hello.hack" << 'EOF' +function command(resource $ctl, resource $ack, string $cmd): void { + \fwrite($ctl, $cmd."\n"); + \fflush($ctl); + // perf writes sizeof("ack\n"), including the trailing NUL. + invariant(\fread($ack, 5) === "ack\n\0", "Missing perf control ack"); +} + +<<__NEVER_INLINE>> +function leaf(string $s): void { + echo $s; +} + +<<__NEVER_INLINE>> +function a2(string $s): void { + leaf($s); +} + +<<__NEVER_INLINE>> +function a1(string $s): void { + a2($s); +} + +<<__NEVER_INLINE>> +function b1(string $s): void { + leaf($s); +} + +<<__NEVER_INLINE>> +function stacks(string $hello, string $world): void { + a1($hello); + b1($world); +} + +<<__EntryPoint>> +function main(): void { + $ctl = \fopen(\getenv("PERF_CTL_FIFO") as string, "w"); + $ack = \fopen(\getenv("PERF_ACK_FIFO") as string, "r"); + command($ctl, $ack, "enable"); + stacks("Hello, ", "world\n"); + stacks("Hello, ", "world\n"); + command($ctl, $ack, "disable"); +} +EOF +mkfifo "$tmpdir/ctl" "$tmpdir/ack" +export PERF_CTL_FIFO="$tmpdir/ctl" PERF_ACK_FIFO="$tmpdir/ack" +export JITDUMP_USE_ARCH_TIMESTAMP=1 + +# HHVM deletes the jitdump on exit unless KeepPerfPidMap is set. +perf record \ + -o "$tmpdir/data" -e cs_etm//u -D -1 -m ,8M \ + --control "fifo:$tmpdir/ctl,$tmpdir/ack" -- \ + hhvm -vEval.PerfJitDump=1 -vEval.PerfJitDumpDir="$tmpdir" \ + -vEval.KeepPerfPidMap=1 "$tmpdir/hello.hack" > "$tmpdir/out" +[ "$(cat "$tmpdir/out")" = "$(printf 'Hello, world\nHello, world')" ] + +perf inject --jit -b \ + -i "$tmpdir/data" -o "$tmpdir/injected.data" + +perf script -i "$tmpdir/injected.data" \ + --itrace=b -F ip,sym > "$tmpdir/script" + +stacks="stacks a1 a2 leaf a2 a1 stacks b1 leaf b1 stacks" +printf '%s\n' main $stacks main $stacks main > "$tmpdir/expected" +sed -nE 's/^.*hello.hack::(main|stacks|a1|a2|b1|leaf)$/\1/p' "$tmpdir/script" | + uniq > "$tmpdir/actual" +diff -u "$tmpdir/expected" "$tmpdir/actual" +echo "HHVM JIT call stacks match the expected sequence"