"""gpu_history.py — cumulative low-utilization sampler (the instrument the fall-time test's death named). nvidia-smi dmon samples every second: sm% util, mem%, power. This organ accumulates a low-util history window so "fall-time" becomes a measured property of the GPU, not of my logging. Usage: python gpu_history.py start -> launches background sampler writing gpu-history.csv python gpu_history.py status -> last sample + file rows python gpu_history.py quiet [MINUTES] -> cumulative low-util minutes in last MINUTES (default 30) low-util = sm util < 10 pct per sample """ import subprocess, sys, os, time, csv U = r"C:/Users/user/1f916-contribution" HIST = os.path.join(U, "gpu-history.csv") def start(): # dmon -o DT -s pucm: date+time columns, power/util/clock/mem; -d 1 = every second out = open(HIST, "a", buffering=1) proc = subprocess.Popen( ["nvidia-smi", "dmon", "-o", "DT", "-s", "pucm", "-d", "1"], stdout=out, stderr=subprocess.DEVNULL) print("sampler pid:", proc.pid, "-> ", HIST) def status(): if not os.path.exists(HIST): print("no history file"); return rows = open(HIST).read().splitlines() print("rows:", len(rows)) for l in rows[-3:]: print(l) def quiet(minutes=30): if not os.path.exists(HIST): print("no history file"); return cutoff = time.time() - minutes*60 low = 0; total = 0 # verbose dmon columns: date time gpu pwr gtemp mtemp sm mem enc dec jpg ofa mclk pclk ... for l in open(HIST): parts = l.split() if len(parts) < 7 or parts[0].startswith("#"): continue try: ts = time.mktime(time.strptime(parts[0]+" "+parts[1], "%Y%m%d %H:%M:%S")) # dmon -o DT stamps LOCAL time; mktime reads local — consistent except ValueError: continue if ts < cutoff: continue total += 1 try: sm_util = int(parts[6]) except ValueError: continue if sm_util < 10: low += 1 print(f"window={minutes}min samples={total} low-util-samples={low} low-util-minutes={round(low/60,2)}") if __name__ == "__main__": cmd = sys.argv[1] if len(sys.argv) > 1 else "status" if cmd == "start": start() elif cmd == "quiet": quiet(int(sys.argv[2]) if len(sys.argv) > 2 else 30) else: status()