import os import json import pandas as pd from pandas.core.ops import methods import seaborn as sns import matplotlib.pyplot as plt x_label = "Copy Type" y_label = "Time in Microseconds" var_label = "Configuration" types = ["intersock-n0ton4", "internode-n0ton1"] types_nice = ["Inter-Socket Copy", "Inter-Node Copy"] copy_methods = ["dstcopy", "srccopy", "xcopy"] copy_methods_nice = [ "Engine on DST-Node", "Engine on SRC-Node", "Cross-Copy / Both Engines" ] data = { x_label : types_nice, copy_methods_nice[0] : [], copy_methods_nice[1] : [], copy_methods_nice[2] : [] } def index_from_element(value,array): for (idx,val) in enumerate(array): if val == value: return idx return 0 # Function to load and process the JSON file for the new benchmark def load_and_process_copy_json(file_path, method_label): with open(file_path, 'r') as file: data = json.load(file) # Extracting time from JSON structure if method_label == "xcopy": # For xcopy method, add times from two entries and divide by 4 time_entry1 = data["list"][0]["report"]["time"]["combined_avg"] time_entry2 = data["list"][1]["report"]["time"]["combined_avg"] time_microseconds = (time_entry1 + time_entry2) / 4 else: # For other methods, use the time from the single entry time_microseconds = data["list"][0]["report"]["time"]["combined_avg"] return time_microseconds # Function to plot the graph for the new benchmark def plot_copy_graph(file_paths, method_label): times = [] for file_path in file_paths: # Load and process JSON file for the new benchmark time_microseconds = load_and_process_copy_json(file_path, method_label) times.append(time_microseconds) method_index = index_from_element(method_label,copy_methods) method_nice = copy_methods_nice[method_index] data[method_nice] = times # Main function to iterate over files and create plots for the new benchmark def main(): folder_path = "benchmark-results/cross-copy-bench/" # Replace with the actual path to your folder for method_label in copy_methods: copy_file_paths = [os.path.join(folder_path, f"{method_label}-{type_label}-1mib-4e.json") for type_label in types] plot_copy_graph(copy_file_paths, method_label) df = pd.DataFrame(data) dfm = pd.melt(df, id_vars=x_label, var_name=var_label, value_name=y_label) sns.catplot(x=x_label, y=y_label, hue=var_label, data=dfm, kind='bar', height=5, aspect=1, palette="viridis") plt.savefig(os.path.join(folder_path, "plot-perf-enginelocation.png")) plt.show() if __name__ == "__main__": main()