[2f6a9391] | 1 | import os
|
---|
| 2 | import sys
|
---|
| 3 | import time
|
---|
[4912520] | 4 | import itertools
|
---|
[2f6a9391] | 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,
|
---|
[4912520] | 20 | 'font.size': 16
|
---|
[2f6a9391] | 21 | })
|
---|
[14e1053] | 22 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
|
---|
| 23 |
|
---|
| 24 | def sci_format(x, pos):
|
---|
| 25 | return '{:.1e}'.format(x).replace('+0', '')
|
---|
[2f6a9391] | 26 |
|
---|
| 27 | readfile = open(sys.argv[1], "r")
|
---|
| 28 |
|
---|
| 29 | machineName = ""
|
---|
| 30 |
|
---|
| 31 | if len(sys.argv) > 2:
|
---|
| 32 | machineName = sys.argv[2]
|
---|
| 33 |
|
---|
| 34 | # first line has num times per experiment
|
---|
| 35 | line = readfile.readline()
|
---|
| 36 | numTimes = int(line)
|
---|
| 37 |
|
---|
| 38 | # second line has processor args
|
---|
| 39 | line = readfile.readline()
|
---|
| 40 | procs = []
|
---|
| 41 | for val in line.split():
|
---|
| 42 | procs.append(int(val))
|
---|
| 43 |
|
---|
[d24b1985] | 44 | # 3rd line has number of variants
|
---|
[2f6a9391] | 45 | line = readfile.readline()
|
---|
| 46 | names = line.split()
|
---|
| 47 | numVariants = len(names)
|
---|
| 48 |
|
---|
| 49 | lines = (line.rstrip() for line in readfile) # All lines including the blank ones
|
---|
| 50 | lines = (line for line in lines if line) # Non-blank lines
|
---|
| 51 |
|
---|
[d24b1985] | 52 | class Bench(Enum):
|
---|
| 53 | Unset = 0
|
---|
| 54 | Contend = 1
|
---|
| 55 | Zero = 2
|
---|
| 56 | Barrier = 3
|
---|
| 57 | Churn = 4
|
---|
| 58 | Daisy_Chain = 5
|
---|
| 59 | Hot_Potato = 6
|
---|
| 60 | Pub_Sub = 7
|
---|
| 61 |
|
---|
[2f6a9391] | 62 | nameSet = False
|
---|
[d24b1985] | 63 | currBench = Bench.Unset # default val
|
---|
[2f6a9391] | 64 | count = 0
|
---|
| 65 | procCount = 0
|
---|
| 66 | currVariant = 0
|
---|
[14e1053] | 67 | experiment_duration = 10.0
|
---|
[d24b1985] | 68 | name = ""
|
---|
[14e1053] | 69 | title = ""
|
---|
[2f6a9391] | 70 | var_name = ""
|
---|
| 71 | sendData = [0.0 for j in range(numVariants)]
|
---|
| 72 | data = [[0.0 for i in range(len(procs))] for j in range(numVariants)]
|
---|
| 73 | bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)]
|
---|
| 74 | tempData = [0.0 for i in range(numTimes)]
|
---|
| 75 | for idx, line in enumerate(lines):
|
---|
| 76 | # print(line)
|
---|
| 77 |
|
---|
[d24b1985] | 78 | if currBench == Bench.Unset:
|
---|
| 79 | if line == "contend:":
|
---|
[14e1053] | 80 | name = "Channel_Contention"
|
---|
| 81 | title = "Channel Contention"
|
---|
[d24b1985] | 82 | currBench = Bench.Contend
|
---|
| 83 | elif line == "zero:":
|
---|
| 84 | name = "Zero"
|
---|
| 85 | currBench = Bench.Zero
|
---|
| 86 | elif line == "barrier:":
|
---|
| 87 | name = "Barrier"
|
---|
| 88 | currBench = Bench.Barrier
|
---|
| 89 | elif line == "churn:":
|
---|
| 90 | name = "Churn"
|
---|
| 91 | currBench = Bench.Churn
|
---|
| 92 | elif line == "daisy_chain:":
|
---|
| 93 | name = "Daisy_Chain"
|
---|
| 94 | currBench = Bench.Daisy_Chain
|
---|
| 95 | elif line == "hot_potato:":
|
---|
| 96 | name = "Hot_Potato"
|
---|
| 97 | currBench = Bench.Hot_Potato
|
---|
| 98 | elif line == "pub_sub:":
|
---|
| 99 | name = "Pub_Sub"
|
---|
| 100 | currBench = Bench.Pub_Sub
|
---|
| 101 | else:
|
---|
| 102 | print("Expected benchmark name")
|
---|
| 103 | print("Line: " + line)
|
---|
| 104 | sys.exit()
|
---|
[2f6a9391] | 105 | continue
|
---|
| 106 |
|
---|
| 107 | if line[0:5] == "cores":
|
---|
| 108 | continue
|
---|
| 109 |
|
---|
| 110 | if not nameSet:
|
---|
| 111 | nameSet = True
|
---|
| 112 | continue
|
---|
| 113 |
|
---|
| 114 | lineArr = line.split()
|
---|
[917e1fd] | 115 | tempData[count] = float(lineArr[-1]) / experiment_duration
|
---|
[2f6a9391] | 116 | count += 1
|
---|
| 117 | if count == numTimes:
|
---|
| 118 | currMedian = median( tempData )
|
---|
| 119 | data[currVariant][procCount] = currMedian
|
---|
| 120 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData))
|
---|
| 121 | bars[currVariant][0][procCount] = currMedian - lower
|
---|
| 122 | bars[currVariant][1][procCount] = upper - currMedian
|
---|
| 123 | count = 0
|
---|
| 124 | procCount += 1
|
---|
| 125 |
|
---|
| 126 | if procCount == len(procs):
|
---|
| 127 | procCount = 0
|
---|
| 128 | nameSet = False
|
---|
| 129 | currVariant += 1
|
---|
| 130 |
|
---|
| 131 | if currVariant == numVariants:
|
---|
[1803d4d] | 132 | fig, ax = plt.subplots(layout='constrained')
|
---|
[14e1053] | 133 | if title != "":
|
---|
| 134 | plt.title(title + " Benchmark")
|
---|
| 135 | title = ""
|
---|
| 136 | else:
|
---|
| 137 | plt.title(name + " Benchmark")
|
---|
| 138 | plt.ylabel("Throughput (channel operations per second)")
|
---|
[2f6a9391] | 139 | plt.xlabel("Cores")
|
---|
[14e1053] | 140 | ax.yaxis.set_major_formatter(ticks.FuncFormatter(sci_format))
|
---|
[2f6a9391] | 141 | for idx, arr in enumerate(data):
|
---|
[4912520] | 142 | plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) )
|
---|
[60f4919] | 143 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
|
---|
[14e1053] | 144 | # plt.yscale("log")
|
---|
[d24b1985] | 145 | # plt.ylim(1, None)
|
---|
| 146 | # ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter())
|
---|
| 147 | # else:
|
---|
| 148 | # plt.ylim(0, None)
|
---|
[2f6a9391] | 149 | plt.xticks(procs)
|
---|
| 150 | ax.legend(names)
|
---|
[d24b1985] | 151 | # fig.savefig("plots/" + machineName + name + ".png")
|
---|
| 152 | plt.savefig("plots/" + machineName + name + ".pgf")
|
---|
[2f6a9391] | 153 | fig.clf()
|
---|
| 154 |
|
---|
| 155 | # reset
|
---|
[d24b1985] | 156 | currBench = Bench.Unset
|
---|
[2f6a9391] | 157 | currVariant = 0
|
---|