From c2c4c0d7e4748b8f72fdcea4383c0594d53bb860 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Mon, 19 Oct 2020 18:37:45 -0700 Subject: [PATCH] Fixes the issue with show interface counters and for pfc and queue counters. (#1180) * Fix for Issue: https://github.com/Azure/sonic-buildimage/issues/5655 Signed-off-by: Abhishek Dosi * Updated the the fix for pfc/queue counters also. Signed-off-by: Abhishek Dosi --- scripts/pfcstat | 12 +----------- scripts/portstat | 27 +++++++++++++-------------- scripts/queuestat | 13 +------------ utilities_common/netstat.py | 12 ++++++++---- 4 files changed, 23 insertions(+), 41 deletions(-) diff --git a/scripts/pfcstat b/scripts/pfcstat index 8a4b167327..999f320b96 100755 --- a/scripts/pfcstat +++ b/scripts/pfcstat @@ -21,6 +21,7 @@ from natsort import natsorted from tabulate import tabulate from sonic_py_common.multi_asic import get_external_ports +from utilities_common.netstat import ns_diff, STATUS_NA from utilities_common import multi_asic as multi_asic_util from utilities_common import constants @@ -66,7 +67,6 @@ counter_bucket_tx_dict = { 'SAI_PORT_STAT_PFC_7_TX_PKTS': 7 } -STATUS_NA = 'N/A' COUNTER_TABLE_PREFIX = "COUNTERS:" COUNTERS_PORT_NAME_MAP = "COUNTERS_PORT_NAME_MAP" @@ -158,16 +158,6 @@ class Pfcstat(object): """ Print the difference between two cnstat results. """ - def ns_diff(newstr, oldstr): - """ - Calculate the diff. - """ - if newstr == STATUS_NA or oldstr == STATUS_NA: - return STATUS_NA - else: - new, old = int(newstr), int(oldstr) - return '{:,}'.format(new - old) - table = [] for key, cntr in cnstat_new_dict.iteritems(): diff --git a/scripts/portstat b/scripts/portstat index e9dc6613cc..2e014f9ffc 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -138,13 +138,12 @@ class Portstat(object): """ # Get speed from APPL_DB full_table_id = PORT_STATUS_TABLE_PREFIX + port_name - speed = PORT_RATE for ns in self.multi_asic.get_ns_list_based_on_options(): self.db = multi_asic.connect_to_all_dbs_for_ns(ns) speed = self.db.get(self.db.APPL_DB, full_table_id, PORT_SPEED_FIELD) if speed is not None: return int(speed)//1000 - return speed + return PORT_RATE def get_port_state(self, port_name): """ @@ -250,18 +249,18 @@ class Portstat(object): else: if old_cntr is not None: table.append((key, self.get_port_state(key), - ns_diff(cntr.rx_ok, old_cntr.rx_ok), - ns_brate(cntr.rx_byt, old_cntr.rx_byt, time_gap), - ns_util(cntr.rx_byt, old_cntr.rx_byt, time_gap), - ns_diff(cntr.rx_err, old_cntr.rx_err), - ns_diff(cntr.rx_drop, old_cntr.rx_drop), - ns_diff(cntr.rx_ovr, old_cntr.rx_ovr), - ns_diff(cntr.tx_ok, old_cntr.tx_ok), - ns_brate(cntr.tx_byt, old_cntr.tx_byt, time_gap), - ns_util(cntr.tx_byt, old_cntr.tx_byt, time_gap), - ns_diff(cntr.tx_err, old_cntr.tx_err), - ns_diff(cntr.tx_drop, old_cntr.tx_drop), - ns_diff(cntr.tx_ovr, old_cntr.tx_ovr))) + ns_diff(cntr.rx_ok, old_cntr.rx_ok), + ns_brate(cntr.rx_byt, old_cntr.rx_byt, time_gap), + ns_util(cntr.rx_byt, old_cntr.rx_byt, time_gap, port_speed), + ns_diff(cntr.rx_err, old_cntr.rx_err), + ns_diff(cntr.rx_drop, old_cntr.rx_drop), + ns_diff(cntr.rx_ovr, old_cntr.rx_ovr), + ns_diff(cntr.tx_ok, old_cntr.tx_ok), + ns_brate(cntr.tx_byt, old_cntr.tx_byt, time_gap), + ns_util(cntr.tx_byt, old_cntr.tx_byt, time_gap, port_speed), + ns_diff(cntr.tx_err, old_cntr.tx_err), + ns_diff(cntr.tx_drop, old_cntr.tx_drop), + ns_diff(cntr.tx_ovr, old_cntr.tx_ovr))) else: table.append((key, self.get_port_state(key), cntr.rx_ok, diff --git a/scripts/queuestat b/scripts/queuestat index b93251ac8d..16b7aab99f 100755 --- a/scripts/queuestat +++ b/scripts/queuestat @@ -30,8 +30,7 @@ counter_bucket_dict = { 'SAI_QUEUE_STAT_DROPPED_BYTES': 5, } -STATUS_NA = 'N/A' -STATUS_INVALID = 'INVALID' +from utilities_common.netstat import ns_diff, STATUS_NA QUEUE_TYPE_MC = 'MC' QUEUE_TYPE_UC = 'UC' @@ -161,16 +160,6 @@ class Queuestat(object): """ Print the difference between two cnstat results. """ - def ns_diff(newstr, oldstr): - """ - Calculate the diff. - """ - if newstr == STATUS_NA or oldstr == STATUS_NA: - return STATUS_NA - else: - new, old = int(newstr), int(oldstr) - return '{:,}'.format(new - old) - table = [] queue_count = len(cnstat_new_dict) diff --git a/utilities_common/netstat.py b/utilities_common/netstat.py index 9bf266e580..3fd328f3a0 100755 --- a/utilities_common/netstat.py +++ b/utilities_common/netstat.py @@ -9,11 +9,15 @@ def ns_diff(newstr, oldstr): """ Calculate the diff. """ - if newstr == STATUS_NA or oldstr == STATUS_NA: + if newstr == STATUS_NA: return STATUS_NA - else: - new, old = int(newstr), int(oldstr) - return '{:,}'.format(max(0, new - old)) + + # if new is valid but old is not we should return new + if oldstr == STATUS_NA: + oldstr = '0' + + new, old = int(newstr), int(oldstr) + return '{:,}'.format(max(0, new - old)) def ns_brate(newstr, oldstr, delta): """