Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, subprocess, numpy, Gnuplot
- latency_file = "latencies.txt"
- def create_latency_file(logfile):
- # extract latency column from log
- out_file = open(latency_file, "w")
- var = subprocess.call(["cut", "-d", " ", "-f", "4", logfile], stdout=out_file)
- out_file.close()
- def get_ordered_latencies():
- latencies = []
- valid_latencies = []
- with open(latency_file) as f:
- data = f.read()
- latencies = data.split("\n")
- latencies.pop(-1) #ninjahack
- for latency in latencies:
- # Only use valid latencies. -1 indicates failure
- if latency != '-1':
- valid_latencies.append(float(latency))
- return sorted(valid_latencies)
- def plot_cdf():
- x_values = get_ordered_latencies()
- y_values = numpy.arange(len(x_values))/float(len(x_values))
- gp = Gnuplot.Gnuplot(persist = 1)
- gp('set title "CDF of latencies"')
- gp('set grid')
- gp('set xlabel "Latency [s]"')
- gp('set ylabel "Cumulative probability"')
- cdf = Gnuplot.Data(x_values, y_values, with_="line", title="Latency")
- gp.plot(cdf)
- if __name__ == "__main__":
- if len(sys.argv) == 2:
- if 'plot' in sys.argv[1]:
- print "... Plotting CDF ..."
- plot_cdf()
- print "... Plotting completed ..."
- elif len(sys.argv) == 3:
- if "extract" in sys.argv[1]:
- print "... Extracting latencies from logfile ..."
- create_latency_file(sys.argv[2])
- print "... Done ..."
- else:
- print "Commands:"
- print "* 'extract' 'logfile': creates a new file with all the latencies extracted from the log file"
- print "* 'plot': plots the latencies from the newly created latency file using Gnuplot"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement