okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
407ea8192
main
1"""Sample system RAM, swap and AMD GPU readings once per second during the trial. 2 3Radeon Pro VII / ROCm 6.2 adaptation of 4bench/results/2026-10-04-community-mi50/monitor_mi50.py: 5GPU memory, edge/junction/memory temperature and socket power via rocm-smi 6(ROCm 6.2 has no `--showpowercap`, so the power cap comes from the hwmon 7`power1_cap` file). Runs on the HOST (needs rocm-smi), writes telemetry.jsonl. 8 9python3 monitor_rpv.py telemetry.jsonl 10""" 11import json 12import subprocess 13import sys 14import time 15from pathlib import Path 16 17 18def parse_rocm_smi (): 19"""One rocm-smi call per sample: VRAM, temperatures, power, GPU use.""" 20out = {} 21try : 22text = subprocess .check_output ( 23 ["rocm-smi" ,"--showmeminfo" ,"vram" ,"--showtemp" ,"--showpower" ,"--showuse" ], 24text = True ,stderr = subprocess .DEVNULL ) 25except Exception as error :# noqa: BLE001 26return {"error" :str (error )} 27for line in text .splitlines (): 28# rocm-smi 的行形如 "GPU[0]\t\t: Temperature (Sensor edge) (C): 37.0" —— 指标名在**最后一个** 29# 冒号之前,所以按最后一个冒号切(按第一个切会只拿到 "GPU[0]")。 30if ":" not in line : 31continue 32name ,_ ,value = line .rpartition (":" ) 33name ,value = name .strip (),value .strip () 34try : 35if name .endswith ("VRAM Total Memory (B)" ): 36out ["vram_total_bytes" ]= int (value ) 37elif name .endswith ("VRAM Total Used Memory (B)" ): 38out ["vram_used_bytes" ]= int (value ) 39elif "(Sensor edge) (C)" in name : 40out ["temp_edge_c" ]= float (value ) 41elif "(Sensor junction) (C)" in name : 42out ["temp_junction_c" ]= float (value ) 43elif "(Sensor memory) (C)" in name : 44out ["temp_memory_c" ]= float (value ) 45elif "Socket Graphics Package Power (W)" in name : 46out ["power_w" ]= float (value ) 47elif "GPU use (%)" in name : 48out ["gpu_use_pct" ]= float (value ) 49except ValueError : 50continue 51return out 52 53 54def power_cap_uw (): 55for path in Path ("/sys/class/drm" ).glob ("card*/device/hwmon/hwmon*/power1_cap" ): 56try : 57return int (path .read_text ().strip ()),str (path ) 58except OSError : 59continue 60return None ,None 61 62 63cap ,cap_path = power_cap_uw () 64target = Path (sys .argv [1 ]if len (sys .argv )> 1 else "telemetry.jsonl" ) 65with target .open ("a" )as output : 66while True : 67memory = {} 68for line in Path ("/proc/meminfo" ).read_text ().splitlines (): 69key ,value = line .split (":" ,1 ) 70if key in ("MemTotal" ,"MemAvailable" ,"SwapTotal" ,"SwapFree" ): 71memory [key + "_KiB" ]= int (value .strip ().split ()[0 ]) 72output .write (json .dumps ({"epoch_s" :time .time (),"memory" :memory , 73"gpu" :parse_rocm_smi (), 74"power_cap_uw" :cap ,"power_cap_path" :cap_path })+ "\n" ) 75output .flush () 76time .sleep (1 )