[action] [PR:4787] [tempershow]: Avoid heavy SFP/xcvr import for port-name mapping - #465
Merged
Merged
Conversation
#### What I did Fixed a ~40% performance regression in `show platform temperature` (which invokes the `tempershow` utility). Fixes sonic-net/sonic-buildimage#28529. `tempershow` maps each logical port name (e.g. `Ethernet0`) to the legacy `xSFP module <N> Temp` sensor label. It previously built this mapping by calling `platform_sfputil_helper.load_platform_sfputil()`, which imports the entire `sonic_platform_base` -> `sonic_xcvr` transceiver-API stack (CMIS/CDB/VDM/yaml/netaddr) plus `utilities_common.cli`. That import chain dominates the command's runtime even though the actual STATE_DB temperature read only takes a few milliseconds. #### How I did it - Build the `{logical_port_name: front-panel index}` map directly from the platform port configuration via `portconfig.get_port_config`, reading the same `index` field that `SfpUtilHelper.read_porttab_mappings` uses. This pulls in only `swsscommon`/`sonic_py_common`, which `tempershow` already imports. - Dropped the `utilities_common.platform_sfputil_helper` dependency (and the heavy `sonic_platform_base`/`sonic_xcvr` import chain it triggers) from `tempershow`. - Preserved single-ASIC and multi-ASIC namespace handling; if the port config is unavailable, the display name falls back to the logical port name, exactly as before. - The `xSFP module <N> Temp` labels are byte-for-byte unchanged — only the heavy import is removed. - Added `tests/tempershow_test.py` covering the new mapping (single/multi-ASIC, missing/failing port config, invalid index) and the display-name fallback. #### How to verify it 1. Run the unit tests: ``` pytest tests/tempershow_test.py -v ``` 2. On a switch, confirm that the output of `show platform temperature` (including every `xSFP module <N> Temp` row) is unchanged before and after this change. 3. Confirm the heavy import chain is gone: ``` python3 -X importtime /usr/local/bin/tempershow 2>&1 | grep -E 'sonic_platform_base|sonic_xcvr|portconfig' ``` Before: the `sonic_platform_base`/`sonic_xcvr` chain is imported (~40 ms cumulative). After: only `portconfig` (~0.5 ms) is imported. **Hardware verification on a 202605 image** — Mellanox-SN2700 (single-ASIC, `SONiC.20260510.10`, internal-202605 build, Python 3.13). The DUT-tested commit is byte-for-byte identical to this PR's `scripts/tempershow` and `tests/tempershow_test.py`. | Metric (7 runs each) | Baseline (heavy import) | Fixed (this PR) | | --- | --- | --- | | End-to-end `tempershow` real time — median | 0.328 s | **0.233 s (~29% faster)** | | End-to-end `tempershow` real time — min / max | 0.297 s / 0.371 s | 0.224 s / 0.255 s | | Isolated port-name mapping path | ~0.283 s (`platform_sfputil_helper`) | ~0.150 s (`portconfig.get_port_config`) | | Heavy `sonic_platform_base`/`sonic_xcvr` chain at module load | ~41.7 ms | eliminated (only `portconfig`, ~0.57 ms) | Functional correctness: output is 43 lines before and after, and all 32 `xSFP module <N> Temp` sensor labels (and their order) are byte-for-byte identical to the previous implementation. #### Previous command output (if the output of a command-line utility has changed) No change to command output. The `show platform temperature` / `tempershow` table (including the `xSFP module <N> Temp` labels) is identical before and after this change; only the runtime/import cost is reduced. #### New command output (if the output of a command-line utility has changed) N/A — output unchanged (see above). Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
Collaborator
Author
|
Original PR: sonic-net/sonic-utilities#4787 |
Collaborator
Author
|
/azp run |
1 similar comment
Collaborator
Author
|
/azp run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
Fixed a ~40% performance regression in
show platform temperature(which invokes thetempershowutility). Fixes sonic-net/sonic-buildimage#28529.tempershowmaps each logical port name (e.g.Ethernet0) to the legacyxSFP module <N> Tempsensor label. It previously built this mapping by callingplatform_sfputil_helper.load_platform_sfputil(), which imports the entiresonic_platform_base->sonic_xcvrtransceiver-API stack (CMIS/CDB/VDM/yaml/netaddr) plusutilities_common.cli. That import chain dominates the command's runtime even though the actual STATE_DB temperature read only takes a few milliseconds.How I did it
{logical_port_name: front-panel index}map directly from the platform port configuration viaportconfig.get_port_config, reading the sameindexfield thatSfpUtilHelper.read_porttab_mappingsuses. This pulls in onlyswsscommon/sonic_py_common, whichtempershowalready imports.utilities_common.platform_sfputil_helperdependency (and the heavysonic_platform_base/sonic_xcvrimport chain it triggers) fromtempershow.xSFP module <N> Templabels are byte-for-byte unchanged — only the heavy import is removed.tests/tempershow_test.pycovering the new mapping (single/multi-ASIC, missing/failing port config, invalid index) and the display-name fallback.How to verify it
show platform temperature(including everyxSFP module <N> Temprow) is unchanged before and after this change.sonic_platform_base/sonic_xcvrchain is imported (~40 ms cumulative). After: onlyportconfig(~0.5 ms) is imported.Hardware verification on a 202605 image — Mellanox-SN2700 (single-ASIC,
SONiC.20260510.10, internal-202605 build, Python 3.13). The DUT-tested commit is byte-for-byte identical to this PR'sscripts/tempershowandtests/tempershow_test.py.tempershowreal time — mediantempershowreal time — min / maxplatform_sfputil_helper)portconfig.get_port_config)sonic_platform_base/sonic_xcvrchain at module loadportconfig, ~0.57 ms)Functional correctness: output is 43 lines before and after, and all 32
xSFP module <N> Tempsensor labels (and their order) are byte-for-byte identical to the previous implementation.Previous command output (if the output of a command-line utility has changed)
No change to command output. The
show platform temperature/tempershowtable (including thexSFP module <N> Templabels) is identical before and after this change; only the runtime/import cost is reduced.New command output (if the output of a command-line utility has changed)
N/A — output unchanged (see above).
Signed-off-by: Sonic Build Admin sonicbld@microsoft.com