-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathqperf-parse.py
More file actions
executable file
·82 lines (62 loc) · 2.07 KB
/
Copy pathqperf-parse.py
File metadata and controls
executable file
·82 lines (62 loc) · 2.07 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: zhiguohong@tencent.com
import sys
import operator
STATE_NIL = 0
STATE_BW = 1
STATE_LAT = 2
if __name__ == '__main__':
state = STATE_NIL
bw = 0.0
lat = 0.0
mix_dict = {}
for line in sys.stdin:
str = line.strip()
if str.startswith("tcp_bw:"):
continue
if str.startswith("tcp_lat:"):
continue
if str.startswith("bw"):
tokens = str.split()
# ['bw', '=', '49.9', 'MB/sec']
assert tokens[3] == 'MB/sec', "Not supported unit {}".format(tokens[3])
bw = float(tokens[2])
state = STATE_BW
continue
if str.startswith("latency"):
tokens = str.split()
if tokens[3] == 'us':
unit = 1
elif tokens[3] == 'ms':
unit = 1000
else:
sys.exit("Not supported unit {}".format(tokens[3]))
lat = float(tokens[2]) * unit
state = STATE_LAT
continue
if str.startswith("msg_size"):
tokens = str.split()
if tokens[3] == 'bytes':
unit = 1
elif tokens[3] == 'KiB':
unit = 1024
else:
sys.exit("Not supported unit {}".format(tokens[3]))
msgsize = int(tokens[2]) * unit
if state == STATE_BW:
if msgsize not in mix_dict:
record = [-1, -1]
mix_dict[msgsize] = record
mix_dict[msgsize][0] = bw
elif state == STATE_LAT:
if msgsize not in mix_dict:
record = [-1, -1]
mix_dict[msgsize] = record
mix_dict[msgsize][1] = lat
else:
sys.exit("Bad state {}".format(state))
sorted_mix = sorted(mix_dict.items(), key=operator.itemgetter(0))
print "# msgsize(Bytes) bw(MB/sec) lat(us)"
for item in sorted_mix:
print "%d %.1f %d" % (item[0], item[1][0], item[1][1])