Created
November 5, 2013 18:42
-
-
Save queertypes/7323896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""summarize: Given Tsung's HTTP Return Code table saved in a file, outputs: | |
=================== | |
Summary: % of Total | |
=================== | |
{200: 0.03223020521177586, | |
201: 0.6133764139909427, | |
204: 0.3496694087548634, | |
404: 0.0035652209764322185, | |
500: 0.0008723182182140912, | |
503: 0.0002864328477717911} | |
============= | |
Zoom In: 500s | |
============= | |
500s 0.000872% | |
""" | |
from __future__ import division, print_function | |
import itertools | |
import pprint | |
import sys | |
def show_header(title): | |
length = len(title) | |
decoration = '=' * length | |
print(decoration + '\n' + title + '\n' + decoration) | |
print() | |
def analyze(name): | |
data = None | |
with open(name) as f: | |
data = f.readlines() | |
columns = [x.split('\t') for x in data] | |
fields = [(int(code.strip()), secs.strip(), int(count.strip())) for | |
(code, secs, count) in columns] | |
d = {} | |
total = sum([count for (_, _, count) in fields]) | |
for code, _, count in fields: | |
d[code] = count / total | |
show_header('Summary: % of Total') | |
pprint.pprint(d) | |
print() | |
show_header('Zoom In: 500s') | |
print('500s %f%%' % sum([v for (k, v) in d.items() if k / 100 == 5])) | |
if __name__ == '__main__': | |
analyze(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment