watch-8012.sh 1.03 KB
#!/usr/bin/env bash
# 盯 disk offload 那条任务:耗时、内存、以及 rchar/read_bytes——
# rchar 是所有读(含页缓存命中),read_bytes 是真正落到存储层的。
# 两者差得越大说明页缓存命中越好;read_bytes 跟着涨就是在读机械盘,方案不成立。
set -uo pipefail
PID=$(pgrep -f "port 8012")
JOB="$1"
while true; do
  S=$(curl -s --max-time 5 "http://127.0.0.1:8012/v1/videos/$JOB")
  ST=$(echo "$S" | grep -o '"status":"[a-z]*"' | cut -d'"' -f4)
  EL=$(echo "$S" | grep -o '"elapsed_seconds":[0-9]*' | cut -d: -f2)
  RC=$(grep "^rchar:" /proc/$PID/io | tr -dc 0-9)
  RB=$(grep "^read_bytes:" /proc/$PID/io | tr -dc 0-9)
  PD=$(grep "^Private_Dirty:" /proc/$PID/smaps_rollup | tr -dc 0-9)
  printf "%s  %-8s 已跑%4ss  rchar=%6.1fG  read_bytes=%6.2fG  私有内存=%5.2fG\n" \
    "$(date +%H:%M:%S)" "$ST" "${EL:-0}" \
    "$(echo "$RC/1073741824" | bc -l)" "$(echo "$RB/1073741824" | bc -l)" \
    "$(echo "$PD/1048576" | bc -l)"
  case "$ST" in done|failed) echo "$S"; break;; esac
  sleep 60
done