Skip to content

Commit 05d2704

Browse files
[ROCM-2950] Fix amd-smi default command output alignment (#5632)
## Summary Fix misaligned field values in the default `amd-smi` output. ## Changes - Updated all format strings in `amdsmi_logger.py` to use consistent left-aligned (`:<width>`) formatting with a uniform column width - Affected fields: AMD-SMI version, amdgpu/kernel version, ROCm version, VBIOS version, FW PLDM, Platform - Purely cosmetic — no functional impact ## Changelog ### Resolved Issues - **Fixed `amd-smi` default command alignment**. - Updated default `amd-smi` output to align values to the left for improved readability. Several items were misaligned in the default output, and this change ensures a consistent left-aligned format across all fields. - *This change is purely cosmetic and does not affect any functionality.* --------- Signed-off-by: Charis Poag <charis.poag@amd.com>
1 parent 44c8aeb commit 05d2704

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

projects/amdsmi/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr
111111
- **Fixed `cu_occupancy` displaying `0%` instead of `N/A` when file is unavailable**.
112112
- Process `cu_occupancy` is now initialized to `INVALID` instead of zero, so `amd-smi process` displays `N/A` rather than a misleading `0%` when the sysfs file is not accessible.
113113

114+
- **Fixed `amd-smi` default command alignment**.
115+
- Updated default `amd-smi` output to align values to the left for improved readability.
116+
Several items were misaligned in the default output, and this change ensures a consistent left-aligned format across all fields.
117+
- *This change is purely cosmetic and does not affect any functionality.*
118+
114119
### Changed
115120

116121
- **Package install no longer modifies the system-wide logrotate timer or cron schedule**.

projects/amdsmi/amdsmi_cli/amdsmi_logger.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,6 @@ def print_default_output(self, output: Dict):
11951195

11961196
# print the version information first
11971197
amd_smi_version = str(output["version_info"]["amd-smi"])
1198-
if len(amd_smi_version) > 60:
1199-
amd_smi_version = amd_smi_version[:57] + "..."
12001198
rocm_version = "N/A"
12011199
if output["version_info"]["rocm version"][0]:
12021200
rocm_version = str(output["version_info"]["rocm version"][1]).ljust(8)
@@ -1218,28 +1216,49 @@ def print_default_output(self, output: Dict):
12181216
fw_pldm_version = str(output["version_info"]["fw pldm version"])
12191217
vbios_version = str(output["version_info"]["vbios version"])
12201218
kernel_version = str(output["version_info"]["kernel version"])
1221-
1219+
_COL_WIDTH = 57 # inner column width for the default output table
1220+
1221+
def _trunc(s):
1222+
"""Truncate string to _COL_WIDTH chars, appending '...' if it was cut."""
1223+
return s[: _COL_WIDTH - 3] + "..." if len(s) > _COL_WIDTH else s
1224+
1225+
amd_smi_version = _trunc(amd_smi_version)
1226+
rocm_version = _trunc(rocm_version)
1227+
amdgpu_version = _trunc(amdgpu_version)
1228+
fw_pldm_version = _trunc(fw_pldm_version)
1229+
vbios_version = _trunc(vbios_version)
1230+
kernel_version = _trunc(kernel_version)
1231+
1232+
#####################################################################################
1233+
# FORMATTING LOGIC: #
1234+
# Each version field is left-aligned within a fixed _COL_WIDTH column. Fields that #
1235+
# exceed the column width are truncated with "..." to keep the box border intact. #
1236+
# Fields that are "N/A" are skipped entirely to avoid cluttering the output. #
1237+
#####################################################################################
12221238
# print GPU info
12231239
print(default_line_1)
1224-
# Split the version line into 3 lines, each wrapping to the same width
1225-
print("| AMD-SMI {0:40s} {1:19s}|".format(amd_smi_version.ljust(40), ""))
1240+
print("| AMD-SMI {0:<{w}s} |".format(amd_smi_version, w=_COL_WIDTH))
12261241

12271242
# Print amdgpu or kernel version based on availability, if neither then don't print
12281243
if amdgpu_version.strip() != "N/A":
1229-
print("| amdgpu Version: {0:40s} {1:19s}|".format(amdgpu_version, ""))
1244+
print("| amdgpu Version: {0:<{w}s} |".format(amdgpu_version, w=_COL_WIDTH))
12301245
elif kernel_version.strip() != "N/A":
1231-
print("| OS kernel Version: {0:40s} {1:19s}|".format(kernel_version, ""))
1246+
print("| OS kernel Version: {0:<{w}s} |".format(kernel_version, w=_COL_WIDTH))
12321247

12331248
if rocm_version != "N/A":
1234-
print("| ROCm Version: {0:40s} {1:19s}|".format(rocm_version, ""))
1249+
print("| ROCm Version: {0:<{w}s} |".format(rocm_version, w=_COL_WIDTH))
12351250

12361251
# only print if the version is not "N/A"
12371252
if vbios_version != "N/A":
1238-
print("| VBIOS Version: {0:22s} {1:35s} |".format(vbios_version, ""))
1253+
print("| VBIOS Version: {0:<{w}s} |".format(vbios_version, w=_COL_WIDTH))
12391254
if fw_pldm_version != "N/A":
1240-
print("| FW PLDM: {0:15s} {1:42s} |".format(fw_pldm_version, ""))
1255+
print("| FW PLDM: {0:<{w}s} |".format(fw_pldm_version, w=_COL_WIDTH))
12411256

1242-
print("| Platform: {0:25.25s} {1:34s}|".format(str(self.helpers.os_info()), ""))
1257+
print(
1258+
"| Platform: {0:<{w}s} |".format(
1259+
_trunc(str(self.helpers.os_info())), w=_COL_WIDTH
1260+
)
1261+
)
12431262
print(default_line_2)
12441263
print("| BDF GPU-Name | Mem-Uti Temp UEC Power-Usage |")
12451264
print("| GPU HIP-ID OAM-ID Partition-Mode | GFX-Uti Fan Mem-Usage |")

0 commit comments

Comments
 (0)