summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/stack_sampler.sh
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-29 16:57:09 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-29 16:57:09 -0400
commit50da0edc952f5ad93dcbd33a3e5cb974d2411d45 (patch)
tree38b69063f916332ebb1b63bac7af50376ccacfff /tools/guest-diag/stack_sampler.sh
parentf049f8613a1e54ba2578e78727f6782a5c45494e (diff)
downloadopen-iov-50da0edc952f5ad93dcbd33a3e5cb974d2411d45.tar.gz
open-iov-50da0edc952f5ad93dcbd33a3e5cb974d2411d45.zip
guest-diag: per-thread kernel stack sampler for the CUDA client
The failing wait can live in a libcuda worker thread (strace without -f misses it); sample every /proc/<pid>/task/*/stack + wchan while the client runs.
Diffstat (limited to 'tools/guest-diag/stack_sampler.sh')
-rwxr-xr-xtools/guest-diag/stack_sampler.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/guest-diag/stack_sampler.sh b/tools/guest-diag/stack_sampler.sh
new file mode 100755
index 0000000..f210422
--- /dev/null
+++ b/tools/guest-diag/stack_sampler.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# stack_sampler.sh - per-thread kernel stack sampler for the CUDA client.
+#
+# The client's failing wait is not always visible in strace: libcuda runs
+# worker threads and the main thread may only see the error. Sample every
+# thread's wchan + kernel stack so the wait that expires is captured.
+#
+# Usage: sh /tmp/stack_sampler.sh [samples] [sleep]
+N="${1:-900}"
+SLEEP="${2:-0.2}"
+
+PID=""
+for i in $(seq 1 80); do
+ PID=$(pgrep -x cdt | head -1)
+ [ -n "$PID" ] && break
+ sleep 0.25
+done
+[ -n "$PID" ] || { echo "no cdt" > /tmp/stacks.log; exit 1; }
+
+: > /tmp/stacks.log
+i=0
+while [ "$i" -lt "$N" ]; do
+ kill -0 "$PID" 2>/dev/null || { echo "GONE" >> /tmp/stacks.log; break; }
+ T=$(date +%T.%3N)
+ for t in /proc/$PID/task/*; do
+ [ -d "$t" ] || continue
+ tid=${t##*/}
+ st=$(awk '{print $3}' "$t/stat" 2>/dev/null)
+ wc=$(cat "$t/wchan" 2>/dev/null)
+ echo "$T tid=$tid state=$st wchan=$wc" >> /tmp/stacks.log
+ cat "$t/stack" >> /tmp/stacks.log 2>/dev/null
+ done
+ i=$((i + 1))
+ sleep "$SLEEP"
+done
+echo "DONE" >> /tmp/stacks.log \ No newline at end of file