Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions scripts/queuestat
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ from utilities_common.cli import UserCache

QueueStats = namedtuple("QueueStats", "queueindex, queuetype, totalpacket, totalbytes, droppacket, dropbytes")
header = ['Port', 'TxQ', 'Counter/pkts', 'Counter/bytes', 'Drop/pkts', 'Drop/bytes']
voq_header = ['Port', 'Voq', 'Counter/pkts', 'Counter/bytes', 'Drop/pkts', 'Drop/bytes']

counter_bucket_dict = {
'SAI_QUEUE_STAT_PACKETS': 2,
Expand All @@ -47,13 +48,17 @@ from utilities_common.netstat import ns_diff, STATUS_NA
QUEUE_TYPE_MC = 'MC'
QUEUE_TYPE_UC = 'UC'
QUEUE_TYPE_ALL = 'ALL'
QUEUE_TYPE_VOQ = 'VOQ'
SAI_QUEUE_TYPE_MULTICAST = "SAI_QUEUE_TYPE_MULTICAST"
SAI_QUEUE_TYPE_UNICAST = "SAI_QUEUE_TYPE_UNICAST"
SAI_QUEUE_TYPE_UNICAST_VOQ = "SAI_QUEUE_TYPE_UNICAST_VOQ"
SAI_QUEUE_TYPE_ALL = "SAI_QUEUE_TYPE_ALL"

COUNTER_TABLE_PREFIX = "COUNTERS:"
COUNTERS_PORT_NAME_MAP = "COUNTERS_PORT_NAME_MAP"
COUNTERS_SYSTEM_PORT_NAME_MAP = "COUNTERS_SYSTEM_PORT_NAME_MAP"
COUNTERS_QUEUE_NAME_MAP = "COUNTERS_QUEUE_NAME_MAP"
COUNTERS_VOQ_NAME_MAP= "COUNTERS_VOQ_NAME_MAP"
COUNTERS_QUEUE_TYPE_MAP = "COUNTERS_QUEUE_TYPE_MAP"
COUNTERS_QUEUE_INDEX_MAP = "COUNTERS_QUEUE_INDEX_MAP"
COUNTERS_QUEUE_PORT_MAP = "COUNTERS_QUEUE_PORT_MAP"
Expand All @@ -80,9 +85,10 @@ def build_json(port, cnstat):


class Queuestat(object):
def __init__(self):
def __init__(self, voq=False):
self.db = SonicV2Connector(use_unix_socket_path=False)
self.db.connect(self.db.COUNTERS_DB)
self.voq = voq

def get_queue_port(table_id):
port_table_id = self.db.get(self.db.COUNTERS_DB, COUNTERS_QUEUE_PORT_MAP, table_id)
Expand All @@ -93,7 +99,11 @@ class Queuestat(object):
return port_table_id

# Get all ports
self.counter_port_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_PORT_NAME_MAP)
if voq:
self.counter_port_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_SYSTEM_PORT_NAME_MAP)
else:
self.counter_port_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_PORT_NAME_MAP)

if self.counter_port_name_map is None:
print("COUNTERS_PORT_NAME_MAP is empty!")
sys.exit(1)
Expand All @@ -105,8 +115,13 @@ class Queuestat(object):
self.port_queues_map[port] = {}
self.port_name_map[self.counter_port_name_map[port]] = port

counter_queue_name_map = None
# Get Queues for each port
counter_queue_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP)
if voq:
counter_queue_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_VOQ_NAME_MAP)
else:
counter_queue_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP)

if counter_queue_name_map is None:
print("COUNTERS_QUEUE_NAME_MAP is empty!")
sys.exit(1)
Expand Down Expand Up @@ -140,6 +155,8 @@ class Queuestat(object):
return QUEUE_TYPE_MC
elif queue_type == SAI_QUEUE_TYPE_UNICAST:
return QUEUE_TYPE_UC
elif queue_type == SAI_QUEUE_TYPE_UNICAST_VOQ:
return QUEUE_TYPE_VOQ
elif queue_type == SAI_QUEUE_TYPE_ALL:
return QUEUE_TYPE_ALL
else:
Expand Down Expand Up @@ -190,7 +207,8 @@ class Queuestat(object):
json_output[port].update(build_json(port, table))
return json_output
else:
print(tabulate(table, header, tablefmt='simple', stralign='right'))
hdr = voq_header if self.voq else header
print(tabulate(table, hdr, tablefmt='simple', stralign='right'))
print()

def cnstat_diff_print(self, port, cnstat_new_dict, cnstat_old_dict, json_opt):
Expand Down Expand Up @@ -225,7 +243,8 @@ class Queuestat(object):
json_output[port].update(build_json(port, table))
return json_output
else:
print(tabulate(table, header, tablefmt='simple', stralign='right'))
hdr = voq_header if self.voq else header
print(tabulate(table, hdr, tablefmt='simple', stralign='right'))
print()

def get_print_all_stat(self, json_opt):
Expand Down Expand Up @@ -325,11 +344,13 @@ Examples:
parser.add_argument('-d', '--delete', action='store_true', help='Delete saved stats')
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')
args = parser.parse_args()

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

port_to_show_stats = args.port

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

queuestat = Queuestat()
queuestat = Queuestat( 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 @@ -547,7 +547,8 @@ def queue():
@click.argument('interfacename', required=False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.option('--json', is_flag=True, help="JSON output")
def counters(interfacename, verbose, json):
@click.option('--voq', is_flag=True, help="VOQ counters")
def counters(interfacename, verbose, json, voq):
"""Show queue counters"""

cmd = "queuestat"
Expand All @@ -562,6 +563,9 @@ def counters(interfacename, verbose, json):
if json:
cmd += " -j"

if voq:
cmd += " -V"

run_command(cmd, display_cmd=verbose)

#
Expand Down
Loading