Skip to content

Commit

Permalink
Fixes the issue with show interface counters and for pfc and queue co…
Browse files Browse the repository at this point in the history
…unters. (#1180)

* Fix for Issue: sonic-net/sonic-buildimage#5655

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Updated the the fix for pfc/queue counters also.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
  • Loading branch information
abdosi committed Oct 21, 2020
1 parent ce36e01 commit c2c4c0d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 41 deletions.
12 changes: 1 addition & 11 deletions scripts/pfcstat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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():
Expand Down
27 changes: 13 additions & 14 deletions scripts/portstat
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 1 addition & 12 deletions scripts/queuestat
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 8 additions & 4 deletions utilities_common/netstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit c2c4c0d

Please sign in to comment.