From 10feb1dce7ea9f01cd24a16727b7acb55ad4cdfd Mon Sep 17 00:00:00 2001 From: hehongzhe <935062458@qq.com> Date: Thu, 10 Jul 2025 17:33:20 +0800 Subject: [PATCH] profiler simplify_data support multi-device --- torch_npu/profiler/analysis/_profiling_parser.py | 9 +++++---- .../profiler/analysis/prof_common_func/_path_manager.py | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/torch_npu/profiler/analysis/_profiling_parser.py b/torch_npu/profiler/analysis/_profiling_parser.py index 4458d7559c4..f86de286b65 100644 --- a/torch_npu/profiler/analysis/_profiling_parser.py +++ b/torch_npu/profiler/analysis/_profiling_parser.py @@ -31,13 +31,14 @@ class ProfilingParser: @staticmethod def simplify_data(profiler_path: str, simplify_flag: bool): cann_path = ProfilerPathManager.get_cann_path(profiler_path) - device_path = ProfilerPathManager.get_device_path(cann_path) + device_paths = ProfilerPathManager.get_device_path(cann_path) host_path = ProfilerPathManager.get_host_path(cann_path) rm_dirs = ['sqlite', 'summary', 'timeline'] if simplify_flag else ['sqlite'] for rm_dir in rm_dirs: - if device_path: - target_path = os.path.join(device_path, rm_dir) - PathManager.remove_path_safety(target_path) + if device_paths: + for device_path in device_paths: + target_path = os.path.join(device_path, rm_dir) + PathManager.remove_path_safety(target_path) if host_path: target_path = os.path.join(host_path, rm_dir) PathManager.remove_path_safety(target_path) diff --git a/torch_npu/profiler/analysis/prof_common_func/_path_manager.py b/torch_npu/profiler/analysis/prof_common_func/_path_manager.py index cb12d2fb414..866f0cc3c1b 100644 --- a/torch_npu/profiler/analysis/prof_common_func/_path_manager.py +++ b/torch_npu/profiler/analysis/prof_common_func/_path_manager.py @@ -61,13 +61,14 @@ class ProfilerPathManager: return "" @classmethod - def get_device_path(cls, cann_path: str) -> str: + def get_device_path(cls, cann_path: str) -> list: + device_paths = [] sub_dirs = os.listdir(os.path.realpath(cann_path)) for sub_dir in sub_dirs: sub_path = os.path.join(cann_path, sub_dir) if os.path.isdir(sub_path) and re.match(r"^device_\d", sub_dir): - return sub_path - return "" + device_paths.append(sub_path) + return device_paths @classmethod def get_device_id(cls, cann_path: str) -> int: -- Gitee