Skip to content

Commit 850f6a3

Browse files
author
root
committed
parse_trx.py script to parse response time
1 parent 79d92f1 commit 850f6a3

File tree

1 file changed

+94
-7
lines changed

1 file changed

+94
-7
lines changed

scripts/parse_trx.py

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,111 @@
11
import sys
2+
import math
3+
import functools
24

35
ins = open( sys.argv[1], "r" )
46
array = {}
7+
response_times= {}
8+
9+
array_10s = {}
10+
response_times_10s = {}
11+
12+
array_60s = {}
13+
response_times_60s = {}
14+
15+
def calms(f_sec,f_ms,s_sec,s_ms):
16+
res=(int(f_sec)-int(s_sec))*1000 + (int(f_ms)-int(s_ms))/1000000
17+
return res
18+
19+
def percentile(N, percent, key=lambda x:x):
20+
"""
21+
Find the percentile of a list of values.
22+
23+
@parameter N - is a list of values. Note N MUST BE already sorted.
24+
@parameter percent - a float value from 0.0 to 1.0.
25+
@parameter key - optional key function to compute value from each element of N.
26+
27+
@return - the percentile of the values
28+
"""
29+
if not N:
30+
return None
31+
k = (len(N)-1) * percent
32+
f = math.floor(k)
33+
c = math.ceil(k)
34+
if f == c:
35+
return key(N[int(k)])
36+
d0 = key(N[int(f)]) * (c-k)
37+
d1 = key(N[int(c)]) * (k-f)
38+
return d0+d1
39+
540
if len(sys.argv)>=2:
641
pref=sys.argv[2]
742
else:
843
pref=""
44+
945
for line in ins:
1046
data=line.split()
11-
if array.has_key(data[3]):
12-
array[data[3]] = array[data[3]]+1
47+
current_sec = int(data[3]);
48+
if array.has_key(current_sec):
49+
array[current_sec] = array[current_sec]+1
50+
response_times[current_sec].append(calms(data[3],data[4],data[6],data[7]))
51+
else:
52+
array[current_sec] = 1
53+
response_times[current_sec]=[calms(data[3],data[4],data[6],data[7])]
54+
cur_10s = current_sec/10
55+
if array_10s.has_key(cur_10s):
56+
array_10s[cur_10s] = array_10s[cur_10s]+1
57+
response_times_10s[cur_10s].append(calms(data[3],data[4],data[6],data[7]))
58+
else:
59+
array_10s[cur_10s] = 1
60+
response_times_10s[cur_10s]=[calms(data[3],data[4],data[6],data[7])]
61+
# print calms(data[3],data[4],data[6],data[7])
62+
cur_60s = current_sec/60
63+
if array_60s.has_key(cur_60s):
64+
array_60s[cur_60s] = array_60s[cur_60s]+1
65+
response_times_60s[cur_60s].append(calms(data[3],data[4],data[6],data[7]))
66+
else:
67+
array_60s[cur_60s] = 1
68+
response_times_60s[cur_60s]=[calms(data[3],data[4],data[6],data[7])]
69+
70+
minsec=min(array.keys())
71+
maxsec=max(array.keys())
72+
i=minsec
73+
while i<=maxsec:
74+
if array.has_key(i):
75+
# print str(i),len(response_times[str(i)].sort())
76+
response_times[i].sort()
77+
pct99=percentile(response_times[i],0.99)
78+
print pref,i-minsec,array[i],pct99
79+
else:
80+
print pref,i-minsec,0
81+
i=i+1
82+
83+
print "========== 10 sec ============="
84+
85+
minsec=min(array_10s.keys())
86+
maxsec=max(array_10s.keys())
87+
i=minsec
88+
while i<=maxsec:
89+
if array_10s.has_key(i):
90+
# print str(i),len(response_times[str(i)].sort())
91+
response_times_10s[i].sort()
92+
pct99=percentile(response_times_10s[i],0.99)
93+
print pref,i-minsec,array_10s[i],pct99
1394
else:
14-
array[data[3]] = 1
95+
print pref,i-minsec,0
96+
i=i+1
97+
98+
print "========== 60 sec ============="
1599

16-
minsec=int(min(array.keys()))
17-
maxsec=int(max(array.keys()))
100+
minsec=min(array_60s.keys())
101+
maxsec=max(array_60s.keys())
18102
i=minsec
19103
while i<=maxsec:
20-
if array.has_key(str(i)):
21-
print pref,i-minsec,array[str(i)]
104+
if array_60s.has_key(i):
105+
# print str(i),len(response_times[str(i)].sort())
106+
response_times_60s[i].sort()
107+
pct99=percentile(response_times_60s[i],0.99)
108+
print pref,i-minsec,array_60s[i],pct99
22109
else:
23110
print pref,i-minsec,0
24111
i=i+1

0 commit comments

Comments
 (0)