okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7b52a0b62
main
1#!/usr/bin/env python3 2"""Sample VRAM and host RAM once a second into a CSV until told to stop. 3 4Reports what the machine used while Strata served requests: VRAM from the amdgpu 5sysfs counters of every card, host RAM as MemTotal - MemAvailable. Both are 6whole-machine numbers, not the engine's own accounting. 7""" 8import argparse 9import csv 10import os 11import time 12from pathlib import Path 13 14 15def cards (): 16return sorted (Path ('/sys/class/drm' ).glob ('card*/device/mem_info_vram_total' )) 17 18 19def read (path ): 20try : 21return int (path .read_text ()) 22except OSError : 23return - 1 24 25 26def meminfo (): 27total = avail = 0 28for line in Path ('/proc/meminfo' ).read_text ().splitlines (): 29if line .startswith ('MemTotal:' ): 30total = int (line .split ()[1 ]) 31elif line .startswith ('MemAvailable:' ): 32avail = int (line .split ()[1 ]) 33return total ,avail 34 35 36def main (): 37p = argparse .ArgumentParser (description = __doc__ ) 38p .add_argument ('--out' ,type = Path ,required = True ) 39p .add_argument ('--seconds' ,type = float ,default = 3600 ) 40p .add_argument ('--stop-file' ,type = Path ) 41args = p .parse_args () 42paths = cards () 43total ,_ = meminfo () 44end = time .monotonic ()+ args .seconds 45with args .out .open ('w' ,newline = '' )as fh : 46w = csv .writer (fh ) 47w .writerow (['unix_s' ]+ [c .parent .name + '_vram_used' for c in paths ]+ ['ram_used_mib' ]) 48while time .monotonic ()< end : 49if args .stop_file and args .stop_file .exists (): 50break 51used = total - meminfo ()[1 ] 52w .writerow ([round (time .time (),2 )]+ [read (c .with_name ('mem_info_vram_used' ))for c in paths ]+ [round (used / 1024 ,1 )]) 53fh .flush () 54time .sleep (1.0 ) 55 56 57if __name__ == '__main__' : 58os .nice (10 ) 59main ()