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

[202012] [portstat pfcstat] Unify the packet number format in the output of portstat and pfcstat in all cases #1795

Merged
merged 1 commit into from
Sep 3, 2021
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
26 changes: 17 additions & 9 deletions scripts/pfcstat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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.netstat import ns_diff, STATUS_NA, format_number_with_comma
from utilities_common import multi_asic as multi_asic_util
from utilities_common import constants

Expand Down Expand Up @@ -141,10 +141,14 @@ class Pfcstat(object):
if key == 'time':
continue
table.append((key,
data.pfc0, data.pfc1,
data.pfc2, data.pfc3,
data.pfc4, data.pfc5,
data.pfc6, data.pfc7))
format_number_with_comma(data.pfc0),
format_number_with_comma(data.pfc1),
format_number_with_comma(data.pfc2),
format_number_with_comma(data.pfc3),
format_number_with_comma(data.pfc4),
format_number_with_comma(data.pfc5),
format_number_with_comma(data.pfc6),
format_number_with_comma(data.pfc7)))

if rx:
print(tabulate(table, header_Rx, tablefmt='simple', stralign='right'))
Expand Down Expand Up @@ -176,10 +180,14 @@ class Pfcstat(object):
ns_diff(cntr.pfc7, old_cntr.pfc7)))
else:
table.append((key,
cntr.pfc0, cntr.pfc1,
cntr.pfc2, cntr.pfc3,
cntr.pfc4, cntr.pfc5,
cntr.pfc6, cntr.pfc7))
format_number_with_comma(cntr.pfc0),
format_number_with_comma(cntr.pfc1),
format_number_with_comma(cntr.pfc2),
format_number_with_comma(cntr.pfc3),
format_number_with_comma(cntr.pfc4),
format_number_with_comma(cntr.pfc5),
format_number_with_comma(cntr.pfc6),
format_number_with_comma(cntr.pfc7)))

if rx:
print(tabulate(table, header_Rx, tablefmt='simple', stralign='right'))
Expand Down
77 changes: 48 additions & 29 deletions scripts/portstat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from utilities_common import constants
from utilities_common.intf_filter import parse_interface_in_filter
import utilities_common.multi_asic as multi_asic_util
from utilities_common.netstat import (ns_brate, ns_diff, ns_prate, ns_util,
table_as_json)
table_as_json, format_number_with_comma)

# mock the redis for unit test purposes #
try:
Expand All @@ -40,6 +40,7 @@ try:
except KeyError:
pass


PORT_RATE = 40

"""
Expand Down Expand Up @@ -237,27 +238,45 @@ class Portstat(object):
if print_all:
header = header_all
table.append((key, self.get_port_state(key),
data.rx_ok, STATUS_NA, STATUS_NA, STATUS_NA, data.rx_err,
data.rx_drop, data.rx_ovr,
data.tx_ok, STATUS_NA, STATUS_NA, STATUS_NA, data.tx_err,
data.tx_drop, data.tx_ovr))
format_number_with_comma(data.rx_ok),
STATUS_NA, STATUS_NA, STATUS_NA,
format_number_with_comma(data.rx_err),
format_number_with_comma(data.rx_drop),
format_number_with_comma(data.rx_ovr),
format_number_with_comma(data.tx_ok),
STATUS_NA, STATUS_NA, STATUS_NA,
format_number_with_comma(data.tx_err),
format_number_with_comma(data.tx_drop),
format_number_with_comma(data.tx_ovr)))
elif errors_only:
header = header_errors_only
table.append((key, self.get_port_state(key),
data.rx_err, data.rx_drop, data.rx_ovr,
data.tx_err, data.tx_drop, data.tx_ovr))
format_number_with_comma(data.rx_err),
format_number_with_comma(data.rx_drop),
format_number_with_comma(data.rx_ovr),
format_number_with_comma(data.tx_err),
format_number_with_comma(data.tx_drop),
format_number_with_comma(data.tx_ovr)))
elif rates_only:
header = header_rates_only
table.append((key, self.get_port_state(key),
data.rx_ok, STATUS_NA, STATUS_NA, STATUS_NA,
data.tx_ok, STATUS_NA, STATUS_NA, STATUS_NA))
format_number_with_comma(data.rx_ok),
STATUS_NA, STATUS_NA, STATUS_NA,
format_number_with_comma(data.tx_ok),
STATUS_NA, STATUS_NA, STATUS_NA))
else:
header = header_std
table.append((key, self.get_port_state(key),
data.rx_ok, STATUS_NA, STATUS_NA, data.rx_err,
data.rx_drop, data.rx_ovr,
data.tx_ok, STATUS_NA, STATUS_NA, data.tx_err,
data.tx_drop, data.tx_ovr))
format_number_with_comma(data.rx_ok),
STATUS_NA, STATUS_NA,
format_number_with_comma(data.rx_err),
format_number_with_comma(data.rx_drop),
format_number_with_comma(data.rx_ovr),
format_number_with_comma(data.tx_ok),
STATUS_NA, STATUS_NA,
format_number_with_comma(data.tx_err),
format_number_with_comma(data.tx_drop),
format_number_with_comma(data.tx_ovr)))

if use_json:
print(table_as_json(table, header))
Expand Down Expand Up @@ -370,20 +389,20 @@ class Portstat(object):
ns_diff(cntr.tx_ovr, old_cntr.tx_ovr)))
else:
table.append((key, self.get_port_state(key),
cntr.rx_ok,
format_number_with_comma(cntr.rx_ok),
STATUS_NA,
STATUS_NA,
STATUS_NA,
cntr.rx_err,
cntr.rx_drop,
cntr.rx_ovr,
cntr.tx_ok,
format_number_with_comma(cntr.rx_err),
format_number_with_comma(cntr.rx_drop),
format_number_with_comma(cntr.rx_ovr),
format_number_with_comma(cntr.tx_ok),
STATUS_NA,
STATUS_NA,
STATUS_NA,
cntr.tx_err,
cntr.tx_drop,
cntr.tx_ovr))
format_number_with_comma(cntr.tx_err),
format_number_with_comma(cntr.tx_drop),
format_number_with_comma(cntr.tx_ovr)))
elif errors_only:
header = header_errors_only
table.append((key, self.get_port_state(key),
Expand Down Expand Up @@ -422,18 +441,18 @@ class Portstat(object):
ns_diff(cntr.tx_ovr, old_cntr.tx_ovr)))
else:
table.append((key, self.get_port_state(key),
cntr.rx_ok,
format_number_with_comma(cntr.rx_ok),
STATUS_NA,
STATUS_NA,
cntr.rx_err,
cntr.rx_drop,
cntr.rx_ovr,
cntr.tx_ok,
format_number_with_comma(cntr.rx_err),
format_number_with_comma(cntr.rx_drop),
format_number_with_comma(cntr.rx_ovr),
format_number_with_comma(cntr.tx_ok),
STATUS_NA,
STATUS_NA,
cntr.tx_err,
cntr.tx_drop,
cntr.tx_ovr))
format_number_with_comma(cntr.tx_err),
format_number_with_comma(cntr.tx_drop),
format_number_with_comma(cntr.tx_ovr)))

if use_json:
print(table_as_json(table, header))
Expand Down
16 changes: 8 additions & 8 deletions tests/mock_tables/asic0/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1474,15 +1474,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "100",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "200",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1200",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "201",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "202",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "203",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "204",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "205",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "206",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "207",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "210",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1210",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "211",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "212",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "213",
Expand All @@ -1502,15 +1502,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "400",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1400",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "401",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "402",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "403",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "404",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "405",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "406",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "407",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "410",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1410",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "411",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "412",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "413",
Expand All @@ -1530,15 +1530,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "600",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1600",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "601",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "602",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "603",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "604",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "605",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "606",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "607",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "610",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1610",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "611",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "612",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "613",
Expand All @@ -1558,15 +1558,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "800",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1800",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "801",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "802",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "803",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "804",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "805",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "806",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "807",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "810",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1810",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "811",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "812",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "813",
Expand Down
8 changes: 4 additions & 4 deletions tests/mock_tables/asic1/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "100",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "900",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1900",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "901",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "902",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "903",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "904",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "905",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "906",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "907",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "910",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1910",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "911",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "912",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "913",
Expand All @@ -158,15 +158,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1100",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "101",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "102",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "103",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "104",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "105",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "106",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "107",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "110",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1110",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "111",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "112",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "113",
Expand Down
16 changes: 8 additions & 8 deletions tests/mock_tables/asic2/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1474,15 +1474,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "100",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "200",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1200",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "201",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "202",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "203",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "204",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "205",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "206",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "207",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "210",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1210",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "211",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "212",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "213",
Expand All @@ -1502,15 +1502,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "400",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1400",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "401",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "402",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "403",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "404",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "405",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "406",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "407",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "410",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1410",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "411",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "412",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "413",
Expand All @@ -1530,15 +1530,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "600",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1600",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "601",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "602",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "603",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "604",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "605",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "606",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "607",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "610",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1610",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "611",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "612",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "613",
Expand All @@ -1558,15 +1558,15 @@
"SAI_PORT_STAT_IF_IN_DISCARDS": "1000",
"SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800",
"SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "800",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1800",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "801",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "802",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "803",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "804",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "805",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "806",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "807",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "810",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1810",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "811",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "812",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "813",
Expand Down
Loading