]> git.somenet.org - pub/astra/parallel.git/blob - prefix/parseDat.py
avg instead of min @prefix
[pub/astra/parallel.git] / prefix / parseDat.py
1 #!/usr/bin/env python2
2
3 import os, subprocess
4
5 def listtofile(listing, file):
6         fd = open(file, 'r')
7         for i in listing:
8                 fd.write(i+"\n")
9         fd.close()
10
11 def makeGraphs(graphs, graphtitle = "Title", xlabel = "Numbers calculated", ylabel = "Time needed for calculation"):
12         gendir = "stats/generated/"
13         subprocess.call(["mkdir", "-p", gendir])
14         p = subprocess.Popen(['gnuplot'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
15         # now do the plots
16         for graphfile in graphs:
17                 # set output 'filename'
18                 p.stdin.write("set terminal png font arial 8 #size 600,300\n")
19                 p.stdin.write("set grid\n")
20                 p.stdin.write("set datafile separator ';'\n")
21                 p.stdin.write("set title 'Timing of each "+graphtitle+"'\n")
22                 p.stdin.write("set xlabel '"+xlabel+"'\n")
23                 p.stdin.write("set ylabel '"+ylabel+"'\n")
24                 p.stdin.write("set output '"+gendir+graphfile+"'\n")
25                 # plot 'filename' using 1:2 title 'algorithm' with lines, 'filename2' using 1:2 title 'algo2' with lines
26                 plots = []
27                 for title, file, cols in graphs[graphfile]:
28                         plots.append("'"+gendir+file+"' using "+cols+" title '"+title+"' with lines")
29                 plotcommand = ", ".join(plots)
30                 #print gendir+graphfile
31                 p.stdin.write("plot "+plotcommand+"\n")
32         p.communicate()[0]
33         p.stdin.close()
34
35 statsdir = 'stats/raw/'
36 runs = os.listdir(statsdir)
37 #print runs
38
39 bigrunlist = []
40 for i in runs:
41         runfiles = os.listdir(statsdir+i)
42 #       print runfiles
43         for file in runfiles:
44 #               print "File: %s%s/%s" % (statsdir, i, file)
45                 splitfilename = file.replace('hillis_', 'hillis-').split('_')
46                 splitfilename[1] = splitfilename[1].replace('hillis-', 'hillis_')
47                 dict = {}
48                 dict['scheduler'] = splitfilename[0]
49                 dict['algo'] = splitfilename[1]
50                 dict['n'] = int(splitfilename[2].lstrip('n'))
51                 fd = open(statsdir+i+'/'+file, "r")
52                 fd_text = fd.read()
53                 fd.close()
54                 fd_lines = fd_text.split("\n")
55                 for line in fd_lines:
56                         if line == "":
57                                 continue
58                         elements = line.split(" ")
59                         for elem in elements:
60                                 (key, value) = elem.split("=", 1)
61                                 if key == 'binname':
62                                         (_, prog) = value.split("/", 1)
63                                         if prog != dict['algo']:
64                                                 print "Failed: %s is not %s" % (prog, dict['algo'])
65                                 elif key == 'size':
66                                         size = int(value)
67                                         if size != dict['n']:
68                                                 print "Failed: %s is not %s" % (size, dict['n'])
69                                 elif key == 'time':
70                                         time = float(value)
71                         dict['time'] = time
72                         bigrunlist.append(dict)
73
74 algos = {}
75 schedulers = {}
76 ns = {}
77 foolist = {}
78 for i in bigrunlist:
79         if not (i['algo'], i['scheduler'], i['n']) in foolist:
80                 foolist[(i['algo'], i['scheduler'], i['n'])] = [i['time']]
81         else:
82                 foolist[(i['algo'], i['scheduler'], i['n'])].append(i['time'])
83         if not i['algo'] in algos:
84                 algos[i['algo']] = {}
85         if not i['scheduler'] in schedulers:
86                 schedulers[i['scheduler']] = {}
87         if not i['n'] in ns:
88                 ns[i['n']] = {}
89 #print "Algos: %s" % algos
90 #print "Schedulers: %s" % schedulers
91 #print "Ns: %s" % ns
92 uniquelist = []
93 for key in foolist:
94         minval = min(foolist[key])
95         avgval = float(sum(foolist[key])) / len(foolist[key])
96         uniquelist.append((key[0], key[1], key[2], avgval))
97 uniquelist.sort()
98 alg_dict = {}
99 sched_dict = {}
100 for i in uniquelist:
101         if i[0] not in alg_dict:
102                 alg_dict[i[0]] = {}
103         if i[1] not in alg_dict[i[0]]:
104                 alg_dict[i[0]][i[1]] = []
105         alg_dict[i[0]][i[1]].append(str(i[2])+";"+str(i[3]))
106         if i[1] not in sched_dict:
107                 sched_dict[i[1]] = {}
108         if i[0] not in sched_dict[i[1]]:
109                 sched_dict[i[1]][i[0]] = []
110         sched_dict[i[1]][i[0]].append(str(i[2])+";"+str(i[3]))
111         #print "od["+i[0]+"]["+i[1]+"] = "+str(i[2])+":"+str(i[3])
112
113 graphs_alg = {}
114 graphs_sched = {}
115 gendir = "stats/generated/"
116 subprocess.call(["mkdir", "-p", gendir])
117 for alg in alg_dict:
118         pngfile = 'algorithm.'+alg+'.png'
119         graphs_alg[pngfile] = []
120         for sched in alg_dict[alg]:
121                 datfile = 'data.'+alg+'.'+sched+'.dat'
122                 fh = open(gendir+datfile, 'a+')
123                 graphs_alg[pngfile].append((sched, datfile, '1:2'))
124                 for dot in alg_dict[alg][sched]:
125                         fh.write(dot+"\n")
126                 fh.close()
127 for sched in sched_dict:
128         pngfile = 'scheduler.'+sched+'.png'
129         graphs_sched[pngfile] = []
130         for alg in sched_dict[sched]:
131                 datfile = 'data.'+alg+'.'+sched+'.dat'
132                 graphs_sched[pngfile].append((alg, datfile, '1:2'))
133
134 #graphs['test1.png'] = [('linetitle1', 'prefix.hillis.dat', '1:2')]
135
136 makeGraphs(graphs_alg, "algorithm")
137 makeGraphs(graphs_sched, "scheduler")