Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
18 lines
905 B
Bash
18 lines
905 B
Bash
#!/usr/bin/env bash
|
|
# sample_env.sh OUT.tsv INTERVAL_S name=pid ... : memory/VRAM time series of a running stack (test tooling).
|
|
out=$1; every=$2; shift 2
|
|
echo -e "epoch\tname\tvmrss_mib\tvmhwm_mib\trssanon_mib\trssshmem_mib\tvmlck_mib\tgpu_used_mib\tmem_available_mib" >"$out"
|
|
while :; do
|
|
now=$(date +%s)
|
|
gpu=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits 2>/dev/null | head -1)
|
|
avail=$(awk '/MemAvailable/{print int($2/1024)}' /proc/meminfo)
|
|
for spec in "$@"; do
|
|
name=${spec%%=*}; pid=${spec#*=}
|
|
[ -r /proc/$pid/status ] || continue
|
|
awk -v n="$name" -v t="$now" -v g="$gpu" -v a="$avail" '
|
|
/^VmRSS:/{rss=$2} /^VmHWM:/{hwm=$2} /^RssAnon:/{an=$2} /^RssShmem:/{sh=$2} /^VmLck:/{lck=$2}
|
|
END{printf "%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n", t, n, rss/1024, hwm/1024, an/1024, sh/1024, lck/1024, g, a}' /proc/$pid/status >>"$out"
|
|
done
|
|
sleep "$every"
|
|
done
|