make_graphs.py 27 KB

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