diff --git a/amdsmi_cli/amdsmi_logger.py b/amdsmi_cli/amdsmi_logger.py index df49e31f69..b5b456fbb4 100644 --- a/amdsmi_cli/amdsmi_logger.py +++ b/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/src/amd_smi/fdinfo.cc b/src/amd_smi/fdinfo.cc index 17ac964cd3..d9b8631ef9 100644 --- a/src/amd_smi/fdinfo.cc +++ b/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;