1 | import os |
---|
2 | import sys |
---|
3 | import time |
---|
4 | import itertools |
---|
5 | import matplotlib.pyplot as plt |
---|
6 | import matplotlib.ticker as ticks |
---|
7 | import math |
---|
8 | from scipy import stats as st |
---|
9 | import numpy as np |
---|
10 | from enum import Enum |
---|
11 | from statistics import median |
---|
12 | |
---|
13 | import matplotlib |
---|
14 | matplotlib.use("pgf") |
---|
15 | matplotlib.rcParams.update({ |
---|
16 | "pgf.texsystem": "pdflatex", |
---|
17 | 'font.family': 'serif', |
---|
18 | 'text.usetex': True, |
---|
19 | 'pgf.rcfonts': False, |
---|
20 | 'font.size': 16 |
---|
21 | }) |
---|
22 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' )) |
---|
23 | |
---|
24 | readfile = open(sys.argv[1], "r") |
---|
25 | |
---|
26 | machineName = "" |
---|
27 | |
---|
28 | if len(sys.argv) > 2: |
---|
29 | machineName = sys.argv[2] |
---|
30 | |
---|
31 | # first line has num times per experiment |
---|
32 | line = readfile.readline() |
---|
33 | numTimes = int(line) |
---|
34 | |
---|
35 | # second line has processor args |
---|
36 | line = readfile.readline() |
---|
37 | procs = [] |
---|
38 | for val in line.split(): |
---|
39 | procs.append(int(val)) |
---|
40 | |
---|
41 | # 3rd line has number of variants |
---|
42 | line = readfile.readline() |
---|
43 | names = line.split() |
---|
44 | numVariants = len(names) |
---|
45 | |
---|
46 | lines = (line.rstrip() for line in readfile) # All lines including the blank ones |
---|
47 | lines = (line for line in lines if line) # Non-blank lines |
---|
48 | |
---|
49 | class Bench(Enum): |
---|
50 | Unset = 0 |
---|
51 | Executor = 1 |
---|
52 | Matrix = 2 |
---|
53 | Repeat = 3 |
---|
54 | Balance_One = 4 |
---|
55 | Balance_Multi = 5 |
---|
56 | Static = 7 |
---|
57 | Dynamic = 8 |
---|
58 | Mem = 9 |
---|
59 | |
---|
60 | nameSet = False |
---|
61 | currBench = Bench.Unset # default val |
---|
62 | count = 0 |
---|
63 | procCount = 0 |
---|
64 | currVariant = 0 |
---|
65 | name = "" |
---|
66 | var_name = "" |
---|
67 | sendData = [0.0 for j in range(numVariants)] |
---|
68 | data = [[0.0 for i in range(len(procs))] for j in range(numVariants)] |
---|
69 | bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)] |
---|
70 | tempData = [0.0 for i in range(numTimes)] |
---|
71 | for idx, line in enumerate(lines): |
---|
72 | # print(line) |
---|
73 | |
---|
74 | if currBench == Bench.Unset: |
---|
75 | if line == "executor": |
---|
76 | name = "Executor" |
---|
77 | currBench = Bench.Executor |
---|
78 | elif line == "matrix": |
---|
79 | name = "Matrix" |
---|
80 | currBench = Bench.Matrix |
---|
81 | elif line == "repeat": |
---|
82 | name = "Repeat" |
---|
83 | currBench = Bench.Repeat |
---|
84 | elif line == "balance_one": |
---|
85 | name = "Balance-One" |
---|
86 | currBench = Bench.Balance_One |
---|
87 | elif line == "balance_multi": |
---|
88 | name = "Balance-Multi" |
---|
89 | currBench = Bench.Balance_Multi |
---|
90 | elif line == "static": |
---|
91 | name = "Static" |
---|
92 | currBench = Bench.Static |
---|
93 | elif line == "dynamic": |
---|
94 | name = "Dynamic" |
---|
95 | currBench = Bench.Dynamic |
---|
96 | elif line == "mem": |
---|
97 | name = "ExecutorMemory" |
---|
98 | currBench = Bench.Mem |
---|
99 | else: |
---|
100 | print("Expected benchmark name") |
---|
101 | sys.exit() |
---|
102 | continue |
---|
103 | |
---|
104 | if line[0:4] == "proc": |
---|
105 | continue |
---|
106 | |
---|
107 | if currBench == Bench.Static or currBench == Bench.Dynamic or currBench == Bench.Mem: |
---|
108 | if not nameSet: |
---|
109 | nameSet = True |
---|
110 | continue |
---|
111 | lineArr = line.split() |
---|
112 | tempData[count] = float(lineArr[-1]) |
---|
113 | count += 1 |
---|
114 | if count == numTimes: |
---|
115 | currMedian = median( tempData ) |
---|
116 | sendData[currVariant] = currMedian |
---|
117 | count = 0 |
---|
118 | nameSet = False |
---|
119 | currVariant += 1 |
---|
120 | |
---|
121 | if currVariant == numVariants: |
---|
122 | fileName = "data/" + machineName |
---|
123 | if currBench == Bench.Static: |
---|
124 | fileName += "SendStatic" |
---|
125 | elif currBench == Bench.Dynamic: |
---|
126 | fileName += "SendDynamic" |
---|
127 | else: |
---|
128 | fileName += "ExecutorMem" |
---|
129 | f = open(fileName, 'w') |
---|
130 | if currBench == Bench.Mem: |
---|
131 | f.write(" & ".join(map(lambda a: str(int(a/1000)) + 'MB', sendData))) |
---|
132 | else: |
---|
133 | f.write(" & ".join(map(lambda a: str(int(a)) + 'ns', sendData))) |
---|
134 | |
---|
135 | # reset |
---|
136 | currBench = Bench.Unset |
---|
137 | currVariant = 0 |
---|
138 | |
---|
139 | else: |
---|
140 | if not nameSet: |
---|
141 | nameSet = True |
---|
142 | continue |
---|
143 | |
---|
144 | lineArr = line.split() |
---|
145 | tempData[count] = float(lineArr[-1]) |
---|
146 | count += 1 |
---|
147 | if count == numTimes: |
---|
148 | currMedian = median( tempData ) |
---|
149 | data[currVariant][procCount] = currMedian |
---|
150 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData)) |
---|
151 | bars[currVariant][0][procCount] = currMedian - lower |
---|
152 | bars[currVariant][1][procCount] = upper - currMedian |
---|
153 | count = 0 |
---|
154 | procCount += 1 |
---|
155 | |
---|
156 | if procCount == len(procs): |
---|
157 | procCount = 0 |
---|
158 | nameSet = False |
---|
159 | currVariant += 1 |
---|
160 | |
---|
161 | if currVariant == numVariants: |
---|
162 | fig, ax = plt.subplots() |
---|
163 | plt.title(name + " Benchmark") |
---|
164 | plt.ylabel("Runtime (seconds)") |
---|
165 | plt.xlabel("Cores") |
---|
166 | for idx, arr in enumerate(data): |
---|
167 | plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) ) |
---|
168 | if currBench == Bench.Executor or currBench == Bench.Matrix or currBench == Bench.Balance_One or currBench == Bench.Repeat: |
---|
169 | plt.yscale("log") |
---|
170 | plt.ylim(1, None) |
---|
171 | ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter()) |
---|
172 | else: |
---|
173 | plt.ylim(0, None) |
---|
174 | plt.xticks(procs) |
---|
175 | ax.legend(names) |
---|
176 | # fig.savefig("plots/" + machineName + name + ".png") |
---|
177 | plt.savefig("plots/" + machineName + name + ".pgf") |
---|
178 | fig.clf() |
---|
179 | |
---|
180 | # reset |
---|
181 | currBench = Bench.Unset |
---|
182 | currVariant = 0 |
---|