summaryrefslogtreecommitdiffstats
path: root/test_prompts.sh
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-08-16 16:44:58 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-08-16 16:44:58 +0800
commit356d060293e054d03145c005e7359cef6b5880cf (patch)
treed853fb6a8355f16d711e55c0627ced5605d290ca /test_prompts.sh
parente7e1ab12dd42936e389f1d56ad22f45d795d79a7 (diff)
downloadlex-356d060293e054d03145c005e7359cef6b5880cf.tar.gz
Add swap occupancy to test script.
Diffstat (limited to 'test_prompts.sh')
-rwxr-xr-xtest_prompts.sh64
1 files changed, 41 insertions, 23 deletions
diff --git a/test_prompts.sh b/test_prompts.sh
index 61fb69f..0424e62 100755
--- a/test_prompts.sh
+++ b/test_prompts.sh
@@ -19,26 +19,39 @@ if [ ! -f "$MODEL_PATH" ]; then
fi
# Derive base model name and output result filename
-# e.g., models/qwen2.5-7b-q4.gguf -> results_qwen2.5-7b-q4.gguf.txt
MODEL_NAME=$(basename "$MODEL_PATH")
RESULT_FILE="results_${MODEL_NAME}.txt"
# Default prompt filename (optional 2nd argument)
PROMPT_FILE="${2:-test_prompts.txt}"
-# Ensure the executable exists and is runnable
+# Ensure executable exists
if [ ! -x "$EXECUTABLE" ]; then
echo "Error: Executable '$EXECUTABLE' not found or not executable." >&2
exit 1
fi
-# Ensure the prompt file exists
+# Ensure prompt file exists
if [ ! -f "$PROMPT_FILE" ]; then
echo "Error: Prompt file '$PROMPT_FILE' not found." >&2
exit 1
fi
-# Count valid prompts using POSIX awk to avoid ksh $(...) parenthetical syntax errors
+# Helper function to get current swap occupancy in MB by parsing swapctl -l
+# OpenBSD swapctl -l outputs 512-byte block counts by default
+get_swap_occupancy_mb() {
+ swapctl -l | awk '
+ NR > 1 {
+ # Column 3 is Used blocks (512-byte blocks)
+ used_blocks += $3
+ }
+ END {
+ # Convert 512-byte blocks to MB (blocks * 512 / 1024 / 1024)
+ printf "%.2f", used_blocks * 512 / 1048576
+ }'
+}
+
+# Count valid prompts using POSIX awk
total_prompts=$(awk '/^[[:space:]]*($|#)/ {next} {count++} END {print count+0}' "$PROMPT_FILE")
if [ "$total_prompts" -eq 0 ]; then
@@ -46,10 +59,10 @@ if [ "$total_prompts" -eq 0 ]; then
exit 0
fi
-# Create (or truncate) the result file at the start of the run
+# Create (or truncate) result file
> "$RESULT_FILE"
-# Create horizontal rule.
+# Create horizontal rule
RULE=""
i=0
while [ $i -lt 72 ]; do
@@ -57,7 +70,7 @@ while [ $i -lt 72 ]; do
i=$((i + 1))
done
-# --- Start the daemon once, wait for it to come up, capture its baseline RSS ---
+# --- Start daemon ---
echo "Starting daemon with model: '$MODEL_PATH'"
"$EXECUTABLE" -m "$MODEL_PATH" &
@@ -70,9 +83,6 @@ cleanup() {
}
trap cleanup EXIT INT TERM
-# Wait for the socket to appear (covers model load time) and for the
-# process to still be alive (covers early startup failure, e.g. bad
-# model path -> daemon exits immediately).
waited=0
while [ ! -S "$SOCK_PATH" ]; do
if ! kill -0 "$DAEMON_PID" 2>/dev/null; then
@@ -98,44 +108,51 @@ first=1
# Temporary file to capture time / rusage output
TIME_LOG=$(mktemp /tmp/lex_time.XXXXXX)
-# Process each prompt line by line
+# Process each prompt
while IFS= read -r prompt || [ -n "$prompt" ]; do
- # Skip empty lines or comment lines starting with #
case "$prompt" in
""|\#*) continue ;;
esac
current=$((current + 1))
- # Add delimiter before every prompt except the first in the results file
if [ "$first" -eq 1 ]; then
first=0
else
printf "%s\n\n" "$RULE" >> "$RESULT_FILE"
fi
- # Log prompt header to the result file
printf "PROMPT: %s\n\n" "$prompt" >> "$RESULT_FILE"
- # Sample the daemon's RSS right before firing the request, so we have
- # a rough steady-state figure (won't catch a mid-request peak, but the
- # model's footprint is dominated by the loaded weights, not per-request
- # allocation, so this is a reasonable proxy).
+ # Sample daemon RSS prior to request
daemon_rss_kb=$(ps -o rss= -p "$DAEMON_PID" 2>/dev/null | tr -d ' ')
- # Send the prompt to the daemon over the socket, timing the round trip.
- # This now measures request latency only (no model-load cost), which is
- # the number that actually matters day to day with the daemon design.
+ # Capture baseline swap occupancy before sending the prompt
+ swap_start_mb=$(get_swap_occupancy_mb)
+
+ # Send prompt to daemon over socket
/usr/bin/time -lp sh -c "printf '%s\n' \"\$1\" | nc -U \"\$2\"" _ "$prompt" "$SOCK_PATH" \
>> "$RESULT_FILE" 2> "$TIME_LOG"
+ # Capture ending swap occupancy after prompt completes
+ swap_end_mb=$(get_swap_occupancy_mb)
+
real_time=$(awk '/^real/ {print $2}' "$TIME_LOG")
+ # Calculate net change in swap occupancy during request execution
+ if [ -n "$swap_start_mb" ] && [ -n "$swap_end_mb" ]; then
+ swap_delta_mb=$(awk -v start="$swap_start_mb" -v end="$swap_end_mb" \
+ 'BEGIN { printf "%+.2f", end - start }')
+ else
+ swap_end_mb="unavailable"
+ swap_delta_mb="+0.00"
+ fi
+
if [ -n "$daemon_rss_kb" ]; then
daemon_rss_mb=$(awk -v kb="$daemon_rss_kb" 'BEGIN{printf "%.2f", kb/1024}')
- metrics_summary="ELAPSED: ${real_time}s | DAEMON RSS: ${daemon_rss_mb} MB"
+ metrics_summary="ELAPSED: ${real_time}s | DAEMON RSS: ${daemon_rss_mb} MB | SWAP: ${swap_end_mb} MB (${swap_delta_mb} MB)"
else
- metrics_summary="ELAPSED: ${real_time}s | DAEMON RSS: unavailable"
+ metrics_summary="ELAPSED: ${real_time}s | DAEMON RSS: unavailable | SWAP OCCUPIED: ${swap_end_mb} MB (${swap_delta_mb} MB)"
fi
printf "METRICS: %s\n\n" "$metrics_summary" >> "$RESULT_FILE"
@@ -146,3 +163,4 @@ done < "$PROMPT_FILE"
echo "---------------------------------------------------"
echo "Done! Processed $total_prompts prompt(s)."
+