Skip to content

Instantly share code, notes, and snippets.

@asadoughi
Created February 3, 2015 17:15
Show Gist options
  • Save asadoughi/32d035ded5c8f8fa496d to your computer and use it in GitHub Desktop.
Save asadoughi/32d035ded5c8f8fa496d to your computer and use it in GitHub Desktop.
"""
$ python simulation.py ./simulation.log
mean 168604.207778
min 85959.0
50% 180946.0
75% 198296.0
95% 205020.0
99% 207004.0
max 207197.0
"""
import sys
times = []
with open(sys.argv[1], "r") as f:
lines = f.readlines()
for line in lines:
l = line.strip().split()
if l[3:7] == ["REQUEST", "Admin", "POST", "/ports"]:
if l[-1] == "OK":
rqstart, rqend, rsstart, rsend = [float(e) for e in l[-5:-1]]
times.append(rsstart - rqstart)
tms = sorted(times)
print "mean", sum(tms)/len(tms)
print "min", tms[0]
print "50%", tms[int(round(.5 * len(tms)))]
print "75%", tms[int(round(.75 * len(tms)))]
print "95%", tms[int(round(.95 * len(tms)))]
print "99%", tms[int(round(.99 * len(tms)))]
print "max", tms[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment