[Mellanox] optimize platform API import time (#10815)

- Why I did it
"import sonic_platform" takes about 600ms ~ 1000ms, it is kind of slow. After this optimization, the time is about 100ms. The benefit is that those CLIs which does not need the slow import sentence would be faster than before.

- How I did it
Find slow import and call them when need.

- How to verify it
Measure the import time.
This commit is contained in:
Junchao-Mellanox 2022-06-07 20:13:16 +08:00 committed by GitHub
parent 5c869492bd
commit f135f37a50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -30,7 +30,6 @@ try:
from . import utils
from .device_data import DeviceDataManager
from .sfp import SFP, deinitialize_sdk_handle
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
@ -113,8 +112,10 @@ class Chassis(ChassisBase):
if self.sfp_event:
self.sfp_event.deinitialize()
if SFP.shared_sdk_handle:
deinitialize_sdk_handle(SFP.shared_sdk_handle)
if self._sfp_list:
from .sfp import SFP, deinitialize_sdk_handle
if SFP.shared_sdk_handle:
deinitialize_sdk_handle(SFP.shared_sdk_handle)
##############################################
# PSU methods

View File

@ -17,7 +17,6 @@
import glob
import os
from sonic_py_common import device_info
from . import utils
@ -173,6 +172,7 @@ class DeviceDataManager:
@classmethod
@utils.read_only_cache()
def get_platform_name(cls):
from sonic_py_common import device_info
return device_info.get_platform()
@classmethod