github.com/badrootd/celestia-core@v0.0.0-20240305091328-aa4207a4b25d/scripts/qa/reporting/latency_plotter.py (about) 1 import sys 2 import os 3 from datetime import datetime 4 5 import matplotlib as mpl 6 import matplotlib.pyplot as plt 7 8 import numpy as np 9 import pandas as pd 10 11 release = 'v0.34.27' 12 13 if len(sys.argv) != 2: 14 print('Pls provide the raw.csv file') 15 exit() 16 else: 17 csvpath = sys.argv[1] 18 if not os.path.exists(csvpath): 19 print('Pls provide a valid the raw.csv file') 20 exit() 21 22 print(csvpath) 23 24 path = os.path.join('imgs') 25 26 #Load the CSV 27 csv = pd.read_csv(csvpath) 28 29 #Transform ns to s in the latency/duration 30 csv['duration_ns'] = csv['duration_ns'].apply(lambda x: x/10**9) 31 csv['block_time'] = csv['block_time'].apply(lambda x: x/10**9) 32 33 #Group by experiment 34 groups = csv.groupby(['experiment_id']) 35 36 #number of rows and columns in the graph 37 ncols = 2 if groups.ngroups > 1 else 1 38 nrows = int( np.ceil(groups.ngroups / ncols)) if groups.ngroups > 1 else 1 39 fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(6*ncols, 4*nrows), sharey=True) 40 fig.tight_layout(pad=5.0) 41 42 #Plot experiments as subplots 43 for (key,ax) in zip(groups.groups.keys(), [axes] if ncols == 1 else axes.flatten()): 44 group = groups.get_group(key) 45 ax.set_ylabel('latency (s)') 46 ax.set_xlabel('experiment time (s)') 47 ax.set_title(key) 48 ax.grid(True) 49 50 #Group by connection number and transaction rate 51 paramGroups = group.groupby(['connections','rate']) 52 for (subKey) in paramGroups.groups.keys(): 53 subGroup = paramGroups.get_group(subKey) 54 startTime = subGroup['block_time'].min() 55 print('exp ' + key + ' starts at ' + str(datetime.fromtimestamp(startTime)) + 'UTC') 56 subGroupMod = subGroup['block_time'].apply(lambda x: x - startTime) 57 58 (con,rate) = subKey 59 label = 'c='+str(con) + ' r='+ str(rate) 60 ax.scatter(subGroupMod, subGroup.duration_ns, label=label) 61 ax.legend() 62 63 #Save individual axes 64 extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) 65 fig.savefig(os.path.join(path,'e_'+key + '.png'), bbox_inches=extent) 66 67 fig.suptitle('200-node testnet experiments - ' + release) 68 69 # Save the figure with subplots 70 fig.savefig(os.path.join(path,'all_experiments.png')) 71 72 73 74 #Group by configuration 75 groups = csv.groupby(['connections','rate']) 76 77 #number of rows and columns in the graph 78 ncols = 2 if groups.ngroups > 1 else 1 79 nrows = int( np.ceil(groups.ngroups / ncols)) if groups.ngroups > 1 else 1 80 fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(6*ncols, 4*nrows), sharey=True) 81 fig.tight_layout(pad=5.0) 82 83 #Plot configurations as subplots 84 for (key,ax) in zip(groups.groups.keys(), [axes] if ncols == 1 else axes.flatten()): 85 group = groups.get_group(key) 86 ax.set_ylabel('latency (s)') 87 ax.set_xlabel('experiment time (s)') 88 ax.grid(True) 89 (con,rate) = key 90 label = 'c='+str(con) + ' r='+ str(rate) 91 ax.set_title(label) 92 93 #Group by experiment 94 paramGroups = group.groupby(['experiment_id']) 95 for (subKey) in paramGroups.groups.keys(): 96 subGroup = paramGroups.get_group(subKey) 97 startTime = subGroup['block_time'].min() 98 subGroupMod = subGroup['block_time'].apply(lambda x: x - startTime) 99 ax.scatter(subGroupMod, subGroup.duration_ns, label=label) 100 #ax.legend() 101 102 #Save individual axes 103 extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) 104 fig.savefig(os.path.join(path,'c'+str(con) + 'r'+ str(rate) + '.png'), bbox_inches=extent) 105 106 fig.suptitle('200-node testnet configurations - ' + release) 107 108 # Save the figure with subplots 109 fig.savefig(os.path.join(path,'all_configs.png')) 110 111 112 fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(6*ncols, 4*nrows), sharey=True) 113 fig.tight_layout(pad=5.0) 114 115 #Plot configurations as subplots 116 for (key,ax) in zip(groups.groups.keys(), [axes] if ncols == 1 else axes.flatten()): 117 group = groups.get_group(key) 118 ax.set_ylabel('latency (s)') 119 ax.set_xlabel('experiment time (s)') 120 ax.grid(True) 121 (con,rate) = key 122 label = 'c='+str(con) + ' r='+ str(rate) 123 ax.set_title(label) 124 125 #Group by experiment, but merge them as a single experiment 126 paramGroups = group.groupby(['experiment_id']) 127 for (subKey) in paramGroups.groups.keys(): 128 subGroup = paramGroups.get_group(subKey) 129 startTime = subGroup['block_time'].min() 130 subGroupMod = subGroup['block_time'].apply(lambda x: x - startTime) 131 ax.scatter(subGroupMod, subGroup.duration_ns, marker='o',c='#1f77b4') 132 133 #Save individual axes 134 extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) 135 (con,rate) = key 136 fig.savefig(os.path.join(path,'c'+str(con) + 'r'+ str(rate) + '_merged.png'), bbox_inches=extent) 137 138 plt.show()