From cbd7c5cbd064702616fa230b5d70e1c60a34f294 Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:03:48 +0100 Subject: [PATCH] instrumentation: fail a build, an asset or the gate that ships without the log The CMF's deployed libvkbridge_server.so (v0.5.5.3) has neither VKBRIDGE_LATLOG nor VKBRIDGE_STATS in its string tables, so the knobs did nothing and no per-frame log existed: the one instrument that would say what the rest of a 31.8 ms frame was doing was not on the device (fence wait 2.60 ms, render_scene 3.39 ms, acquire 0.13, present 0.44 - 8.2 % + 10.7 % of the frame; the other ~24 ms unknown). Both diagnostics are compiled in unconditionally (server/server_latency.c, client/latency.c, server/server_conn.c, client/conn.c) and both build scripts compile the whole source directory, so the absence came from a binary built elsewhere (an older checkout, or package-droiddeck-asset.sh's [source-dir]). Nothing checked, so nothing failed. scripts/check-instrumentation.sh reads an ELF's string tables and fails when VKBRIDGE_LATLOG or VKBRIDGE_STATS is missing; --server also demands the latency log's own header line, so a table naming the switch cannot pass for the log. Wired into build-server-android.sh (after strip, on both server outputs), check-droiddeck-asset.sh (on the asset's server, jni and ICD) and run_tests.sh ("instrumentation", so the host gate has it too). The literals survive --strip-unneeded and llvm-strip. Tested: --server on a fresh NDK build (libvkbridge_server.so, libvkbridge_jni.so) and on host/out/vkbridge-server -> ok; on host/out/libvulkan_droidbridge.so -> ok; on a library without them (host/out/libvkb_mali_profile.so) -> FAIL as intended. --- host/run_tests.sh | 9 ++++++++- scripts/build-server-android.sh | 3 +++ scripts/check-droiddeck-asset.sh | 8 +++++++- scripts/check-instrumentation.sh | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100755 scripts/check-instrumentation.sh diff --git a/host/run_tests.sh b/host/run_tests.sh index 09e4792..4765161 100755 --- a/host/run_tests.sh +++ b/host/run_tests.sh @@ -26,7 +26,7 @@ featclamp envfile unflagged eventstatus query querystuck gsexport dmabufsize dsh submitfail waitlost apicap ycbcr_swap driverid vidyn eds compilegate sparse a1zink envswitch poolfull heapleak lowmem exitheap xclipse_zink syncfd dmabufsync timeline imageless dabreg dmabufahb xfb xfb_nofold hotpath wire poll reqcache syncmirror stale_frames bcn_budget bcn_mixcopy hitch bcauto bcbudget bcupload latency lagprobe framequeue -presentwait present_block compileburst querystuck_burst describe dmaheap" +presentwait present_block compileburst querystuck_burst describe dmaheap instrumentation" if [ "${1:-}" = --list ]; then printf '%s\n' $VKB_TEST_NAMES exit 0 @@ -689,6 +689,13 @@ run_mode() { if want server_hup; then timeout 60 ./server_hup_test.sh >out/t-hup.log 2>&1; result $? "server_hup_test ($(tail -1 out/t-hup.log))" fi + # The per-frame instrumentation is in the binaries this checkout builds (VKBRIDGE_LATLOG, + # VKBRIDGE_STATS; scripts/check-instrumentation.sh, which the Android build and the asset check + # also run): a build that lost it cannot answer "where did the frame go" + if want instrumentation; then + timeout 60 ../scripts/check-instrumentation.sh --server out/vkbridge-server >out/t-instr.log 2>&1 && + timeout 60 ../scripts/check-instrumentation.sh out/libvulkan_droidbridge.so >>out/t-instr.log 2>&1; result $? "instrumentation ($(tail -1 out/t-instr.log))" + fi # A driver crash's line names the client, the bind's image and memory, a draw's bound pipeline if want crashline; then timeout 200 ./crashline_test.sh >out/t-crashline.log 2>&1; result $? "crashline_test ($(tail -1 out/t-crashline.log))" diff --git a/scripts/build-server-android.sh b/scripts/build-server-android.sh index c0f0429..87c32b5 100755 --- a/scripts/build-server-android.sh +++ b/scripts/build-server-android.sh @@ -32,4 +32,7 @@ git=$(git -C "$root" describe --tags --match 'v[0-9]*' --always --dirty 2>/dev/n "$srv"/*.c "$root/common/vkb_wire.c" "$root/common/vkb_caps.c" "$root/common/gen/vkb_gen_structs.c" "$root/common/gen/vkb_gen_server.c" \ -ldl -llog -lm "$(dirname "$cc")/llvm-strip" --strip-unneeded "$out/libvkbridge_jni.so" +# The per-frame instrumentation (VKBRIDGE_LATLOG, VKBRIDGE_STATS) is what a "where did the frame go" +# answer is made of; a checkout that lost it must not ship quietly. +"$root/scripts/check-instrumentation.sh" --server "$out/libvkbridge_server.so" "$out/libvkbridge_jni.so" echo "built $out/libvkbridge_server.so and libvkbridge_jni.so" diff --git a/scripts/check-droiddeck-asset.sh b/scripts/check-droiddeck-asset.sh index c2cc2ad..536831c 100755 --- a/scripts/check-droiddeck-asset.sh +++ b/scripts/check-droiddeck-asset.sh @@ -62,4 +62,10 @@ for f in android/arm64-v8a/libvkbridge_server.so android/arm64-v8a/libvkbridge_j readelf -h "$f" | grep -q 'Machine:.*AArch64' || fail "$f is not aarch64" done readelf -d android/arm64-v8a/libvkbridge_jni.so | grep -q 'SONAME.*libvkbridge_jni.so' || fail "jni soname" -echo "elf ok: ICD GLIBC_$g, self-test GLIBC_$s, 3 vk_icd exports" +# The device's per-frame instrumentation: an asset built from an older checkout shipped the bridge +# without VKBRIDGE_LATLOG / VKBRIDGE_STATS, so the knobs did nothing and no latency log existed. +here=$(cd "$(dirname "$0")" && pwd) +"$here/check-instrumentation.sh" --server android/arm64-v8a/libvkbridge_server.so android/arm64-v8a/libvkbridge_jni.so >/dev/null && + "$here/check-instrumentation.sh" usr/local/lib/vkbridge/libvulkan_droidbridge.so >/dev/null || + fail "the asset was built without the latency log / VKBRIDGE_STATS (see check-instrumentation.sh)" +echo "elf ok: ICD GLIBC_$g, self-test GLIBC_$s, 3 vk_icd exports, instrumentation present" diff --git a/scripts/check-instrumentation.sh b/scripts/check-instrumentation.sh new file mode 100755 index 0000000..2a8c61e --- /dev/null +++ b/scripts/check-instrumentation.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Checks that a built bridge library still carries the diagnostics that answer "where did the frame go": +# scripts/check-instrumentation.sh [--server] ... +# Every file must carry the VKBRIDGE_LATLOG and VKBRIDGE_STATS switches; with --server it must also +# carry the latency log's own header line, so that what is checked is the log (server_latency.c) and +# not just a table naming the switch. +# Both are compiled in unconditionally, but they only help if the binary that reaches the device has +# them. A build from an older checkout or a package built from the wrong source directory ships without +# them silently: the knobs are set, nothing is logged, and no measurement can be taken (the CMF's +# v0.5.5.3 server, 2026-11-20: fence wait 2.60 ms and render_scene 3.39 ms of a 31.8 ms frame, with no +# per-frame log to say what the rest of the frame was doing). +# Reads the ELF's string tables, so it runs before or after strip: the literals stay either way. +set -euo pipefail + +server=0 +if [ "${1:-}" = --server ]; then server=1; shift; fi +[ $# -gt 0 ] || { echo "usage: $0 [--server] ..." >&2; exit 2; } + +fail=0 +for f in "$@"; do + [ -f "$f" ] || { echo "FAIL: $f: no such file" >&2; fail=1; continue; } + readelf -h "$f" >/dev/null 2>&1 || { echo "FAIL: $f: not an ELF file" >&2; fail=1; continue; } + missing= + grep -aq 'VKBRIDGE_LATLOG' "$f" || missing="$missing VKBRIDGE_LATLOG" + grep -aq 'VKBRIDGE_STATS' "$f" || missing="$missing VKBRIDGE_STATS" + [ "$server" = 0 ] || grep -aq 'vkbridge latency log' "$f" || missing="$missing latency-log-writer" + if [ -n "$missing" ]; then + echo "FAIL: $f has no:$missing -- built without the per-frame instrumentation?" >&2 + fail=1 + else + echo "ok: $f carries$( [ "$server" = 0 ] || echo ' the latency log and') VKBRIDGE_LATLOG VKBRIDGE_STATS" + fi +done +exit $fail