Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the issue with show interface counters and for pfc and queue counters. #1180

Merged
merged 2 commits into from
Oct 20, 2020
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
12 changes: 1 addition & 11 deletions scripts/pfcstat
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -63,7 +64,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 @@ -155,16 +155,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
7 changes: 3 additions & 4 deletions scripts/portstat
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,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 @@ -294,13 +293,13 @@ class Portstat(object):
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_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),
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)))
Expand Down
13 changes: 1 addition & 12 deletions scripts/queuestat
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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 @@ -158,16 +157,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 = []

for key, cntr in cnstat_new_dict.iteritems():
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