make_graphs.py 26 KB

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