okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b73e77021
main
1"""Sample system RAM, swap and GPU memory once per second during the trial.""" 2import json 3import subprocess 4import sys 5import time 6from pathlib import Path 7 8with Path (sys .argv [1 ]if len (sys .argv )> 1 else 'telemetry.jsonl' ).open ('a' )as output : 9while True : 10memory = {} 11for line in Path ('/proc/meminfo' ).read_text ().splitlines (): 12key ,value = line .split (':' ,1 ) 13if key in ('MemTotal' ,'MemAvailable' ,'SwapTotal' ,'SwapFree' ): 14memory [key + '_KiB' ]= int (value .strip ().split ()[0 ]) 15gpu = subprocess .check_output (['nvidia-smi' ,'--query-gpu=memory.used,memory.total,utilization.gpu,power.draw,temperature.gpu' ,'--format=csv,noheader,nounits' ],text = True ).strip () 16output .write (json .dumps ({'epoch_s' :time .time (),'memory' :memory ,'gpu' :gpu })+ '\n' ) 17output .flush () 18time .sleep (1 )