Skip to content

Commit 0b629ba

Browse files
Revert "[chassis][voq] Clear fabric counters queue/port (#2789)" (#2882)
This reverts commit fceef2e.
1 parent 3ba8241 commit 0b629ba

File tree

3 files changed

+44
-268
lines changed

3 files changed

+44
-268
lines changed

clear/main.py

-12
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,6 @@ def queuecounters():
181181
command = ["queuestat", "-c"]
182182
run_command(command)
183183

184-
@cli.command()
185-
def fabriccountersqueue():
186-
"""Clear fabric queue counters"""
187-
command = "fabricstat -C -q"
188-
run_command(command)
189-
190-
@cli.command()
191-
def fabriccountersport():
192-
"""Clear fabric port counters"""
193-
command = "fabricstat -C"
194-
run_command(command)
195-
196184
@cli.command()
197185
def pfccounters():
198186
"""Clear pfc counters"""

scripts/fabricstat

+7-127
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
import argparse
44
from collections import OrderedDict, namedtuple
5-
import json
65
import os
76
import sys
87

98
from utilities_common import constants
10-
from utilities_common.cli import json_serial, UserCache
11-
from utilities_common.netstat import format_number_with_comma, table_as_json, ns_diff, format_prate
129
from natsort import natsorted
1310
from tabulate import tabulate
1411
from sonic_py_common import multi_asic
@@ -35,10 +32,6 @@ FABRIC_PORT_STATUS_TABLE_PREFIX = APP_FABRIC_PORT_TABLE_NAME+"|"
3532
FABRIC_PORT_STATUS_FIELD = "STATUS"
3633
STATUS_NA = 'N/A'
3734

38-
cnstat_dir = 'N/A'
39-
cnstat_fqn_file_port = 'N/A'
40-
cnstat_fqn_file_queue = 'N/A'
41-
4235
class FabricStat(object):
4336
def __init__(self, namespace):
4437
self.db = None
@@ -85,12 +78,6 @@ class FabricStat(object):
8578
"""
8679
assert False, 'Need to override this method'
8780

88-
def save_fresh_stats(self):
89-
"""
90-
Get stat for each port and save.
91-
"""
92-
assert False, 'Need to override this method'
93-
9481
def cnstat_print(self, cnstat_dict, errors_only=False):
9582
"""
9683
Print the counter stat.
@@ -128,24 +115,6 @@ class FabricPortStat(FabricStat):
128115
cnstat_dict[port_name] = PortStat._make(cntr)
129116
return cnstat_dict
130117

131-
def save_fresh_stats(self):
132-
# Get stat for each port and save
133-
counter_port_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_FABRIC_PORT_NAME_MAP)
134-
if counter_port_name_map is None:
135-
return
136-
cnstat_dict = self.get_cnstat()
137-
asic_name = '0'
138-
if self.namespace:
139-
asic_name = multi_asic.get_asic_id_from_name(self.namespace)
140-
try:
141-
cnstat_fqn_file_port_name = cnstat_fqn_file_port + asic_name
142-
json.dump(cnstat_dict, open(cnstat_fqn_file_port_name, 'w'), default=json_serial)
143-
except IOError as e:
144-
print(e.errno, e)
145-
sys.exit(e.errno)
146-
else:
147-
print("Clear and update saved counters port")
148-
149118
def cnstat_print(self, cnstat_dict, errors_only=False):
150119
if len(cnstat_dict) == 0:
151120
print("Counters %s empty" % self.namespace)
@@ -158,44 +127,19 @@ class FabricPortStat(FabricStat):
158127
asic_name = '0'
159128
if self.namespace:
160129
asic_name = multi_asic.get_asic_id_from_name(self.namespace)
161-
162-
cnstat_fqn_file_port_name = cnstat_fqn_file_port + asic_name
163-
cnstat_cached_dict = {}
164-
if os.path.isfile(cnstat_fqn_file_port_name):
165-
try:
166-
cnstat_cached_dict = json.load(open(cnstat_fqn_file_port_name, 'r'))
167-
except IOError as e:
168-
print(e.errno, e)
169-
170130
for key, data in cnstat_dict.items():
171131
port_id = key[len(PORT_NAME_PREFIX):]
172-
port_name = "PORT" + port_id
173-
# The content in the for each port:
174-
# "IN_CELL, IN_OCTET, OUT_CELL, OUT_OCTET, CRC, FEC_CORRECTABLE, FEC_UNCORRECTABL, SYMBOL_ERR"
175-
# e.g. PORT76 ['0', '0', '36', '6669', '0', '13', '302626', '3']
176-
# Now, set default saved values to 0
177-
diff_cached = ['0', '0', '0', '0', '0', '0', '0', '0']
178-
if port_name in cnstat_cached_dict:
179-
diff_cached = cnstat_cached_dict.get(port_name)
180-
181132
if errors_only:
182133
header = portstat_header_errors_only
183134
table.append((asic_name, port_id, self.get_port_state(key),
184-
ns_diff(data.crc, diff_cached[4]),
185-
ns_diff(data.fec_correctable, diff_cached[5]),
186-
ns_diff(data.fec_uncorrectable, diff_cached[6]),
187-
ns_diff(data.symbol_err, diff_cached[7])))
135+
data.crc, data.fec_correctable, data.fec_uncorrectable,
136+
data.symbol_err))
188137
else:
189138
header = portstat_header_all
190139
table.append((asic_name, port_id, self.get_port_state(key),
191-
ns_diff(data.in_cell, diff_cached[0]),
192-
ns_diff(data.in_octet, diff_cached[1]),
193-
ns_diff(data.out_cell, diff_cached[2]),
194-
ns_diff(data.out_octet, diff_cached[3]),
195-
ns_diff(data.crc, diff_cached[4]),
196-
ns_diff(data.fec_correctable, diff_cached[5]),
197-
ns_diff(data.fec_uncorrectable, diff_cached[6]),
198-
ns_diff(data.symbol_err, diff_cached[7])))
140+
data.in_cell, data.in_octet, data.out_cell, data.out_octet,
141+
data.crc, data.fec_correctable, data.fec_uncorrectable,
142+
data.symbol_err))
199143

200144
print(tabulate(table, header, tablefmt='simple', stralign='right'))
201145
print()
@@ -222,24 +166,6 @@ class FabricQueueStat(FabricStat):
222166
cnstat_dict[port_queue_name] = QueueStat._make(cntr)
223167
return cnstat_dict
224168

225-
def save_fresh_stats(self):
226-
# Get stat for each port and save
227-
counter_port_name_map = self.db.get_all(self.db.COUNTERS_DB, COUNTERS_FABRIC_PORT_NAME_MAP)
228-
if counter_port_name_map is None:
229-
return
230-
cnstat_dict = self.get_cnstat()
231-
asic_name = '0'
232-
if self.namespace:
233-
asic_name = multi_asic.get_asic_id_from_name(self.namespace)
234-
try:
235-
cnstat_fqn_file_queue_name = cnstat_fqn_file_queue + asic_name
236-
json.dump(cnstat_dict, open(cnstat_fqn_file_queue_name, 'w'), default=json_serial)
237-
except IOError as e:
238-
print(e.errno, e)
239-
sys.exit(e.errno)
240-
else:
241-
print("Clear and update saved counters queue")
242-
243169
def cnstat_print(self, cnstat_dict, errors_only=False):
244170
if len(cnstat_dict) == 0:
245171
print("Counters %s empty" % self.namespace)
@@ -251,29 +177,11 @@ class FabricQueueStat(FabricStat):
251177
asic_name = '0'
252178
if self.namespace:
253179
asic_name = multi_asic.get_asic_id_from_name(self.namespace)
254-
255-
cnstat_fqn_file_queue_name = cnstat_fqn_file_queue + asic_name
256-
cnstat_cached_dict={}
257-
if os.path.isfile(cnstat_fqn_file_queue_name):
258-
try:
259-
cnstat_cached_dict = json.load(open(cnstat_fqn_file_queue_name, 'r'))
260-
except IOError as e:
261-
print(e.errno, e)
262-
263180
for key, data in cnstat_dict.items():
264181
port_name, queue_id = key.split(':')
265-
# The content of saved counters queue for each port:
266-
# portName:queueId CURRENT_LEVEL, WATERMARK_LEVEL, CURRENT_BYTE
267-
# e.g. PORT90:0 ['N/A', 'N/A', 'N/A']
268-
# Now, set default saved values to 0
269-
diff_cached = ['0', '0', '0']
270-
if key in cnstat_cached_dict:
271-
diff_cached = cnstat_cached_dict.get(key)
272182
port_id = port_name[len(PORT_NAME_PREFIX):]
273183
table.append((asic_name, port_id, self.get_port_state(port_name), queue_id,
274-
ns_diff(data.curbyte, diff_cached[2]),
275-
ns_diff(data.curlevel, diff_cached[0]),
276-
ns_diff(data.watermarklevel, diff_cached[1])))
184+
data.curbyte, data.curlevel, data.watermarklevel))
277185

278186
print(tabulate(table, queuestat_header, tablefmt='simple', stralign='right'))
279187
print()
@@ -306,10 +214,6 @@ class FabricReachability(FabricStat):
306214
return
307215

308216
def main():
309-
global cnstat_dir
310-
global cnstat_fqn_file_port
311-
global cnstat_fqn_file_queue
312-
313217
parser = argparse.ArgumentParser(description='Display the fabric port state and counters',
314218
formatter_class=argparse.RawTextHelpFormatter,
315219
epilog="""
@@ -319,40 +223,19 @@ Examples:
319223
fabricstat -p -n asic0 -e
320224
fabricstat -q
321225
fabricstat -q -n asic0
322-
fabricstat -C
323-
fabricstat -D
324226
""")
325227

326228
parser.add_argument('-q','--queue', action='store_true', help='Display fabric queue stat, otherwise port stat')
327229
parser.add_argument('-r','--reachability', action='store_true', help='Display reachability, otherwise port stat')
328230
parser.add_argument('-n','--namespace', default=None, help='Display fabric ports counters for specific namespace')
329231
parser.add_argument('-e', '--errors', action='store_true', help='Display errors')
330-
parser.add_argument('-C','--clear', action='store_true', help='Copy & clear fabric counters')
331-
parser.add_argument('-D','--delete', action='store_true', help='Delete saved stats')
332232

333233
args = parser.parse_args()
334234
queue = args.queue
335235
reachability = args.reachability
336236
namespace = args.namespace
337237
errors_only = args.errors
338238

339-
save_fresh_stats = args.clear
340-
delete_stats = args.delete
341-
342-
cache = UserCache()
343-
344-
cnstat_dir = cache.get_directory()
345-
346-
cnstat_file = "fabricstatport"
347-
cnstat_fqn_file_port = os.path.join(cnstat_dir, cnstat_file)
348-
349-
cnstat_file = "fabricstatqueue"
350-
cnstat_fqn_file_queue = os.path.join(cnstat_dir, cnstat_file)
351-
352-
if delete_stats:
353-
cache.remove()
354-
sys.exit(0)
355-
356239
def nsStat(ns, errors_only):
357240
if queue:
358241
stat = FabricQueueStat(ns)
@@ -363,10 +246,7 @@ Examples:
363246
else:
364247
stat = FabricPortStat(ns)
365248
cnstat_dict = stat.get_cnstat_dict()
366-
if save_fresh_stats:
367-
stat.save_fresh_stats()
368-
else:
369-
stat.cnstat_print(cnstat_dict, errors_only)
249+
stat.cnstat_print(cnstat_dict, errors_only)
370250

371251
if namespace is None:
372252
# All asics or all fabric asics

0 commit comments

Comments
 (0)