Skip to content

[action] [PR:4787] [tempershow]: Avoid heavy SFP/xcvr import for port-name mapping - #465

Merged
mssonicbld merged 1 commit into
Azure:202608from
mssonicbld:cherry/msft-202608/4787
Sep 16, 2026
Merged

mssonicbld merged 1 commit into
Azure:202608from
mssonicbld:cherry/msft-202608/4787

Conversation

@mssonicbld

Copy link
Copy Markdown
Collaborator

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

#### 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>
@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Original PR: sonic-net/sonic-utilities#4787

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azp run

1 similar comment
@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azp run

@mssonicbld
mssonicbld merged commit c245a8b into Azure:202608 Sep 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant