Skip to content

Instantly share code, notes, and snippets.

@djinn
Last active March 20, 2023 06:38
Show Gist options
  • Save djinn/a0fcced87a2e9be401d96959f7201837 to your computer and use it in GitHub Desktop.
Save djinn/a0fcced87a2e9be401d96959f7201837 to your computer and use it in GitHub Desktop.
Useful in situations where you are tuning system and comparing benchmarks
#!/usr/bin/env python3
from json import dumps
test_load = """SQL statistics:
queries performed:
read: 845684
write: 241589
other: 120831
total: 1208104
transactions: 60398 (1506.89 per sec.)
queries: 1208104 (30141.30 per sec.)
ignored errors: 8 (0.20 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 40.0802s
total number of events: 60398
Latency (ms):
min: 6.38
avg: 33.14
max: 369.33
95th percentile: 51.94
sum: 2001450.92
Threads fairness:
events (avg/stddev): 1207.9600/52.97
execution time (avg/stddev): 40.0290/0.02
"""
class SysbenchParser:
def __init__(self):
self.hold = {}
self.current = []
def parse(self, row):
if ':' not in row:
return
# We are in a tree branch state
if row.rstrip().endswith(':'):
if row[0] != ' ':
self.current = [row.split(':')[0].lower()]
else:
self.current.append(row.split(':')[0].lstrip()[:-1])
# Leaf node
else:
t = [a.strip() for a in row.strip().split(':')]
key = t[0].replace(' ', '_').lower()
value = self.process_value(t[1])
key = '_'.join([i.replace(' ', '_') for i in self.current]) + '_' + key
self.hold[key] = value
return
def process_value(self, row):
if row.endswith(')'):
t = row.split(' ')
total = float(row[0])
e = None
for i in t[1:]:
if i.startswith('('):
e = i[1:]
ps = float(e)
return {'total': total, 'per_second': ps}
elif row.endswith('s'):
return {'second': float(row[:-1])}
elif '/' in row:
t = row.split('/')
return {'values': [float(v) for v in t]}
else:
return {'value': float(row)}
def payload(self):
return dumps(self.hold)
if __name__ == '__main__':
d = SysbenchParser()
import sys
for i in sys.stdin.readlines():
d.parse(i)
print(d.payload())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment