Skip to content

Instantly share code, notes, and snippets.

@jolynch
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolynch/eddcd329b3c754f5b0b2 to your computer and use it in GitHub Desktop.
Save jolynch/eddcd329b3c754f5b0b2 to your computer and use it in GitHub Desktop.
Hacky script to convert an apache benchmark data file into a CDF
#!/usr/bin/python
# Usage
# ./convert_to_cdf.py ab_output.dat ab_output_cdf.dat
import csv
import sys
times = []
just_times = []
infile = sys.argv[1]
outfile = sys.argv[2]
with open(infile, 'r') as f:
next(f)
reader = csv.reader(f, delimiter='\t')
for st, s, ctime, dtime, ttime, wait in reader:
times.append((s, ttime))
just_times.append(ttime)
with open(outfile, 'w') as f:
writer = csv.writer(f, delimiter='\t')
writer.writerow(('ms', 'percent'))
num = float(len(times))
seen = {}
rows = []
for s, ttime in times:
if ttime in seen:
continue
rows.append((ttime, '{:.6f}'.format(just_times.count(ttime) / num)))
seen[ttime] = True
writer.writerows(rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment