From 979c59fadcbe75505dde0fece0fe66dd22fb173d Mon Sep 17 00:00:00 2001 From: jamessiddeley-amd Date: Wed, 18 Jun 2025 14:09:09 -0400 Subject: [PATCH] added progress printout in rocprof-compute profile (#727) * added progress printout for profiler * added comments and fixed readability * removed redundant newlines * moved format_time helper function to utils * removed tqdm and redundant time calc [ROCm/rocprofiler-compute commit: 036866fc120228c6cae5fc9cb372b0d2c605742e] --- .../rocprof_compute_profile/profiler_base.py | 27 +++++++++++++------ .../rocprofiler-compute/src/utils/utils.py | 13 +++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/projects/rocprofiler-compute/src/rocprof_compute_profile/profiler_base.py b/projects/rocprofiler-compute/src/rocprof_compute_profile/profiler_base.py index 9cc0ce44df..94236a06ca 100644 --- a/projects/rocprofiler-compute/src/rocprof_compute_profile/profiler_base.py +++ b/projects/rocprofiler-compute/src/rocprof_compute_profile/profiler_base.py @@ -32,7 +32,6 @@ from abc import ABC, abstractmethod from pathlib import Path import pandas as pd -from tqdm import tqdm import config from utils.logger import ( @@ -44,6 +43,7 @@ from utils.logger import ( ) from utils.utils import ( capture_subprocess_output, + format_time, gen_sysinfo, pc_sampling_prof, print_status, @@ -353,16 +353,24 @@ class RocProfCompute_Base: else print_status(msg + " (Roofline Only)") ) - # show status bar in error-only mode - disable_tqdm = True - if self.__args.loglevel >= logging.ERROR: - disable_tqdm = False - # Run profiling on each input file input_files = glob.glob(self.get_args().path + "/perfmon/*.txt") input_files.sort() - for fname in tqdm(input_files, disable=disable_tqdm): + total_runs = len(input_files) + total_profiling_time_so_far = 0 + avg_profiling_time = 0 + + for i, fname in enumerate(input_files): + run_number = i + 1 + if i > 0: + avg_profiling_time = total_profiling_time_so_far / i + time_left_seconds = (total_runs - run_number) * avg_profiling_time + time_left = format_time(time_left_seconds) + console_log(f"[Run {run_number}/{total_runs}][Approximate profiling time left: {time_left}]...") + else: + console_log(f"[Run {run_number}/{total_runs}][Approximate profiling time left: pending first measurement...]") + # Kernel filtering (in-place replacement) if not self.__args.kernel == None: success, output = capture_subprocess_output( @@ -421,6 +429,7 @@ class RocProfCompute_Base: format_rocprof_output=self.get_args().format_rocprof_output, ) end_run_prof = time.time() + actual_profiling_duration = end_run_prof - start_run_prof console_debug( "The time of run_prof of {} is {} m {} sec".format( fname, @@ -430,11 +439,12 @@ class RocProfCompute_Base: ) else: console_error("Profiler not supported") - + total_profiling_time_so_far += actual_profiling_duration if self.__pc_sampling == True and self.__profiler in ( "rocprofv3", "rocprofiler-sdk", ): + console_log(f"[Run {total_runs+1}/{total_runs+1}][PC sampling profile run]") start_run_prof = time.time() pc_sampling_prof( method=self.get_args().pc_sampling_method, @@ -444,6 +454,7 @@ class RocProfCompute_Base: rocprofiler_sdk_library_path=self.get_args().rocprofiler_sdk_library_path, ) end_run_prof = time.time() + pc_sampling_duration = end_run_prof - start_run_prof console_debug( "The time of pc sampling profiling is {} m {} sec".format( int((end_run_prof - start_run_prof) / 60), diff --git a/projects/rocprofiler-compute/src/utils/utils.py b/projects/rocprofiler-compute/src/utils/utils.py index 49375a6116..d5cc848827 100644 --- a/projects/rocprofiler-compute/src/utils/utils.py +++ b/projects/rocprofiler-compute/src/utils/utils.py @@ -1552,3 +1552,16 @@ def convert_metric_id_to_panel_idx(metric_id): return int(tokens[0]) * 100 + int(tokens[1]) else: raise Exception(f"Invalid metric id: {metric_id}") + +def format_time(seconds): + hours = int(seconds // 3600) + minutes = int((seconds % 3600) // 60) + secs = int(seconds % 60) + parts = [] + if hours > 0: + parts.append(f"{hours} hour{'s' if hours != 1 else ''}") + if minutes > 0: + parts.append(f"{minutes} minute{'s' if minutes != 1 else ''}") + if secs > 0 or not parts: + parts.append(f"{secs} second{'s' if secs != 1 else ''}") + return ', '.join(parts[:-1]) + (' and ' if len(parts) > 1 else '') + parts[-1]