From 4f43139bceed3a93176beddb81200a74e59f55b8 Mon Sep 17 00:00:00 2001 From: "Kanangot Balakrishnan, Bindhiya" Date: Wed, 9 Jul 2025 16:34:39 -0500 Subject: [PATCH] [SWDEV-539721] Show complete process name (#536) Modified the file used to fetch process name so that complete name with path can be displayed. Changes: amd-smi monitor -q - human readable format will output only the process name - csv and json formats will print the full path amd-smi process - name will always be the full path to the process amd-smi (default output) - name will always be truncated. --------- Signed-off-by: Bindhiya Kanangot Balakrishnan Signed-off-by: Maisam Arif [ROCm/amdsmi commit: 514517e536e8e5611b44a6e27147a4e3a589f78d] --- projects/amdsmi/amdsmi_cli/amdsmi_logger.py | 4 ++-- projects/amdsmi/src/amd_smi/fdinfo.cc | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py index df49e31f69..b5b456fbb4 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py @@ -228,7 +228,7 @@ class AMDSMILogger(): string_process_value = str(process_value) if process_key == "name": # Truncate name if too long - process_name = string_process_value[:17] + process_name = string_process_value.split('/')[-1][:17] if process_name == "": process_name = "N/A" table_values += process_name.rjust(17) @@ -1079,7 +1079,7 @@ class AMDSMILogger(): for process in output['processes']: gpu_id = str(process['gpu']).rjust(4) pid = str(process['pid']).rjust(9) - process_name = str(process['name']).ljust(19) + process_name = str(process['name']).split('/')[-1].ljust(19) gtt_mem = str(process['gtt']).rjust(8) vram_mem = str(process['vram']).rjust(8) mem_usage = str(process['mem_usage']).rjust(9) diff --git a/projects/amdsmi/src/amd_smi/fdinfo.cc b/projects/amdsmi/src/amd_smi/fdinfo.cc index 17ac964cd3..d9b8631ef9 100644 --- a/projects/amdsmi/src/amd_smi/fdinfo.cc +++ b/projects/amdsmi/src/amd_smi/fdinfo.cc @@ -126,7 +126,7 @@ amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid, static_cast(bdf.function_number & 0x7)); std::string path = "/proc/" + std::to_string(pid) + "/fdinfo/"; - std::string name_path = "/proc/" + std::to_string(pid) + "/comm"; + std::string name_path = "/proc/" + std::to_string(pid) + "/exe"; std::string cgroup_path = "/proc/" + std::to_string(pid) + "/cgroup"; if (gpuvsmi_pid_is_gpu(path.c_str(), bdf_str)) { @@ -189,10 +189,9 @@ amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid, // Note: If possible at all, try to get the name of the process/container. // In case the other info fail, get at least something. - std::ifstream filename(name_path.c_str()); - std::string name; - - getline(filename, name); + char exe_realpath[PATH_MAX] = {0}; + ssize_t len = readlink(name_path.c_str(), exe_realpath, sizeof(exe_realpath) - 1); + std::string name = (len > 0) ? std::string(exe_realpath, len) : "N/A"; if (name.empty()) return AMDSMI_STATUS_API_FAILED;