Skip to content

Commit

Permalink
suppport multi asic for show queue counter (#2439)
Browse files Browse the repository at this point in the history
Added option -n for both "show queue counter" and "queuestat", using multi_asic module in queuestat to query database of specified namespace.
Removed function get_queue_port() to decrease the times of connecting database.
  • Loading branch information
zhixzhu authored Jan 30, 2023
1 parent 1b21201 commit c4c6808
Show file tree
Hide file tree
Showing 4 changed files with 756 additions and 69 deletions.
22 changes: 18 additions & 4 deletions scripts/queuestat
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import sys
from collections import namedtuple, OrderedDict
from natsort import natsorted
from tabulate import tabulate
from sonic_py_common import multi_asic

# mock the redis for unit test purposes #
try:
Expand All @@ -24,12 +25,17 @@ try:
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector # lgtm [py/unused-import]
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
import mock_tables.mock_multi_asic
mock_tables.dbconnector.load_namespace_config()

except KeyError:
pass

from swsscommon.swsscommon import SonicV2Connector
from utilities_common.cli import UserCache
from utilities_common import constants
import utilities_common.multi_asic as multi_asic_util

QueueStats = namedtuple("QueueStats", "queueindex, queuetype, totalpacket, totalbytes, droppacket, dropbytes")
header = ['Port', 'TxQ', 'Counter/pkts', 'Counter/bytes', 'Drop/pkts', 'Drop/bytes']
Expand Down Expand Up @@ -85,9 +91,15 @@ def build_json(port, cnstat):


class Queuestat(object):
def __init__(self, voq=False):
self.db = SonicV2Connector(use_unix_socket_path=False)
self.db.connect(self.db.COUNTERS_DB)
def __init__(self, namespace, voq=False):
self.db = None
self.multi_asic = multi_asic_util.MultiAsic(constants.DISPLAY_ALL, namespace)
if namespace is not None:
for ns in self.multi_asic.get_ns_list_based_on_options():
self.db = multi_asic.connect_to_all_dbs_for_ns(ns)
else:
self.db = SonicV2Connector(use_unix_socket_path=False)
self.db.connect(self.db.COUNTERS_DB)
self.voq = voq

def get_queue_port(table_id):
Expand Down Expand Up @@ -345,12 +357,14 @@ Examples:
parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0')
parser.add_argument('-j', '--json_opt', action='store_true', help='Print in JSON format')
parser.add_argument('-V', '--voq', action='store_true', help='display voq stats')
parser.add_argument('-n','--namespace', default=None, help='Display queue counters for specific namespace')
args = parser.parse_args()

save_fresh_stats = args.clear
delete_stats = args.delete
voq = args.voq
json_opt = args.json_opt
namespace = args.namespace

port_to_show_stats = args.port

Expand All @@ -362,7 +376,7 @@ Examples:
if delete_stats:
cache.remove()

queuestat = Queuestat( voq )
queuestat = Queuestat( namespace, voq )

if save_fresh_stats:
queuestat.save_fresh_stats()
Expand Down
6 changes: 5 additions & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,11 @@ def queue():
# 'counters' subcommand ("show queue counters")
@queue.command()
@click.argument('interfacename', required=False)
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.option('--json', is_flag=True, help="JSON output")
@click.option('--voq', is_flag=True, help="VOQ counters")
def counters(interfacename, verbose, json, voq):
def counters(interfacename, namespace, display, verbose, json, voq):
"""Show queue counters"""

cmd = "queuestat"
Expand All @@ -719,6 +720,9 @@ def counters(interfacename, verbose, json, voq):
if interfacename is not None:
cmd += " -p {}".format(interfacename)

if namespace is not None:
cmd += " -n {}".format(namespace)

if json:
cmd += " -j"

Expand Down
Loading

0 comments on commit c4c6808

Please sign in to comment.