-
Notifications
You must be signed in to change notification settings - Fork 0
/
iozone_parser.py
executable file
·76 lines (66 loc) · 2.57 KB
/
iozone_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python
# Parse iozone result
# will parse all files under this directory
import os
import json
# file larger than 10k is omitted
MAX_FILE_SIZE = 10000
def err (s):
print s
exit (1)
def parse_one_result (fname):
lines = open(fname).read().split("\n")
result = {}
for line in lines:
if "Record Size" in line:
record_size = line.replace(
"Record Size", "").strip()
record_size = int(record_size.replace(
" ", "").replace("kB", ""))
unit = "KB"
result["record_size_kb"] = record_size
if record_size >= 1024:
record_size >>= 10
unit = "MB"
result["record_size_str"] = "%s%s" % (record_size, unit)
elif "Children see throughput" in line:
bw = float(line.split("=", 1)[1].strip().\
split(" ", 1)[0]) / 1000
if "write" in line:
result["seq_write"] = bw
elif "read" in line:
result["seq_read"] = bw
else:
err("Unknown line: " + line)
for key in ["record_size_kb",
"seq_read",
"seq_write"]:
if key not in result:
err("Key '%s' missing" % key)
return result
def parse_all_results (dirname):
files = os.listdir(dirname)
results = []
for fname in files:
fsize = os.stat(fname).st_size
# file too large is omitted
if fsize >= MAX_FILE_SIZE:
print "File '%s' size too big, skip" \
% fname
continue
result = parse_one_result(fname)
results.append(result)
results.sort(key=lambda x: x["record_size_kb"])
return results
def print_results (results):
# result should be sorted
print "%12s%12s%12s" % ("Block Size", "Seq Read", "Seq Write")
for result in results:
print "%12s%12.2f%12.2f" % \
(result["record_size_str"],
result["seq_read"],
result["seq_write"])
def main ():
results = parse_all_results(".")
print_results(results)
main()