loadprof.sh 1.5 KB

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  2. # Profile the weight-load phase of a boot on the head: py-spy dumps of the TP0 scheduler every
  3. # 10 s, NVMe read rate and MemFree/Cached every 5 s. Run on the head after `./start-tp4.sh serve`.
  4. # bash scripts/loadprof.sh ~/loadprof-$(date +%Y%m%d-%H%M)
  5. # Summarise the disk log with:
  6. # sed 's/readMB=//' disk.log | awk '{if(prev!=""){printf "%s +%.2f GB/s\n", $1, ($2-prev)/5000}; prev=$2}'
  7. set -u
  8. OUT=${1:-~/loadprof}; mkdir -p "$OUT"
  9. L=${LOG:-logs-tp4/dsv41.log}
  10. until docker ps --format '{{.Names}}' | grep -q '^dsv41-head$'; do sleep 2; done
  11. until grep -aq "Load weight begin" "$L" 2>/dev/null; do sleep 2; done
  12. ( while true; do echo "$(date +%T) $(awk '$3=="nvme0n1"{printf "readMB=%.0f", $6*512/1e6}' /proc/diskstats) $(grep -E 'MemFree|MemAvailable|^Cached' /proc/meminfo | tr -s ' ' | tr '\n' ' ')"; sleep 5; done ) > "$OUT/disk.log" 2>&1 &
  13. DP=$!
  14. until grep -aq "Engine startup timings" "$L" 2>/dev/null; do
  15. PID=$(docker exec dsv41-head sh -c "ps -eo pid,args | grep scheduler_TP0 | grep -v grep | awk '{print \$1}'" 2>/dev/null | head -1)
  16. T=$(date +%H%M%S)
  17. if [ -n "$PID" ]; then
  18. timeout 20 docker exec dsv41-head py-spy dump --pid "$PID" > "$OUT/dump-$T.txt" 2>&1
  19. docker exec dsv41-head sh -c "top -b -n1 -H -p $PID | sed -n 7,16p" > "$OUT/top-$T.txt" 2>&1
  20. fi
  21. sleep 10
  22. done
  23. kill $DP 2>/dev/null
  24. grep -aE "Load weight|fast load|Engine startup timings|max_total_num_tokens" "$L" | cut -c1-220 > "$OUT/timeline.txt"
  25. echo "profile in $OUT"