]> git.somenet.org - pub/astra/parallel.git/blob - prefix/parseDat.py
parsing done
[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):
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 title 'Timing of each "+graphtitle+"'\n")
19                 p.stdin.write("set output '"+gendir+graphfile+"'\n")
20                 # plot 'filename' using 1:2 title 'algorithm' with lines, 'filename2' using 1:2 title 'algo2' with lines
21                 plots = []
22                 for title, file, cols in graphs[graphfile]:
23                         plots.append("'"+gendir+file+"' using "+cols+" title '"+title+"' with lines")
24                 plotcommand = ", ".join(plots)
25                 #print gendir+graphfile
26                 p.stdin.write("plot "+plotcommand+"\n")
27         p.communicate()[0]
28         p.stdin.close()
29
30 statsdir = 'stats/raw/'
31 runs = os.listdir(statsdir)
32 #print runs
33
34 bigrunlist = []
35 for i in runs:
36         runfiles = os.listdir(statsdir+i)
37 #       print runfiles
38         for file in runfiles:
39 #               print "File: %s%s/%s" % (statsdir, i, file)
40                 splitfilename = file.replace('hillis_', 'hillis-').split('_')
41                 splitfilename[1] = splitfilename[1].replace('hillis-', 'hillis_')
42                 dict = {}
43                 dict['scheduler'] = splitfilename[0]
44                 dict['algo'] = splitfilename[1]
45                 dict['n'] = int(splitfilename[2].lstrip('n'))
46                 fd = open(statsdir+i+'/'+file, "r")
47                 fd_text = fd.read()
48                 fd.close()
49                 fd_lines = fd_text.split("\n")
50                 for line in fd_lines:
51                         if line == "":
52                                 continue
53                         elements = line.split(" ")
54                         for elem in elements:
55                                 (key, value) = elem.split("=", 1)
56                                 if key == 'binname':
57                                         (_, prog) = value.split("/", 1)
58                                         if prog != dict['algo']:
59                                                 print "Failed: %s is not %s" % (prog, dict['algo'])
60                                 elif key == 'size':
61                                         size = int(value)
62                                         if size != dict['n']:
63                                                 print "Failed: %s is not %s" % (size, dict['n'])
64                                 elif key == 'time':
65                                         time = float(value)
66                         dict['time'] = time
67                         bigrunlist.append(dict)
68
69 algos = {}
70 schedulers = {}
71 ns = {}
72 foolist = {}
73 for i in bigrunlist:
74         if not (i['algo'], i['scheduler'], i['n']) in foolist:
75                 foolist[(i['algo'], i['scheduler'], i['n'])] = [i['time']]
76         else:
77                 foolist[(i['algo'], i['scheduler'], i['n'])].append(i['time'])
78         if not i['algo'] in algos:
79                 algos[i['algo']] = {}
80         if not i['scheduler'] in schedulers:
81                 schedulers[i['scheduler']] = {}
82         if not i['n'] in ns:
83                 ns[i['n']] = {}
84 #print "Algos: %s" % algos
85 #print "Schedulers: %s" % schedulers
86 #print "Ns: %s" % ns
87 uniquelist = []
88 for key in foolist:
89         minval = min(foolist[key])
90         uniquelist.append((key[0], key[1], key[2], minval))
91 uniquelist.sort()
92 alg_dict = {}
93 sched_dict = {}
94 for i in uniquelist:
95         if i[0] not in alg_dict:
96                 alg_dict[i[0]] = {}
97         if i[1] not in alg_dict[i[0]]:
98                 alg_dict[i[0]][i[1]] = []
99         alg_dict[i[0]][i[1]].append(str(i[2])+";"+str(i[3]))
100         if i[1] not in sched_dict:
101                 sched_dict[i[1]] = {}
102         if i[0] not in sched_dict[i[1]]:
103                 sched_dict[i[1]][i[0]] = []
104         sched_dict[i[1]][i[0]].append(str(i[2])+";"+str(i[3]))
105         #print "od["+i[0]+"]["+i[1]+"] = "+str(i[2])+":"+str(i[3])
106
107 graphs_alg = {}
108 graphs_sched = {}
109 gendir = 'stats/generated'
110 for alg in alg_dict:
111         pngfile = 'algorithm.'+alg+'.png'
112         graphs_alg[pngfile] = []
113         for sched in alg_dict[alg]:
114                 datfile = 'data.'+alg+'.'+sched+'.dat'
115                 fh = open(gendir+'/'+datfile, 'a+')
116                 graphs_alg[pngfile].append((sched, datfile, '1:2'))
117                 for dot in alg_dict[alg][sched]:
118                         fh.write(dot+"\n")
119                 fh.close()
120 for sched in sched_dict:
121         pngfile = 'scheduler.'+sched+'.png'
122         graphs_sched[pngfile] = []
123         for alg in sched_dict[sched]:
124                 datfile = 'data.'+alg+'.'+sched+'.dat'
125                 graphs_sched[pngfile].append((alg, datfile, '1:2'))
126
127 #graphs['test1.png'] = [('linetitle1', 'prefix.hillis.dat', '1:2')]
128
129 makeGraphs(graphs_alg, "algorithm")
130 makeGraphs(graphs_sched, "scheduler")