11#! /bin/sh
2- # Install reli (needs PHP 8.4+) in this image and analyse a pre-made dump at
3- # $IN_DUMP -- which may have been produced by ext-rdump on an older PHP. Proves
4- # current reli can inspect/analyze a cross-version RDUMP file.
2+ # Install reli (needs PHP 8.4+) once, then analyse every dump in $IN_DIR. The
3+ # dumps may have been produced by ext-rdump on older PHP versions; this proves
4+ # current reli can inspect/analyze cross-version RDUMP files. Setting reli up
5+ # (FFI build + composer) is the fixed cost, so it's paid once and amortised over
6+ # all dumps rather than per dump.
57#
6- # docker run --rm -e IN_DUMP =/in/d.rdump -e TAG=v74 -v "$PWD/reli ":/reli \
7- # -v "$PWD/out":/in - w /reli php:8.4-cli sh ci/reli-analyze.sh
8- set -eux
8+ # docker run --rm -e IN_DIR =/in -v "$PWD/reli":/reli -v "$PWD/out ":/in \
9+ # -w /reli php:8.4-cli sh /ext/ ci/reli-analyze.sh
10+ set -eu
911
10- : " ${IN_DUMP:? set IN_DUMP to the dump file to analyse} "
11- test -s " $IN_DUMP "
12+ : " ${IN_DIR:? set IN_DIR to the directory of dumps to analyse} "
1213
1314apt-get update
1415apt-get install -y --no-install-recommends git unzip libffi-dev
@@ -20,29 +21,51 @@ rm -f /tmp/composer-setup.php
2021
2122composer install --no-interaction --no-progress
2223
23- # The dump records its origin PHP version (e.g. v70/v74); reli reads that from
24- # the header, so no --php-version override is needed for a file dump.
25- INSPECT=" $( php -d ffi.enable=1 reli inspector:memory:dump:inspect " $IN_DUMP " ) "
26- echo " $INSPECT " | head -20
27- echo " $INSPECT " | grep -q ' Magic:.*RDUMP' || { echo ' ::error::reli did not recognise the RDUMP magic' ; exit 1; }
28- echo " $INSPECT " | grep -q ' Format Version:.*3' || { echo ' ::error::unexpected format version' ; exit 1; }
29- if [ -n " ${TAG:- } " ]; then
30- echo " $INSPECT " | grep -qi " PHP Version:.*$TAG " \
31- || { echo " ::error::dump did not report origin PHP $TAG " ; exit 1; }
32- fi
24+ analyze_one () {
25+ dump=" $1 "
26+ # Derive the expected origin tag from the filename (php7.0-cli.rdump -> v70).
27+ tag=" v$( basename " $dump " | sed -E ' s/^php([0-9])\.([0-9]).*/\1\2/' ) "
28+ echo " ::group::analyze $( basename " $dump " ) (origin $tag )"
29+ test -s " $dump " || { echo " ::error::missing/empty dump $dump " ; return 1; }
30+
31+ # The dump records its origin PHP version in the header, so no
32+ # --php-version override is needed for a file dump.
33+ inspect=" $( php -d ffi.enable=1 reli inspector:memory:dump:inspect " $dump " ) "
34+ echo " $inspect " | head -20
35+ echo " $inspect " | grep -q ' Magic:.*RDUMP' || { echo " ::error::$dump : no RDUMP magic" ; return 1; }
36+ echo " $inspect " | grep -q ' Format Version:.*3' || { echo " ::error::$dump : unexpected format version" ; return 1; }
37+ echo " $inspect " | grep -qi " PHP Version:.*$tag " || { echo " ::error::$dump : origin not $tag " ; return 1; }
38+
39+ if php -d ffi.enable=1 reli inspector:memory:analyze " $dump " -f report \
40+ > /tmp/reli-analyze.log 2>&1 ; then
41+ head -20 /tmp/reli-analyze.log
42+ else
43+ echo " ::error::$dump : reli analyze exited non-zero; full output:"
44+ cat /tmp/reli-analyze.log
45+ return 1
46+ fi
47+ grep -q ' Memory Analysis Report' /tmp/reli-analyze.log || {
48+ echo " ::error::$dump : no report produced; full output:"
49+ cat /tmp/reli-analyze.log
50+ return 1
51+ }
52+ echo " OK: $( basename " $dump " ) "
53+ echo " ::endgroup::"
54+ }
3355
34- if php -d ffi.enable=1 reli inspector:memory:analyze " $IN_DUMP " -f report \
35- > /tmp/reli-analyze.log 2>&1 ; then
36- head -30 /tmp/reli-analyze.log
37- else
38- echo ' ::error::reli analyze exited non-zero; full output:'
39- cat /tmp/reli-analyze.log
56+ rc=0
57+ n=0
58+ for d in " $IN_DIR " /* .rdump; do
59+ n=$(( n + 1 ))
60+ analyze_one " $d " || rc=1
61+ done
62+
63+ if [ " $n " -eq 0 ]; then
64+ echo " ::error::no dumps found in $IN_DIR "
4065 exit 1
4166fi
42- grep -q ' Memory Analysis Report' /tmp/reli-analyze.log || {
43- echo ' ::error::reli analyze produced no report; full output:'
44- cat /tmp/reli-analyze.log
67+ if [ " $rc " -ne 0 ]; then
68+ echo " ::error::one or more cross-version dumps failed to analyse"
4569 exit 1
46- }
47-
48- echo " reli cross-version analyze OK (dump=$IN_DUMP tag=${TAG:- n/ a} )"
70+ fi
71+ echo " reli cross-version analyze OK ($n dumps)"
0 commit comments