make_graphs.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import json
  5. from math import sqrt
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. from scipy.optimize import curve_fit
  9. from contextlib import contextmanager
  10. PLOT_OPTIONS = {
  11. "workload": {
  12. "all": {
  13. "legend": 'Covert Security, Workload: "all"',
  14. "marker": '^',
  15. "color": "red"
  16. },
  17. "half": {
  18. "legend": 'Covert Security, Workload: "half"',
  19. "marker": 'X',
  20. "color": "green"
  21. },
  22. "no": {
  23. "legend": 'Covert Security, Workload: "no"',
  24. "marker": '*',
  25. "color": "blue"
  26. },
  27. "hbcall": {
  28. "legend": 'HBC Security, Workload: "all"',
  29. "marker": '^',
  30. "color": "red"
  31. },
  32. "hbchalf": {
  33. "legend": 'HBC Security, Workload: "half"',
  34. "marker": 'X',
  35. "color": "green"
  36. },
  37. "hbcno": {
  38. "legend": 'HBC Security, Workload: "no"',
  39. "marker": '*',
  40. "color": "blue"
  41. }
  42. },
  43. "numServers": {
  44. 2: {
  45. "legend": "2 servers",
  46. "marker": '^',
  47. "color": "red"
  48. },
  49. 3: {
  50. "legend": "3 servers",
  51. "marker": 'X',
  52. "color": "blue"
  53. },
  54. 4: {
  55. "legend": "4 servers",
  56. "marker": '*',
  57. "color": "green"
  58. },
  59. 5: {
  60. "legend": "5 servers",
  61. "marker": 'h',
  62. "color": "orange"
  63. }
  64. },
  65. "numClients": {
  66. 5: {
  67. "legend": "5 clients",
  68. "marker": "^",
  69. "color": "red"
  70. },
  71. 10: {
  72. "legend": "10 clients",
  73. "marker": "v",
  74. "color": "green"
  75. },
  76. 15: {
  77. "legend": "15 clients",
  78. "marker": ">",
  79. "color": "blue"
  80. },
  81. 20: {
  82. "legend": "20 clients",
  83. "marker": "<",
  84. "color": "orange"
  85. },
  86. 25: {
  87. "legend": "25 clients",
  88. "marker": "X",
  89. "color": "magenta"
  90. },
  91. 30: {
  92. "legend": "30 clients",
  93. "marker": "*",
  94. "color": "pink"
  95. },
  96. 40: {
  97. "legend": "40 clients",
  98. "marker": "h",
  99. "color": "cyan"
  100. },
  101. 50: {
  102. "legend": "50 clients",
  103. "marker": ".",
  104. "color": "black"
  105. }
  106. },
  107. "lambda": {
  108. 40: {
  109. "legend": "Lambda: 40",
  110. "marker": "^",
  111. "color": "red"
  112. },
  113. 50: {
  114. "legend": "Lambda: 50",
  115. "marker": "X",
  116. "color": "green"
  117. },
  118. 64: {
  119. "legend": "Lambda: 64",
  120. "marker": "*",
  121. "color": "blue"
  122. }
  123. }
  124. }
  125. ##
  126. # This functionality allows us to temporarily change our working directory
  127. #
  128. # @input newdir - the new directory (relative to our current position) we want to be in
  129. @contextmanager
  130. def cd(newdir, makenew):
  131. prevdir = os.getcwd()
  132. directory = os.path.expanduser(newdir)
  133. if not os.path.exists(directory) and makenew:
  134. os.makedirs(directory)
  135. os.chdir(directory)
  136. try:
  137. yield
  138. finally:
  139. os.chdir(prevdir)
  140. def genericCube(x, a, b, c, d):
  141. return a * (x * x * x) + b * (x * x) + c * x + d
  142. def readData(dataDirectory):
  143. serverData = {}
  144. clientData = {}
  145. realDirectory = os.path.expanduser(dataDirectory)
  146. for test in os.listdir(realDirectory):
  147. if not test.startswith('.') and not test.endswith('.tar.gz') and test.find("default") == -1:
  148. testParts = test.split("-")
  149. if not testParts[0] in serverData:
  150. serverData[testParts[0]] = {}
  151. if not testParts[0] in clientData:
  152. clientData[testParts[0]] = {}
  153. if not testParts[1] in serverData[testParts[0]]:
  154. serverData[testParts[0]][testParts[1]] = {}
  155. if not testParts[1] in clientData[testParts[0]]:
  156. clientData[testParts[0]][testParts[1]] = {}
  157. if not testParts[2] in serverData[testParts[0]][testParts[1]]:
  158. serverData[testParts[0]][testParts[1]][testParts[2]] = {}
  159. if not testParts[2] in clientData[testParts[0]][testParts[1]]:
  160. clientData[testParts[0]][testParts[1]][testParts[2]] = {}
  161. if not testParts[3] in serverData[testParts[0]][testParts[1]][testParts[2]]:
  162. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]] = {}
  163. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_wall'] = []
  164. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_cpu'] = []
  165. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_recv'] = []
  166. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_sent'] = []
  167. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_total'] = []
  168. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_wall'] = []
  169. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_cpu'] = []
  170. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_recv'] = []
  171. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_sent'] = []
  172. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_total'] = []
  173. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_wall'] = []
  174. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_cpu'] = []
  175. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_recv'] = []
  176. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_sent'] = []
  177. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_total'] = []
  178. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_wall'] = []
  179. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_cpu'] = []
  180. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_recv'] = []
  181. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_sent'] = []
  182. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_total'] = []
  183. if not testParts[3] in clientData[testParts[0]][testParts[1]][testParts[2]]:
  184. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]] = {}
  185. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_wall'] = []
  186. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_cpu'] = []
  187. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_recv'] = []
  188. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_sent'] = []
  189. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_total'] = []
  190. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_wall'] = []
  191. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_cpu'] = []
  192. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_recv'] = []
  193. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_sent'] = []
  194. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_total'] = []
  195. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_wall'] = []
  196. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_cpu'] = []
  197. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_recv'] = []
  198. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_sent'] = []
  199. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_total'] = []
  200. for test in os.listdir(realDirectory):
  201. if not test.startswith('.') and not test.endswith('.tar.gz') and test.find("default") == -1:
  202. testParts = test.split("-")
  203. for whichEntity in os.listdir(os.path.join(realDirectory, test)):
  204. if whichEntity.startswith('s') or whichEntity.startswith('d'):
  205. try:
  206. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'overallEpoch.out')), 'r') as overallEpochFile:
  207. for line in overallEpochFile:
  208. lineParts = line.rstrip().split(',')
  209. wallTime = float(lineParts[0])
  210. cpuTime = float(lineParts[1])
  211. dataRecv = float(lineParts[2])
  212. dataSent = float(lineParts[3])
  213. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_wall'].append(wallTime)
  214. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_cpu'].append(cpuTime)
  215. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_recv'].append(dataRecv)
  216. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_sent'].append(dataSent)
  217. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['overall_epoch_total'].append(dataRecv + dataSent)
  218. except FileNotFoundError as e:
  219. pass
  220. try:
  221. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'epochUp.out')), 'r') as epochUpFile:
  222. for line in epochUpFile:
  223. lineParts = line.rstrip().split(',')
  224. wallTime = float(lineParts[0])
  225. cpuTime = float(lineParts[1])
  226. dataRecv = float(lineParts[2])
  227. dataSent = float(lineParts[3])
  228. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_wall'].append(wallTime)
  229. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_cpu'].append(cpuTime)
  230. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_recv'].append(dataRecv)
  231. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_sent'].append(dataSent)
  232. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_up_total'].append(dataRecv + dataSent)
  233. except FileNotFoundError as e:
  234. pass
  235. try:
  236. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'epochDown.out')), 'r') as epochDownFile:
  237. for line in epochDownFile:
  238. lineParts = line.rstrip().split(',')
  239. wallTime = float(lineParts[0])
  240. cpuTime = float(lineParts[1])
  241. dataRecv = float(lineParts[2])
  242. dataSent = float(lineParts[3])
  243. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_wall'].append(wallTime)
  244. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_cpu'].append(cpuTime)
  245. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_recv'].append(dataRecv)
  246. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_sent'].append(dataSent)
  247. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['epoch_down_total'].append(dataRecv + dataSent)
  248. except FileNotFoundError as e:
  249. pass
  250. try:
  251. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'voteUpdate.out')), 'r') as voteUpdateFile:
  252. for line in voteUpdateFile:
  253. lineParts = line.rstrip().split(',')
  254. wallTime = float(lineParts[0])
  255. cpuTime = float(lineParts[1])
  256. dataRecv = float(lineParts[2])
  257. dataSent = float(lineParts[3])
  258. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_wall'].append(wallTime)
  259. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_cpu'].append(cpuTime)
  260. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_recv'].append(dataRecv)
  261. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_sent'].append(dataSent)
  262. serverData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_update_total'].append(dataRecv + dataSent)
  263. except FileNotFoundError as e:
  264. pass
  265. elif whichEntity.startswith('c'):
  266. try:
  267. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'vote.out')), 'r') as repVerifierFile:
  268. for line in repVerifierFile:
  269. lineParts = line.rstrip().split(',')
  270. wallTime = float(lineParts[0])
  271. cpuTime = float(lineParts[1])
  272. dataRecv = float(lineParts[2])
  273. dataSent = float(lineParts[3])
  274. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_wall'].append(wallTime)
  275. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_cpu'].append(cpuTime)
  276. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_recv'].append(dataRecv)
  277. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_sent'].append(dataSent)
  278. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['vote_total'].append(dataRecv + dataSent)
  279. except FileNotFoundError as e:
  280. pass
  281. try:
  282. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'repProver.out')), 'r') as repProverFile:
  283. for line in repProverFile:
  284. lineParts = line.rstrip().split(',')
  285. if not ('*' in lineParts[0]):
  286. wallTime = float(lineParts[0])
  287. cpuTime = float(lineParts[1])
  288. dataRecv = float(lineParts[2])
  289. dataSent = float(lineParts[3])
  290. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_wall'].append(wallTime)
  291. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_cpu'].append(cpuTime)
  292. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_recv'].append(dataRecv)
  293. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_sent'].append(dataSent)
  294. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_prove_total'].append(dataRecv + dataSent)
  295. except FileNotFoundError as e:
  296. pass
  297. try:
  298. with open(os.path.expanduser(os.path.join(realDirectory, test, whichEntity, 'repVerifier.out')), 'r') as repVerifierFile:
  299. for line in repVerifierFile:
  300. lineParts = line.rstrip().split(',')
  301. wallTime = float(lineParts[0])
  302. cpuTime = float(lineParts[1])
  303. dataRecv = float(lineParts[2])
  304. dataSent = float(lineParts[3])
  305. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_wall'].append(wallTime)
  306. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_cpu'].append(cpuTime)
  307. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_recv'].append(dataRecv)
  308. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_sent'].append(dataSent)
  309. clientData[testParts[0]][testParts[1]][testParts[2]][testParts[3]]['rep_verify_total'].append(dataRecv + dataSent)
  310. except FileNotFoundError as e:
  311. pass
  312. return serverData, clientData
  313. def plotComparison(data, dataParts, xVariable, lineVariable, whichGraph, **kwargs):
  314. z_star = kwargs['z_star'] if 'z_star' in kwargs else 1.96
  315. title = kwargs['title'] if 'title' in kwargs else ''
  316. xLabel = kwargs['xLabel'] if 'xLabel' in kwargs else ''
  317. yLabel = kwargs['yLabel'] if 'yLabel' in kwargs else ''
  318. yUnit = kwargs['yUnit'] if 'yUnit' in kwargs else ''
  319. fileNameStr = kwargs['fileNameStr'] if 'fileNameStr' in kwargs else f"basic-{xVariable}-{lineVariable}-{whichGraph}"
  320. legendLoc = kwargs['legendLoc'] if 'legendLoc' in kwargs else "best"
  321. legendBBoxAnchor = kwargs['legendBBoxAnchor'] if 'legendBBoxAnchor' in kwargs else (0, 1)
  322. extraFit = kwargs['extraFit'] if 'extraFit' in kwargs else False
  323. loglog = kwargs['loglog'] if 'loglog' in kwargs else False
  324. yLim = kwargs['yLim'] if 'yLim' in kwargs else False
  325. aspect = kwargs['aspect'] if 'aspect' in kwargs else None
  326. ignoreWorkload = kwargs['ignoreWorkload'] if 'ignoreWorkload' in kwargs else False
  327. fig = plt.figure()
  328. ax = fig.gca()
  329. whichLines = 0
  330. lineSelection = []
  331. legendStart = ""
  332. legendEnd = ""
  333. if lineVariable == 'workload':
  334. whichLines = 0
  335. lineSelection = [str(x) for x in data.keys() if x != "rep" and x != "vote"]
  336. lineSelection.sort()
  337. ignoreWorkload = False
  338. elif lineVariable == 'numServers':
  339. whichLines = 1
  340. lineSelection = [int(x) for x in data['no'].keys()]
  341. lineSelection.sort()
  342. elif lineVariable == 'numClients':
  343. whichLines = 2
  344. lineSelection = [int(x) for x in data['all']['2'].keys()]
  345. lineSelection.sort()
  346. elif lineVariable == 'lambda':
  347. whichLines = 3
  348. lineSelection = [int(x) for x in data['all']['2']['5'].keys()]
  349. lineSelection.sort()
  350. whichX = 0
  351. xSelection = []
  352. if xVariable == 'workload':
  353. whichX = 0
  354. xSelection = data.keys()
  355. ignoreWorkload = False
  356. elif xVariable == 'numServers':
  357. whichX = 1
  358. xSelection = [int(x) for x in data['all'].keys()]
  359. xSelection.sort()
  360. elif xVariable == 'numClients':
  361. whichX = 2
  362. xSelection = [int(x) for x in data['all']['2'].keys()]
  363. xSelection.sort()
  364. elif xVariable == 'lambda':
  365. whichX = 3
  366. xSelection = [int(x) for x in data['all']['2']['5'].keys()]
  367. xSelection.sort()
  368. for selection in lineSelection:
  369. xs = []
  370. xTicks = []
  371. ys = []
  372. additionalYs = []
  373. yErrs = []
  374. additionalYErrs = []
  375. legend = PLOT_OPTIONS[lineVariable][selection]['legend']
  376. marker = PLOT_OPTIONS[lineVariable][selection]['marker']
  377. color = PLOT_OPTIONS[lineVariable][selection]['color']
  378. dataParts[whichLines] = str(selection)
  379. for x in xSelection:
  380. dataParts[whichX] = str(x)
  381. try:
  382. curr_data = []
  383. if ignoreWorkload == False:
  384. curr_data = data[dataParts[0]][dataParts[1]][dataParts[2]][dataParts[3]][whichGraph]
  385. else:
  386. for workload in ['all', 'half', 'no']:
  387. try:
  388. curr_data.extend(data[workload][dataParts[1]][dataParts[2]][dataParts[3]][whichGraph])
  389. except KeyError as e:
  390. pass
  391. if len(curr_data) == 0:
  392. continue
  393. dividing_factor = 1
  394. if yUnit == 'KB':
  395. dividing_factor = 1024.0
  396. if yUnit == 'MB':
  397. dividing_factor = 1024.0 * 1024.0
  398. if lineVariable == 'numServers':
  399. dividing_factor = dividing_factor * selection
  400. else:
  401. dividing_factor = dividing_factor * int(dataParts[1])
  402. used_data = [x / dividing_factor for x in curr_data]
  403. mean = np.mean(used_data)
  404. std = np.std(used_data)
  405. sqrt_len = sqrt(len(used_data))
  406. xs.append(x)
  407. ys.append(mean)
  408. yErrs.append(z_star * std / sqrt_len)
  409. except KeyError as e:
  410. pass
  411. if len(xs) > 1:
  412. line, _, _ = ax.errorbar(xs, ys, yerr=yErrs, capsize=7.0, label=legend, marker=marker, linestyle='-', color=color)
  413. if extraFit:
  414. popt, pcov = curve_fit(genericCube, xs, ys)
  415. beyondXs = np.linspace(xs[-1], 100, 50)
  416. ax.plot(beyondXs, genericCube(beyondXs, *popt), linestyle='--', color=color)
  417. ax.set_title(title, fontsize='x-large')
  418. ax.set_xlabel(xLabel, fontsize='large')
  419. ax.set_ylabel(yLabel, fontsize='large')
  420. if loglog:
  421. ax.set_yscale("log")
  422. ax.set_xscale("log")
  423. else:
  424. bottom, top = ax.get_ylim()
  425. bottom = (0 if bottom > 0 else bottom)
  426. ax.set_ylim(bottom=bottom)
  427. if top > 100000:
  428. yTickLabels = ['{:2g}'.format(x) for x in ax.get_yticks().tolist()]
  429. ax.set_yticklabels(yTickLabels)
  430. if yLim:
  431. ax.set_ylim(bottom=yLim[0], top=yLim[1])
  432. if aspect:
  433. ax.set_aspect(aspect, adjustable='box')
  434. legend = ax.legend(loc=legendLoc, bbox_to_anchor=legendBBoxAnchor, fontsize='large')
  435. with cd('../plt/', True):
  436. fig.savefig(f"{fileNameStr}.pdf", bbox_inches='tight')
  437. plt.close(fig)
  438. def main(dataDirectory, plotOptionsFile):
  439. serverData, clientData = readData(dataDirectory)
  440. plotOptions = []
  441. with open(plotOptionsFile, 'r') as options:
  442. plotOptions = json.load(options)
  443. for option in plotOptions:
  444. try:
  445. data = serverData if (option['data'].lower() == "server" or option['data'].lower() == "s") else clientData
  446. dataParts = option['dataParts']
  447. xVariable = option['xVariable']
  448. lineVariable = option['lineVariable']
  449. whichGraph = option['whichGraph']
  450. except KeyError as e:
  451. continue
  452. kwargs = {}
  453. if "z_star" in option:
  454. kwargs["z_star"] = option["z_star"]
  455. if "title" in option:
  456. kwargs["title"] = option["title"]
  457. if "xLabel" in option:
  458. kwargs["xLabel"] = option["xLabel"]
  459. if "yLabel" in option:
  460. kwargs["yLabel"] = option["yLabel"]
  461. if "yUnit" in option:
  462. kwargs["yUnit"] = option["yUnit"]
  463. if "extraFit" in option:
  464. kwargs["extraFit"] = option["extraFit"]
  465. if "fileNameStr" in option:
  466. kwargs["fileNameStr"] = option["fileNameStr"]
  467. if "legendLoc" in option:
  468. kwargs["legendLoc"] = option["legendLoc"]
  469. if "legendBBoxAnchor" in option:
  470. anchor = (option["legendBBoxAnchor"][0], option["legendBBoxAnchor"][1])
  471. kwargs["legendBBoxAnchor"] = anchor
  472. if "loglog" in option:
  473. kwargs["loglog"] = option["loglog"]
  474. if "yLim" in option:
  475. kwargs["yLim"] = option["yLim"]
  476. if "aspect" in option:
  477. kwargs["aspect"] = option["aspect"]
  478. if "ignoreWorkload" in option:
  479. kwargs["ignoreWorkload"] = option["ignoreWorkload"]
  480. plotComparison(data, dataParts, xVariable, lineVariable, whichGraph, **kwargs)
  481. if __name__ == "__main__":
  482. main("../out", "../plt/plots.json")