Skip to content

Commit c0ec6fa

Browse files
committed
refactor performance table script: improve file handling and environment variable management
1 parent d084789 commit c0ec6fa

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scripts/create_perf_table.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,15 @@ def _write_csv(path: str, header: list[str], tasks_list: list[str], table: dict)
140140
logs_path = os.path.abspath(args.input)
141141
xlsx_path = os.path.abspath(args.output)
142142

143-
list_of_type_of_tasks = ["all", "mpi", "omp", "seq", "stl", "tbb"]
144-
145143
# For each perf_type (pipeline/task_run) store times per task
146144
result_tables = {"pipeline": {}, "task_run": {}}
147145
# Map task name -> category (threads|processes)
148146
task_categories = {}
149147
# Track tasks per category to split output
150148
tasks_by_category = {"threads": set(), "processes": set()}
151149

152-
logs_file = open(logs_path, "r")
153-
logs_lines = logs_file.readlines()
150+
with open(logs_path, "r") as logs_file:
151+
logs_lines = logs_file.readlines()
154152
for line in logs_lines:
155153
# Handle both old format: tasks/task_type/task_name:perf_type:time
156154
# and new format: namespace_task_type_enabled:perf_type:time
@@ -254,11 +252,19 @@ def _write_csv(path: str, header: list[str], tasks_list: list[str], table: dict)
254252
if not tasks_list:
255253
continue
256254

257-
cpu_num_env = os.environ.get("PPC_NUM_PROC")
258-
if cpu_num_env is None:
259-
raise EnvironmentError(
260-
"Required environment variable 'PPC_NUM_PROC' is not set."
261-
)
255+
# Use appropriate env var per category
256+
if category == "threads":
257+
cpu_num_env = os.environ.get("PPC_NUM_THREADS")
258+
if cpu_num_env is None:
259+
raise EnvironmentError(
260+
"Required environment variable 'PPC_NUM_THREADS' is not set."
261+
)
262+
else:
263+
cpu_num_env = os.environ.get("PPC_NUM_PROC")
264+
if cpu_num_env is None:
265+
raise EnvironmentError(
266+
"Required environment variable 'PPC_NUM_PROC' is not set."
267+
)
262268
cpu_num = int(cpu_num_env)
263269
cols = _columns_for_category(category)
264270

0 commit comments

Comments
 (0)