From 2af9d882a8b4351732a06cc4dca124e38a4e0bcd Mon Sep 17 00:00:00 2001 From: fanglanyue Date: Wed, 16 Jul 2025 09:01:56 +0800 Subject: [PATCH] compare judge table exist before query --- .../profiling_parser/npu_profiling_db_parser.py | 14 ++++++++++++++ .../profiling_parser/overall_metrics_parser.py | 4 +++- profiler/msprof_analyze/prof_common/constant.py | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/npu_profiling_db_parser.py b/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/npu_profiling_db_parser.py index 065a82aab6..b68029a57e 100644 --- a/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/npu_profiling_db_parser.py +++ b/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/npu_profiling_db_parser.py @@ -123,6 +123,8 @@ class NPUProfilingDbParser: raise RuntimeError(f"Invalid Step Id: {self.step_id}, please choose from the valid steps: {valid_step}") def _query_torch_op_data(self): + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_PYTORCH_API): + return if any((self._enable_memory_compare, self._enable_operator_compare, self._enable_profiling_compare, self._enable_api_compare)): sql = self.pytorch_api_sql.format( @@ -134,6 +136,8 @@ class NPUProfilingDbParser: self.result_data.update_torch_op_data(FrameworkApiBean(data)) def _query_compute_op_data(self): + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_COMPUTE_TASK_INFO): + return if any((self._enable_operator_compare, self._args.max_kernel_num, self._enable_profiling_compare, self._enable_kernel_compare)): sql = """ @@ -207,6 +211,8 @@ class NPUProfilingDbParser: self.result_data.update_kernel_details(kernels_dict) def _query_comm_op_data(self): + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_COMMUNICATION_OP): + return if self._enable_communication_compare or self._enable_profiling_compare: sql = """ SELECT @@ -240,6 +246,8 @@ class NPUProfilingDbParser: self.comm_op_data = [HcclOpBean(data) for data in all_data] def _query_comm_task_data(self): + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_COMMUNICATION_TASK_INFO): + return if self._enable_communication_compare or self._enable_profiling_compare: sql = """ SELECT @@ -271,6 +279,8 @@ class NPUProfilingDbParser: self.comm_task_data = [HcclTaskBean(data) for data in all_data] def _query_memory_data(self): + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_OP_MEMORY): + return if self._enable_memory_compare: sql = """ SELECT @@ -342,6 +352,8 @@ class NPUProfilingDbParser: Constant.RELEASE_TIME: release_time / Constant.NS_TO_US}) def _query_python_function_data(self): + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_PYTORCH_API): + return if self._enable_operator_compare: sql = self.pytorch_api_sql.format( "AND PYTORCH_API.startNs>=? AND PYTORCH_API.startNs<=?") if len(self.step_range) == 2 else \ @@ -357,6 +369,8 @@ class NPUProfilingDbParser: self.start_time = start_time self.pid = Constant.INVALID_VALUE + if not DBManager.judge_table_exists(self.cursor, Constant.TABLE_PYTORCH_API): + return sql = """ SELECT T.connectionId, T.startNs FROM ( diff --git a/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/overall_metrics_parser.py b/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/overall_metrics_parser.py index b94ef76dfb..54d30466cf 100644 --- a/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/overall_metrics_parser.py +++ b/profiler/msprof_analyze/compare_tools/compare_backend/profiling_parser/overall_metrics_parser.py @@ -146,6 +146,8 @@ class OverallMetricsParser: self.npu_db_parser.result_data.overall_metrics.calculate_other_time() def calculate_memory_usage_peak(self): + if not DBManager.judge_table_exists(self.npu_db_parser.cursor, Constant.TABLE_MEMORY_RECORD): + return sql = "SELECT max(totalReserved) AS 'totalReserved' FROM MEMORY_RECORD {}" sql = sql.format("WHERE timestamp>=? AND timestamp<=?") if self.npu_db_parser.step_range else sql.format("") if self.npu_db_parser.step_range: @@ -157,7 +159,7 @@ class OverallMetricsParser: all_data[0].get('totalReserved', 0) / 1024 / 1024 / 1024) def calculate_computing_time(self): - if DBManager.judge_table_exists(self.npu_db_parser.cursor, "TASK_PMU_INFO"): + if DBManager.judge_table_exists(self.npu_db_parser.cursor, Constant.TABLE_TASK_PMU_INFO): sql = """ SELECT TASK_PMU_INFO.globalTaskId AS "globalTaskId", diff --git a/profiler/msprof_analyze/prof_common/constant.py b/profiler/msprof_analyze/prof_common/constant.py index 129b03f22e..e5265321da 100644 --- a/profiler/msprof_analyze/prof_common/constant.py +++ b/profiler/msprof_analyze/prof_common/constant.py @@ -477,4 +477,6 @@ class Constant(object): TABLE_PYTORCH_CALLCHAINS = "PYTORCH_CALLCHAINS" TABLE_COMMUNICATION_SCHEDULE_TASK_INFO = "COMMUNICATION_SCHEDULE_TASK_INFO" TABLE_TASK_PMU_INFO = "TASK_PMU_INFO" + TABLE_OP_MEMORY = "OP_MEMORY" + TABLE_MEMORY_RECORD = "MEMORY_RECORD" -- Gitee