diff --git a/post_processing/investigateBenchmarkingTimerOutput.py b/post_processing/investigateBenchmarkingTimerOutput.py index 596a5464ff20dfacd40db45d3066184d4ef2367d..3a0144108fe2203ce347b00c1ed8c108e2db9fba 100644 --- a/post_processing/investigateBenchmarkingTimerOutput.py +++ b/post_processing/investigateBenchmarkingTimerOutput.py @@ -1,69 +1,75 @@ - # %% import sqlite3 import pandas as pd -import os -import matplotlib.pyplot as plt import warnings +import argparse -# %% -# Define colors -color1 = "#1F3B66" -color2 = "#C14C30" -color3 = "#4AA7A9" -color4 = "#EBAE65" -color5 = "#EBAE65" -color6 = "#36b700" -color7 = "#9d2c00" -color8 = "#c8c8c8" +def main(databasename: str, verbose: bool) -> None: + """ + Main function to process the benchmarking timer output from the SQLite database. -# %% -# Database configuration -GPUs_per_node = 4 # MareNostrum5 ACC has four GPUs per node -databasename = "/local/ab04unyc/mywalberla/build/benchmark-debug/apps/benchmarks/UniformGridCPU/cpu_benchmark.sqlite3" + Args: + databasename (str): Path to the SQLite database file. + verbose (bool): Flag to enable verbose output. + """ + # Database configuration + GPUs_per_node = 4 # MareNostrum5 ACC has four GPUs per node -# Connect to the database -conn = sqlite3.connect(databasename) -cursor = conn.cursor() -cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") -all_tables = cursor.fetchall() + # Connect to the database + conn = sqlite3.connect(databasename) + cursor = conn.cursor() + cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") + all_tables = cursor.fetchall() -# Extract table names -all_table_names = [str(t[0]) for t in all_tables] + # Extract table names + all_table_names = [str(t[0]) for t in all_tables] -# %% -# Debug output -all_table_names + # Debug output + if verbose: + print("Avalable table names in the database:", all_table_names) -# %% -# Load data from all tables -for table_name in all_table_names: - df = pd.read_sql(f"SELECT * FROM {table_name}", conn) - if 'full_df' in globals(): - full_df = pd.concat([full_df, df], ignore_index=True) - else: - full_df = df.copy() + # Load data from all tables + for table_name in all_table_names: + df = pd.read_sql(f"SELECT * FROM {table_name}", conn) + if 'full_df' in globals(): + full_df = pd.concat([full_df, df], ignore_index=True) + else: + full_df = df.copy() -# Debug output -df.columns + # Debug output + if verbose: + print("Available columns in the database:", df.columns) + print(f"Number of rows in {all_table_names}: {len(full_df)}") -# %% -# Extract unique timer names and properties -timer_columns = df.filter(like='Timer') -timer_names = list(set(col.split('_')[1] for col in timer_columns.columns)) -properties = list(set(col.split('_')[2] for col in timer_columns.columns)) + # Extract unique timer names and properties + timer_columns = df.filter(like='Timer') + timer_names = list(set(col.split('_')[1] for col in timer_columns.columns)) + properties = list(set(col.split('_')[2] for col in timer_columns.columns)) + + # Create a new dataframe with properties as rows and timer names as columns + grouped_timers = pd.DataFrame(columns=properties, index=timer_names) -# Create a new dataframe with properties as rows and timer names as columns -grouped_timers = pd.DataFrame(columns=properties, index=timer_names) + # Fill the new dataframe with the corresponding values + for timer in timer_names: + for prop in properties: + timer_name = f'Timer_{timer}_{prop}' + try: + grouped_timers.at[timer, prop] = timer_columns[timer_name].iloc[0] + except KeyError: + warnings.warn(f"{timer_name} not found in timer_columns") + + # Display the grouped timers + if verbose: + print(f"Processing database file: {databasename}") + else: + print(f"Processing database file: {databasename.split('/')[-1]}") + print(grouped_timers) -# Fill the new dataframe with the corresponding values -for timer in timer_names: - for prop in properties: - timer_name = f'Timer_{timer}_{prop}' - try: - grouped_timers.at[timer, prop] = timer_columns[timer_name].iloc[0] - except KeyError: - warnings.warn(f"{timer_name} not found in timer_columns") +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Process benchmarking timer output from an SQLite database.") + parser.add_argument("databasename", type=str, help="Path to the SQLite database file") + parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output") + + args = parser.parse_args() -# Display the grouped timers -grouped_timers \ No newline at end of file + main(args.databasename, args.verbose) \ No newline at end of file