diff --git a/allocator/bump_alloc/build.sh b/allocator/bump_alloc/build.sh index 26c1db0..52afb0f 100644 --- a/allocator/bump_alloc/build.sh +++ b/allocator/bump_alloc/build.sh @@ -1,2 +1,2 @@ cc -g -Wall -shared -o malloc-huge.so -mabi=purecap-benchmark -lpthread HugePage/bump_alloc.c -cc -g -Wall -shared -o malloc-regular.so -mabi=purecap-benchmark -lpthread Regular/bump_alloc.c \ No newline at end of file +cc -g -Wall -shared -o malloc-regular.so -mabi=purecap-benchmark -lpthread Regular/bump_alloc.c \ No newline at end of file diff --git a/benchmarks/analysis/.gitignore b/benchmarks/analysis/.gitignore new file mode 100644 index 0000000..4adb845 --- /dev/null +++ b/benchmarks/analysis/.gitignore @@ -0,0 +1 @@ +results/* \ No newline at end of file diff --git a/benchmarks/analysis/gen-graphs.py b/benchmarks/analysis/gen-graphs.py new file mode 100644 index 0000000..ee2dd6d --- /dev/null +++ b/benchmarks/analysis/gen-graphs.py @@ -0,0 +1,123 @@ +import re +import sys +import matplotlib.pyplot as plt +import numpy as np +import os +import json + +# Ensure the output directory exists +output_dir = 'graphs/matrixMultiply' + +def GetColumns(input_text): + # Split input text into lines + lines = input_text.strip().split('\n') + + # Extract headers + headers = re.split(r'\s+', lines[0].strip('#').strip()) + + # Initialize a dictionary to store values column-wise + columns = {header: [] for header in headers} + + # Extract values + for line in lines[1:]: + values = list(map(int, re.split(r'\s+', line.strip()))) + for header, value in zip(headers, values): + columns[header].append(value) + + return columns + +def strip_zeros(data_dict): + return {key: {k: v for k, v in value.items() if v != 0} for key, value in data_dict.items()} +def remove_empty_labels(data_dict): + return {key: value for key, value in data_dict.items() if value} + +def generate_grouped_bar_graphs(input_files, labels, grouping, output_dir, output_prefix, colors): + # Initialize a dictionary to store sums for each column across all files + group_sums = {} + + # Extract columns and calculate sums for each group + headers = None + for group_name, group_indices in grouping.items(): + group_sum = {label: {header: 0 for header in headers} for label in labels} if headers else {} + for index in group_indices: + with open(input_files[index], "r") as f: + columns = GetColumns(f.read()) + # if index == 3: + # print(columns) + if headers is None: + headers = list(columns.keys()) + group_sum = {label: {header: 0 for header in headers} for label in labels} + label = labels[index] + for header in headers: + # if index == 3: + # print(label) + # print(header) + group_sum[label][header] += sum(columns[header]) + group_sums[group_name] = remove_empty_labels(strip_zeros(group_sum)) + # if index == 3: + # print(group_sums[group_name]) + # print(group_name) + + # group_sums = remove_empty_labels(strip_zeros(group_sums[group_name])) + return group_sums + +def GenerateSumGraphs(data, output_dir): + + # Extracting datasets and metrics + datasets = list(data.keys()) # ['cheri,regular'] + metrics = list(data['cheri,regular']['cheri'].keys()) # All the metrics + + # Iterate over each metric to create an independent bar chart + for metric in metrics: + # Fetch values for 'cheri' and 'regular' configurations for each dataset + cheri_values = [data[dataset]['cheri'][metric] for dataset in datasets] + regular_values = [data[dataset]['regular'][metric] for dataset in datasets] + + # Plotting configuration + x = np.arange(len(datasets)) # Label locations + width = 0.35 # Width of the bars + + # Plotting + fig, ax = plt.subplots() + rects1 = ax.bar(x - width/2, cheri_values, width, label='Cheri') + rects2 = ax.bar(x + width/2, regular_values, width, label='Regular') + + # Labels and title + ax.set_xlabel('Benchmark Dataset Size') + ax.set_ylabel(f'Count of {metric}') + ax.set_title(f'Comparison of Cheri and Regular for {metric}') + ax.set_xticks(x) + ax.set_xticklabels(datasets, rotation=45, ha="right") + ax.legend() + + # Layout and save + fig.tight_layout() + filename = os.path.join(output_dir, f'matrixMultiply-{metric.replace("/", "_")}.png') + plt.savefig(filename) + plt.close(fig) # Close the figure after saving to avoid display overlap + + + +# Example usage +if __name__ == "__main__": + input_files = sys.argv[1:-5] # List of input files + labels = sys.argv[-5].split(",") # List of labels + print(sys.argv[-4]) + grouping = {group.split(":")[0]: list(map(int, group.split(":")[1].split(","))) for group in sys.argv[-4].split(";")} # Grouping info + colors = sys.argv[-3].split(",") # List of colors + output_dir = sys.argv[-2] # Output directory + output_prefix = sys.argv[-1] # Output file prefix + + group_sums = generate_grouped_bar_graphs(input_files, labels, grouping, output_dir, output_prefix, colors) + + # Make the result directory + os.makedirs(output_dir, exist_ok=True) + + # Save dataset + # Write the modified data to a new JSON file + with open('benchmark.json', 'w') as f: + json.dump(output_dir, f) + + # Generate group sum graphs + GenerateSumGraphs(group_sums, "") + diff --git a/benchmarks/analysis/run-benchmark.py b/benchmarks/analysis/run-benchmark.py new file mode 100644 index 0000000..dd6da14 --- /dev/null +++ b/benchmarks/analysis/run-benchmark.py @@ -0,0 +1,63 @@ +import paramiko +from scp import SCPClient +import os + +def ssh_execute_and_retrieve( + remote_host, remote_user, remote_password, + remote_program, remote_output_path, local_save_path +): + try: + # Create an SSH client + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + # Connect to the remote machine + print("Connecting to remote host...") + # ssh.connect(remote_host, username=remote_user, password=remote_password) + ssh.connect(remote_host, username=remote_user) + print("Connected successfully.") + + # Execute the remote program + print(f"Running remote program: {remote_program}") + stdin, stdout, stderr = ssh.exec_command(remote_program) + stdout.channel.recv_exit_status() # Wait for command to finish + + # Display the program's output + print("Program output:") + for line in stdout.readlines(): + print(line.strip()) + print("Program errors (if any):") + for line in stderr.readlines(): + print(line.strip()) + + # Use SCP to retrieve output files + print(f"Retrieving files from {remote_output_path} to {local_save_path}...") + with SCPClient(ssh.get_transport()) as scp: + scp.get(remote_output_path, local_path=local_save_path) + print(f"Files retrieved successfully to {local_save_path}.") + + except Exception as e: + print(f"An error occurred: {e}") + finally: + ssh.close() + print("Connection closed.") + +if __name__ == "__main__": + # Remote server details + remote_host = "192.0.0.3" # Replace with the remote host IP + remote_user = "akilan" # Replace with the remote username + remote_password = "" # Replace with the remote password + + # Program to execute and file paths + remote_program = "/path/to/your/program --option" # Command to run + remote_output_path = "/path/to/remote/output/*" # Path to the output files + local_save_path = "./downloaded_files" # Local folder to save the files + + # Create the local save path directory if it doesn't exist + os.makedirs(local_save_path, exist_ok=True) + + # Run the function + ssh_execute_and_retrieve( + remote_host, remote_user, remote_password, + remote_program, remote_output_path, local_save_path + )