-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonparser.py
More file actions
executable file
·71 lines (63 loc) · 1.97 KB
/
pythonparser.py
File metadata and controls
executable file
·71 lines (63 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import os
import sys
import argparse
import re
def psize(name):
ps = re.split('_|\.' , name)
return int(ps[len(ps)-2])
def throughput(filenames):
data = []
for filename in filenames:
name = re.split('_|\.', filename)
packetsize = int(name[len(name)-2])
data.append((packetsize, throughput_helper(filename , packetsize)))
return data
def throughput_helper(filename , packetsize):
trace = open(filename , 'r')
count = 0
start = 0.0
end = 0.0
prev = 0.0
for line in trace:
if line.startswith('+') and 'tcp' in line and str(packetsize + 40) in line:
words = line.split(' ')
prev = float(words[1])
if count == 0:
start = prev
count += 1
end = prev
throughput = (count*8.0*(packetsize + 40))/((end-start)*1000000)
trace.close()
return throughput
def create_file(data):
datfile = open('plotvalues.dat', 'w')
datfile.write('#X\tY\n')
for (k , v) in data:
datfile.write(str(k) + '\t' + str(v) + '\n')
datfile.close()
def plot(data):
gp = open('throughputplot.gp' , 'w')
gp.write('set grid\n')
gp.write('set title \"Performance of Stop-n-wait\"\n')
gp.write('set xlabel \"Packet Size(bytes)\"\n')
gp.write('set ylabel \"Throughput(mbps)\"\n')
gp.write('set xrange [64:5000]\n')
l = []
for (key, value) in data:
l.append(str(key))
s = " , ".join(l)
gp.write('set xtics (' + s + ')\n')
gp.write('plot \"plotvalues.dat\" using 1:2:(sprintf(\"(%d,%f)\", $1 , $2)) with labels center offset 3.4,0.5 notitle, \'\' with linespoints pointtype 7\n')
gp.write('pause -1')
print 'Done!!'
def main():
parser = argparse.ArgumentParser(description = 'Process the tracefiles and print the throughput')
parser.add_argument('filenames' , metavar='filename', type=str , nargs='+',
help='ns2 tracefiles for which you want the throughputs in mbps. The throughputs will be used to generate the graph')
args = parser.parse_args()
data = throughput(sorted(args.filenames, key=psize))
create_file(data)
plot(data)
if __name__ == '__main__':
main()