50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import sys, re, os, glob
|
||
|
|
|
||
|
|
# Parse mimalloc-bench logs and print CSV: file,allocator,procs,test,throughput
|
||
|
|
# Assumes lines like: "Throughput = 1234567 operations per second, ..."
|
||
|
|
|
||
|
|
def infer_allocator_from_file(path):
|
||
|
|
fn = os.path.basename(path)
|
||
|
|
if fn.startswith('hakmem_'): return 'hakmem'
|
||
|
|
if fn.startswith('mimalloc_'): return 'mimalloc'
|
||
|
|
if fn.startswith('jemalloc_'): return 'jemalloc'
|
||
|
|
if fn.startswith('system_'): return 'system'
|
||
|
|
# fallback: try substring
|
||
|
|
for k in ('hakmem','mimalloc','jemalloc','system'):
|
||
|
|
if k in fn: return k
|
||
|
|
return 'unknown'
|
||
|
|
|
||
|
|
def infer_procs_from_file(path):
|
||
|
|
m = re.search(r'procs=([0-9,]+)', os.path.basename(path))
|
||
|
|
return m.group(1) if m else ''
|
||
|
|
|
||
|
|
def parse_file(path):
|
||
|
|
alloc = infer_allocator_from_file(path)
|
||
|
|
procs = infer_procs_from_file(path)
|
||
|
|
test = ''
|
||
|
|
with open(path,'r',errors='ignore') as f:
|
||
|
|
for line in f:
|
||
|
|
tl = line.strip()
|
||
|
|
m = re.search(r'^Test\s*:\s*(\S+)', tl)
|
||
|
|
if m: test = m.group(1)
|
||
|
|
m2 = re.search(r'Throughput\s*=\s*([0-9]+)\s+operations per second', tl)
|
||
|
|
if m2:
|
||
|
|
thr = int(m2.group(1))
|
||
|
|
yield (path, alloc, procs, test, thr)
|
||
|
|
|
||
|
|
def main():
|
||
|
|
if len(sys.argv) != 2:
|
||
|
|
print(f"usage: {sys.argv[0]} <log_dir>")
|
||
|
|
sys.exit(1)
|
||
|
|
logdir = sys.argv[1]
|
||
|
|
files = sorted(glob.glob(os.path.join(logdir,'*.log')))
|
||
|
|
print('file,allocator,procs,test,throughput_ops_per_sec')
|
||
|
|
for fp in files:
|
||
|
|
for rec in parse_file(fp):
|
||
|
|
print(','.join(str(x) for x in rec))
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
main()
|
||
|
|
|