-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_ab_results.py
executable file
·97 lines (80 loc) · 2.61 KB
/
process_ab_results.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/python
import sys
import yaml
import os
import json
USE_KEYS = [
("Server Software", "ab_srv_version", "string"),
("Server Hostname", "ab_srv_host", "string"),
("Server Port", "ab_srv_port", "integer"),
("Document Path", "ab_doc_path", "string"),
("Document Length", "ab_doc_length", "integer"),
("Concurrency Level", "ab_concurrent_lvl", "integer"),
("Time taken for tests", "ab_time_used_s", "float"),
("Complete requests", "ab_completed_requests", "integer"),
("Failed requests", "ab_failed_requests", "integer"),
("Total transferred", "ab_total_transfer_byte", "integer"),
("HTML transferred", "ab_html_transfer_byte", "integer"),
("Requests per second", "ab_request_per_second", "float"),
("Time per request", "ab_mean_time_per_request", "float"),
("Transfer rate", "ab_transfer_rate_kbyte_per_second", "float"),
("server_arrangements", "server_arrangements", "string"),
("stats", "stats", "string"),
("servers", "servers", "string")
]
def process_line(l):
for k in USE_KEYS:
if k[0] in l:
return parse_line(l, k[1], k[2])
return None, None
def parse_line(l, k, typ):
try:
p = l.split(":")
value = p[1].split()[0]
if typ == "integer":
value = int(value)
elif typ == "float":
value = float(value)
except Exception, e:
value = None
return k, value
def update_yml(path, data):
old_data = dict()
# try to load existing data
if os.path.exists(path):
print "Reading %r" % path
with open(path, "r") as f:
old_data = yaml.load(f)
# inject new data
old_data.update(data)
# write yml
print "Writing %r" % path
with open(path, "w") as f:
yaml.safe_dump(old_data, f, default_flow_style=False)
def add_rt_distribution_data(path, r):
with open(path, 'r') as myfile:
data=myfile.read()
r["gobetween_stats"] = data
def main():
INPUT = sys.argv[1]
DIST_INPUT = sys.argv[2]
OUTPUT = sys.argv[3]
print "Started result processing..."
print "In: %s" % INPUT
print "Out: %s" % OUTPUT
result = dict()
if not os.path.exists(INPUT):
print("Coudn't process: {}".format(INPUT))
exit(0)
with open(INPUT, "r") as f:
for l in f.readlines():
k, v = process_line(l)
if k is not None:
result[k] = v
add_rt_distribution_data(DIST_INPUT, result)
for k, v in result.items():
print "%s = %r" % (k, v)
update_yml(OUTPUT, result)
print "done."
if __name__ == '__main__':
main()