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