Last active
August 29, 2015 14:21
-
-
Save kgersen/63fe57eb403c79f04dc3 to your computer and use it in GitHub Desktop.
plot wget
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/python | |
import os, sys | |
def readCurlData(fname): | |
lines = [] | |
with open(fname) as f: | |
for line in f: | |
lines.append(line.split()) | |
return lines[3:] | |
def convertUnits(lines,c): | |
converted = [] | |
for line in lines: | |
if len(line) == 12 and not "--" in line[9]: | |
# curl reports speed in bytes per second | |
# curl k,M,G are x1024 not x1000 | |
if 'k' in line[c]: | |
line[c] = str(float(line[c].replace('k','')) * 8 * 1024) | |
elif 'M' in line[c]: | |
line[c] = str(float(line[c].replace('M','')) * 8 * 1048576) | |
elif 'G' in line[c]: | |
line[c] = str(float(line[c].replace('G','')) * 8 * 1073741824) | |
converted.append([line[9], line[c]]) | |
return converted | |
def writeGnuplotData(fname, lines): | |
fname = fname + ".gnuplot.data" | |
with open(fname, 'w') as f: | |
for line in lines: | |
f.write(','.join(line) + '\n') | |
def plot(fname): | |
gp_fname = fname + ".gp" | |
gpdata_fname = fname + ".gnuplot.data" | |
gpavgdata_fname = fname + ".avg.gnuplot.data" | |
png_fname = fname + ".png" | |
f = open(gp_fname, "w") | |
f.write('set output "%s"\n' % png_fname) | |
f.write('set datafile separator ","\n') | |
f.write('set terminal png size 900,500\n') | |
f.write('set title "Download Speed"\n') | |
f.write('set ylabel "Speed (Mbits/s)"\n') | |
f.write('set xlabel "Time (seconds)"\n') | |
f.write('set xdata time\n') | |
f.write('set timefmt "%H:%M:%S"\n') | |
f.write('set key outside\n') | |
f.write('set grid\n') | |
f.write('plot \\\n') | |
f.write('"%s" using 1:($2/1e6) with points pt 7 ps 2 title "speed"' % gpdata_fname) | |
#f.write('\n'); | |
f.write(',"%s" using 1:($2/1e6) with lines lw 1 lt 1 lc 2 title "avg speed"\n' % gpavgdata_fname) | |
f.close() | |
os.system("gnuplot %s" % gp_fname) | |
if len(sys.argv) < 2: | |
print "Usage: %s [curl_data_filename]" % sys.argv[0] | |
exit(1) | |
else: | |
lines = readCurlData(sys.argv[1]) | |
lines = convertUnits(lines,11) | |
writeGnuplotData(sys.argv[1], lines) | |
lines = readCurlData(sys.argv[1]) | |
lines = convertUnits(lines,6) | |
writeGnuplotData(sys.argv[1]+".avg", lines) | |
plot(sys.argv[1]) |
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
plot a wget transfert. | |
req: python, gnuplot, wget | |
sample: | |
./xcurl http://1.testdebit.info/fichiers/1000Mo.dat > curl.out | |
./gcurl.py curl.out |
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
#!/bin/bash | |
curl $1 -k -o /dev/null 2>&1 | tr $'\r' $'\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment