From 11d67aff9c835d6aaabe26e8b2371465dae9f403 Mon Sep 17 00:00:00 2001 From: Nitin Garg Date: Thu, 3 Oct 2024 20:22:13 +0000 Subject: [PATCH] Add try-catch for exception during parsing Adds row with "ERROR" for all values rather than crashing during printing in CSV file. --- .../examples/dlio/parse_logs.py | 53 +++++++++++-------- .../testing_on_gke/examples/fio/parse_logs.py | 53 +++++++++++-------- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/perfmetrics/scripts/testing_on_gke/examples/dlio/parse_logs.py b/perfmetrics/scripts/testing_on_gke/examples/dlio/parse_logs.py index 58f76223cd..34e8d5df5b 100644 --- a/perfmetrics/scripts/testing_on_gke/examples/dlio/parse_logs.py +++ b/perfmetrics/scripts/testing_on_gke/examples/dlio/parse_logs.py @@ -288,29 +288,36 @@ def writeOutput( ) continue - new_row = ( - record_set["mean_file_size"], - record_set["num_files_train"], - total_size, - record_set["batch_size"], - scenario, - r["epoch"], - r["duration"], - r["train_au_percentage"], - r["train_throughput_samples_per_second"], - r["train_throughput_mb_per_second"], - r["throughput_over_local_ssd"], - r["lowest_memory"], - r["highest_memory"], - r["lowest_cpu"], - r["highest_cpu"], - r["pod_name"], - r["start"], - r["end"], - f'"{r["gcsfuse_mount_options"].strip()}"', # need to wrap in quotes to encapsulate commas in the value. - args.instance_id, - ) - rows.append(new_row) + try: + new_row = ( + record_set["mean_file_size"], + record_set["num_files_train"], + total_size, + record_set["batch_size"], + scenario, + r["epoch"], + r["duration"], + r["train_au_percentage"], + r["train_throughput_samples_per_second"], + r["train_throughput_mb_per_second"], + r["throughput_over_local_ssd"], + r["lowest_memory"], + r["highest_memory"], + r["lowest_cpu"], + r["highest_cpu"], + r["pod_name"], + r["start"], + r["end"], + f'"{r["gcsfuse_mount_options"].strip()}"', # need to wrap in quotes to encapsulate commas in the value. + args.instance_id, + ) + rows.append(new_row) + except Exception as e: + print( + f"Error while creating new output row for key={key}," + f" scenario={scenario}, epoch={i}, r={r}: {e}" + ) + rows.append((("ERROR",) * len(_HEADER))) export_to_csv(output_file_path=args.output_file, header=_HEADER, rows=rows) export_to_gsheet( diff --git a/perfmetrics/scripts/testing_on_gke/examples/fio/parse_logs.py b/perfmetrics/scripts/testing_on_gke/examples/fio/parse_logs.py index 8424a30adf..f4053fabb7 100644 --- a/perfmetrics/scripts/testing_on_gke/examples/fio/parse_logs.py +++ b/perfmetrics/scripts/testing_on_gke/examples/fio/parse_logs.py @@ -322,29 +322,36 @@ def writeOutput( ) continue - new_row = ( - record_set["mean_file_size"], - record_set["read_type"], - scenario, - r["epoch"], - r["duration"], - r["throughput_mb_per_second"], - r["IOPS"], - r["throughput_over_local_ssd"], - r["lowest_memory"], - r["highest_memory"], - r["lowest_cpu"], - r["highest_cpu"], - r["pod_name"], - r["start"], - r["end"], - f'"{r["gcsfuse_mount_options"].strip()}"', # need to wrap in quotes to encapsulate commas in the value. - r["blockSize"], - r["filesPerThread"], - r["numThreads"], - args.instance_id, - ) - rows.append(new_row) + try: + new_row = ( + record_set["mean_file_size"], + record_set["read_type"], + scenario, + r["epoch"], + r["duration"], + r["throughput_mb_per_second"], + r["IOPS"], + r["throughput_over_local_ssd"], + r["lowest_memory"], + r["highest_memory"], + r["lowest_cpu"], + r["highest_cpu"], + r["pod_name"], + r["start"], + r["end"], + f'"{r["gcsfuse_mount_options"].strip()}"', # need to wrap in quotes to encapsulate commas in the value. + r["blockSize"], + r["filesPerThread"], + r["numThreads"], + args.instance_id, + ) + rows.append(new_row) + except Exception as e: + print( + f"Error while creating new output row for key={key}," + f" scenario={scenario}, epoch={i}, r={r}: {e}" + ) + rows.append((("ERROR",) * len(_HEADER))) export_to_csv(output_file_path=args.output_file, header=_HEADER, rows=rows) export_to_gsheet(