make_graphs.py 26 KB

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