okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

homeofebench: community results, RTX 2080 Ti 11 GB + Threadripper 3960X, IQ3_S at 262K with KV streaming (#469)707fd49eb

main
1.4 KiB28 linesraw
1#!/usr/bin/env python3
2"""Sample host RAM/swap and GPU memory once per second while the measurements run (one JSON line per sample).
3
4    python monitor.py telemetry.jsonl &      # stop it with kill when done
5"""
6import json
7import subprocess
8import sys
9import time
10from pathlib import Path
11
12FIELDS = "memory.used,memory.total,utilization.gpu,power.draw,temperature.gpu,pcie.link.gen.current"
13with Path(sys.argv[1] if len(sys.argv) > 1 else "telemetry.jsonl").open("a") as output:
14    while True:
15        memory = {}
16        for line in Path("/proc/meminfo").read_text().splitlines():
17            key, value = line.split(":", 1)
18            if key in ("MemTotal", "MemAvailable", "Cached", "SwapTotal", "SwapFree"):
19                memory[key + "_KiB"] = int(value.strip().split()[0])
20        gpu = subprocess.check_output(["nvidia-smi", "--query-gpu=" + FIELDS, "--format=csv,noheader,nounits"],
21                                      text=True).strip()
22        ps = subprocess.run(["ps", "-C", "strata,strata-vision", "-o", "comm=,rss="], text=True,
23                            capture_output=True).stdout.split("\n")
24        rss = {f[0]: int(f[1]) for f in (l.split() for l in ps) if len(f) == 2}     # KiB, resident set
25        output.write(json.dumps({"epoch_s": round(time.time(), 2), "memory": memory, "gpu": gpu,
26                                 "rss_KiB": rss}) + "\n")
27        output.flush()
28        time.sleep(1)