okami.mom/strata

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

jase100kCommunity benchmark: RX 7900 GRE (gfx1100, 16 GB), three Flash-Next quants (#740)7b52a0b62

main
1.8 KiB59 linesraw
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():
16    return sorted(Path('/sys/class/drm').glob('card*/device/mem_info_vram_total'))
17
18
19def read(path):
20    try:
21        return int(path.read_text())
22    except OSError:
23        return -1
24
25
26def meminfo():
27    total = avail = 0
28    for line in Path('/proc/meminfo').read_text().splitlines():
29        if line.startswith('MemTotal:'):
30            total = int(line.split()[1])
31        elif line.startswith('MemAvailable:'):
32            avail = int(line.split()[1])
33    return total, avail
34
35
36def main():
37    p = argparse.ArgumentParser(description=__doc__)
38    p.add_argument('--out', type=Path, required=True)
39    p.add_argument('--seconds', type=float, default=3600)
40    p.add_argument('--stop-file', type=Path)
41    args = p.parse_args()
42    paths = cards()
43    total, _ = meminfo()
44    end = time.monotonic() + args.seconds
45    with args.out.open('w', newline='') as fh:
46        w = csv.writer(fh)
47        w.writerow(['unix_s'] + [c.parent.name + '_vram_used' for c in paths] + ['ram_used_mib'])
48        while time.monotonic() < end:
49            if args.stop_file and args.stop_file.exists():
50                break
51            used = total - meminfo()[1]
52            w.writerow([round(time.time(), 2)] + [read(c.with_name('mem_info_vram_used')) for c in paths] + [round(used / 1024, 1)])
53            fh.flush()
54            time.sleep(1.0)
55
56
57if __name__ == '__main__':
58    os.nice(10)
59    main()