[2f6a9391] | 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 | |
---|
| 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 | |
---|
| 21 | readfile = open(sys.argv[1], "r") |
---|
| 22 | |
---|
| 23 | machineName = "" |
---|
| 24 | |
---|
| 25 | if len(sys.argv) > 2: |
---|
| 26 | machineName = sys.argv[2] |
---|
| 27 | |
---|
| 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 | |
---|
[d24b1985] | 38 | # 3rd line has number of variants |
---|
[2f6a9391] | 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 | |
---|
[d24b1985] | 46 | class Bench(Enum): |
---|
| 47 | Unset = 0 |
---|
| 48 | Contend = 1 |
---|
| 49 | Zero = 2 |
---|
| 50 | Barrier = 3 |
---|
| 51 | Churn = 4 |
---|
| 52 | Daisy_Chain = 5 |
---|
| 53 | Hot_Potato = 6 |
---|
| 54 | Pub_Sub = 7 |
---|
| 55 | |
---|
[2f6a9391] | 56 | nameSet = False |
---|
[d24b1985] | 57 | currBench = Bench.Unset # default val |
---|
[2f6a9391] | 58 | count = 0 |
---|
| 59 | procCount = 0 |
---|
| 60 | currVariant = 0 |
---|
[d24b1985] | 61 | name = "" |
---|
[2f6a9391] | 62 | var_name = "" |
---|
| 63 | sendData = [0.0 for j in range(numVariants)] |
---|
| 64 | data = [[0.0 for i in range(len(procs))] for j in range(numVariants)] |
---|
| 65 | bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)] |
---|
| 66 | tempData = [0.0 for i in range(numTimes)] |
---|
| 67 | for idx, line in enumerate(lines): |
---|
| 68 | # print(line) |
---|
| 69 | |
---|
[d24b1985] | 70 | if currBench == Bench.Unset: |
---|
| 71 | if line == "contend:": |
---|
| 72 | name = "Contend" |
---|
| 73 | currBench = Bench.Contend |
---|
| 74 | elif line == "zero:": |
---|
| 75 | name = "Zero" |
---|
| 76 | currBench = Bench.Zero |
---|
| 77 | elif line == "barrier:": |
---|
| 78 | name = "Barrier" |
---|
| 79 | currBench = Bench.Barrier |
---|
| 80 | elif line == "churn:": |
---|
| 81 | name = "Churn" |
---|
| 82 | currBench = Bench.Churn |
---|
| 83 | elif line == "daisy_chain:": |
---|
| 84 | name = "Daisy_Chain" |
---|
| 85 | currBench = Bench.Daisy_Chain |
---|
| 86 | elif line == "hot_potato:": |
---|
| 87 | name = "Hot_Potato" |
---|
| 88 | currBench = Bench.Hot_Potato |
---|
| 89 | elif line == "pub_sub:": |
---|
| 90 | name = "Pub_Sub" |
---|
| 91 | currBench = Bench.Pub_Sub |
---|
| 92 | else: |
---|
| 93 | print("Expected benchmark name") |
---|
| 94 | print("Line: " + line) |
---|
| 95 | sys.exit() |
---|
[2f6a9391] | 96 | continue |
---|
| 97 | |
---|
| 98 | if line[0:5] == "cores": |
---|
| 99 | continue |
---|
| 100 | |
---|
| 101 | if not nameSet: |
---|
| 102 | nameSet = True |
---|
| 103 | continue |
---|
| 104 | |
---|
| 105 | lineArr = line.split() |
---|
| 106 | tempData[count] = float(lineArr[-1]) |
---|
| 107 | count += 1 |
---|
| 108 | if count == numTimes: |
---|
| 109 | currMedian = median( tempData ) |
---|
| 110 | data[currVariant][procCount] = currMedian |
---|
| 111 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData)) |
---|
| 112 | bars[currVariant][0][procCount] = currMedian - lower |
---|
| 113 | bars[currVariant][1][procCount] = upper - currMedian |
---|
| 114 | count = 0 |
---|
| 115 | procCount += 1 |
---|
| 116 | |
---|
| 117 | if procCount == len(procs): |
---|
| 118 | procCount = 0 |
---|
| 119 | nameSet = False |
---|
| 120 | currVariant += 1 |
---|
| 121 | |
---|
| 122 | if currVariant == numVariants: |
---|
| 123 | fig, ax = plt.subplots() |
---|
[d24b1985] | 124 | plt.title(name + " Benchmark") |
---|
| 125 | plt.ylabel("Throughput (channel operations)") |
---|
[2f6a9391] | 126 | plt.xlabel("Cores") |
---|
| 127 | for idx, arr in enumerate(data): |
---|
| 128 | plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker='o' ) |
---|
[d24b1985] | 129 | |
---|
[2f6a9391] | 130 | plt.yscale("log") |
---|
[d24b1985] | 131 | # plt.ylim(1, None) |
---|
| 132 | # ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter()) |
---|
| 133 | # else: |
---|
| 134 | # plt.ylim(0, None) |
---|
[2f6a9391] | 135 | plt.xticks(procs) |
---|
| 136 | ax.legend(names) |
---|
[d24b1985] | 137 | # fig.savefig("plots/" + machineName + name + ".png") |
---|
| 138 | plt.savefig("plots/" + machineName + name + ".pgf") |
---|
[2f6a9391] | 139 | fig.clf() |
---|
| 140 | |
---|
| 141 | # reset |
---|
[d24b1985] | 142 | currBench = Bench.Unset |
---|
[2f6a9391] | 143 | currVariant = 0 |
---|