File size: 2,664 Bytes
d231962
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
# Live pipeline dashboard. Run it yourself on the box:
#
#   cd /scratch/user4/dai/v2 && bash scripts/monitor.sh
#
# Refreshes every 20 s. Ctrl-C to leave; it only reads, so quitting never affects the run.
# One-shot (for a script or a quick look):   bash scripts/monitor.sh --once
set -uo pipefail
cd "$(dirname "$0")/.."
W="${BERX_WORK:-$(pwd)/work}"
L="$W/logs"
ONCE=0; [ "${1:-}" = "--once" ] && ONCE=1

hr() { printf '%.0s-' $(seq 1 78); echo; }

render() {
  echo "PopTards v2 pipeline   $(date '+%Y-%m-%d %H:%M:%S')"
  hr
  # ---- steps
  if [ -f "$L/status" ]; then
    echo "STEPS"
    awk '{printf "  %-26s %-8s %s\n", $1, $2, $3}' "$L/status"
  else
    echo "STEPS   (no status file yet)"
  fi
  hr
  # ---- what each track is doing
  for t in 1 2; do
    if [ -f "$L/track$t.log" ]; then
      printf "TRACK %s  %s\n" "$t" "$(tail -1 "$L/track$t.log")"
    fi
  done
  hr
  # ---- live progress from whichever stage log moved most recently
  echo "LIVE"
  local newest
  newest=$(ls -t "$L"/t1_*.log "$L"/t2_*.log 2>/dev/null | head -3)
  for f in $newest; do
    local age; age=$(( $(date +%s) - $(stat -c %Y "$f") ))
    printf "  %-16s %4ss ago  %s\n" "$(basename "$f")" "$age" "$(tail -1 "$f" | cut -c1-52)"
  done
  hr
  # ---- the number that matters
  if [ -f "$W/rescore/gate.json" ]; then
    echo "GATE A"
    sed 's/^/  /' "$W/rescore/gate.json"
    hr
  fi
  if [ -f "$W/shards/test_manifest.json" ]; then
    echo "CE SHARDS READY  (start the Colab lanes)"
    grep -E '"total"|"n"|"mb"' "$W/shards/test_manifest.json" | sed 's/^/  /' | head -12
    hr
  fi
  if [ -f "$W/output_v2/matching_results.tsv" ]; then
    echo "SUBMISSION  $W/output_v2/matching_results.tsv"
    printf "  %s lines, %s\n" "$(wc -l < "$W/output_v2/matching_results.tsv")" \
      "$(du -h "$W/output_v2/matching_results.tsv" | cut -f1)"
    hr
  fi
  # ---- machine
  echo "MACHINE"
  printf "  load %s\n" "$(uptime | sed 's/.*average: //')"
  nvidia-smi --query-gpu=index,memory.used,memory.total,utilization.gpu \
    --format=csv,noheader 2>/dev/null | sed 's/^/  gpu /'
  printf "  our procs: %s\n" \
    "$(ps -u "$USER" -o args | grep -c 'scripts/[0-9]' || true)"
  # ---- anything wrong
  local bad
  # grep -c prints "0" AND exits non-zero when nothing matches, so `|| echo 0` appended a
  # second line and the numeric test blew up on "0\n0".
  bad=$(grep -c FAILED "$L/status" 2>/dev/null) || true
  bad=${bad:-0}
  if [ "$bad" -gt 0 ] 2>/dev/null; then
    hr; echo "!! $bad step(s) FAILED - see $L/status and the matching stage log"
  fi
}

if [ "$ONCE" = 1 ]; then render; exit 0; fi
while true; do clear; render; sleep 20; done