forked from DeloitteHux-Old/beeswithmachineguns
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsiege_calc
executable file
·63 lines (48 loc) · 1.95 KB
/
siege_calc
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
#!/usr/bin/env python
"""
this module is used by piping it the stdout from siege when run in verbose mode.
it outputs percentile results for all the requests issued during the siege run,
in exactly the format used by ab.
"""
import re, sqlite3
def get_pctiles(file_like):
"""
"""
p = re.compile(r'\s+([0-9.]+)\ secs')
def _parse_timing(line):
m = p.search(line)
return (m and float(m.group(1))) or None
cx = sqlite3.connect(':memory:', check_same_thread = False)
cur = cx.cursor()
cur.execute('CREATE TABLE timings (secs FLOAT)')
pctiles = {}
try:
cur.executemany('INSERT INTO timings (secs) VALUES (?)',
((_parse_timing(line),) for line in file_like))
cur.execute("""
CREATE TABLE timings_o AS
SELECT secs FROM timings WHERE secs IS NOT NULL ORDER BY secs ASC
""")
cur.execute('SELECT COUNT(*) FROM timings_o')
cnt = int(cur.fetchall()[0][0])
print >> sys.stderr, 'DEBUG: Collected %s timings...'
for pctile in (50, 66, 75, 80, 90, 95, 98, 99, 100):
offset = int((float(pctile)/100)*cnt)-1
cur.execute('SELECT secs FROM timings_o ORDER BY ROWID LIMIT 1 OFFSET %s' % offset)
try:
pctiles[pctile] = cur.fetchall()[0][0]
except IndexError:
print >> sys.stderr, 'ERROR: no result for [%s] percentile' % pctile
# keep on truckin
pctiles[pctile] = 0
return pctiles
finally:
print >> sys.stderr, 'DEBUG: percentiles=%s' % pctiles
cur.close()
cx.close()
if __name__=='__main__':
import sys
pctiles = get_pctiles(sys.stdin)
print >> sys.stderr, 'Percentage of the requests served within a certain time (ms)'
for pctile in sorted(pctiles.keys()):
print >> sys.stderr, ' %s%%\t%s' % (pctile, int(float(pctiles[pctile])*1000))