Skip to content

Commit

Permalink
[show] Moving some py imports inside specific cmds (#1202)
Browse files Browse the repository at this point in the history
- Some py imports in show/main.py script are taking more time on arm cpu.
- modules - pkg_resources, netaddr are taking around 500ms causing delay for all show cmds.
- These modules are used by only specific cmds. So, I have included these imports only for the commands that are using them.

Signed-off-by: Sabareesh Kumar Anandan <sanandan@marvell.com>
  • Loading branch information
Sabareesh-Kumar-Anandan authored Dec 3, 2020
1 parent fab84fb commit d4eb2d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import netaddr
import os
import subprocess
import sys
Expand All @@ -9,7 +8,6 @@
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util
from natsort import natsorted
from pkg_resources import parse_version
from sonic_py_common import device_info, multi_asic
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import SonicV2Connector
Expand Down Expand Up @@ -751,6 +749,7 @@ def get_if_master(iface):
@ip.command()
def interfaces():
"""Show interfaces IPv4 address"""
import netaddr
header = ['Interface', 'Master', 'IPv4 address/mask', 'Admin/Oper', 'BGP Neighbor', 'Neighbor IP']
data = []
bgp_peer = get_bgp_peer()
Expand Down Expand Up @@ -1266,6 +1265,7 @@ def bgp(verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def ntp(ctx, verbose):
"""Show NTP information"""
from pkg_resources import parse_version
ntpstat_cmd = "ntpstat"
ntpcmd = "ntpq -p -n"
if is_mgmt_vrf_enabled(ctx) is True:
Expand Down
2 changes: 1 addition & 1 deletion utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import click
import json
import netaddr

from natsort import natsorted
from sonic_py_common import multi_asic
Expand Down Expand Up @@ -191,6 +190,7 @@ def get_interface_naming_mode():

def is_ipaddress(val):
""" Validate if an entry is a valid IP """
import netaddr
if not val:
return False
try:
Expand Down

0 comments on commit d4eb2d9

Please sign in to comment.