Skip to content

Commit 7dc40ac

Browse files
Fixed the issues with sonic-clear queuecounter for egress queue and voq (sonic-net#3671)
Fixed the sonic-clear queuecounter issues reported in sonic-net#20913 For the egress queue counters, after the queue counter is cleared and show is issued with --nonzero option, the code takes the elif path at line 323 (old code) even if the diff between cached counter and current counter is 0, prints the current counter values from counter_db . This issue was for both egress queue counter and voq counter. When the sonic-clear queuecounter is issued , the queuestat is called first without --voq option and this gets the port names and queue ids for each port in each asic , reads the egress queue counters and cache the values in /tmp/cache/queuestat/. Then queuestat is called with --voq option and this gets all the system ports names and voq id's for each asic , reads the voq counters and cache the values in /tmp/cache/queuestat. Since each asic has the all the system ports and all the voqs, and since the cache file name is queuestat+system_port_name with out asic namespace, caching asic1's voq counters overwrites the asic0's voq counters . How I did it 1)Corrected the logic mistake for issue 1. Since cnstat_diff_print is called only if cache file is present and this should print only if non-zero & valid diff or (not non-zero ) 2) Added asic namespace with the cache file name for vow counters. Signed-off-by: saksarav <[email protected]>
1 parent 72ee4fc commit 7dc40ac

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

scripts/queuestat

+20-23
Original file line numberDiff line numberDiff line change
@@ -294,38 +294,27 @@ class Queuestat(object):
294294
old_cntr = cnstat_old_dict.get(key)
295295
if old_cntr is not None:
296296
if self.voq:
297-
if not non_zero or ns_diff(cntr['totalpacket'], old_cntr['totalpacket']) != '0' or \
297+
if not non_zero or ns_diff(cntr['totalpacket'], old_cntr['totalpacket']) != '0' or \
298298
ns_diff(cntr['totalbytes'], old_cntr['totalbytes']) != '0' or \
299299
ns_diff(cntr['droppacket'], old_cntr['droppacket']) != '0' or \
300300
ns_diff(cntr['dropbytes'], old_cntr['dropbytes']) != '0' or \
301301
ns_diff(cntr['creditWDpkts'], old_cntr['creditWDpkts']) != '0':
302-
table.append((port, cntr['queuetype'] + str(cntr['queueindex']),
302+
table.append((port, cntr['queuetype'] + str(cntr['queueindex']),
303303
ns_diff(cntr['totalpacket'], old_cntr['totalpacket']),
304304
ns_diff(cntr['totalbytes'], old_cntr['totalbytes']),
305305
ns_diff(cntr['droppacket'], old_cntr['droppacket']),
306306
ns_diff(cntr['dropbytes'], old_cntr['dropbytes']),
307307
ns_diff(cntr['creditWDpkts'], old_cntr['creditWDpkts'])))
308-
elif not non_zero or cntr['totalpacket'] != '0' or cntr['totalbytes'] != '0' or \
309-
cntr['droppacket'] != '0' or cntr['dropbytes'] != '0' or cntr['creditWDpkts'] != '0':
310-
table.append((port, cntr['queuetype'] + str(cntr['queueindex']),
311-
cntr['totalpacket'], cntr['totalbytes'],
312-
cntr['droppacket'], cntr['dropbytes'], cntr['creditWDpkts']))
313308
else:
314-
if not non_zero or ns_diff(cntr['totalpacket'], old_cntr['totalpacket']) != '0' or \
309+
if not non_zero or ns_diff(cntr['totalpacket'], old_cntr['totalpacket']) != '0' or \
315310
ns_diff(cntr['totalbytes'], old_cntr['totalbytes']) != '0' or \
316311
ns_diff(cntr['droppacket'], old_cntr['droppacket']) != '0' or \
317312
ns_diff(cntr['dropbytes'], old_cntr['dropbytes']) != '0':
318-
table.append((port, cntr['queuetype'] + str(cntr['queueindex']),
319-
ns_diff(cntr['totalpacket'], old_cntr['totalpacket']),
320-
ns_diff(cntr['totalbytes'], old_cntr['totalbytes']),
321-
ns_diff(cntr['droppacket'], old_cntr['droppacket']),
322-
ns_diff(cntr['dropbytes'], old_cntr['dropbytes'])))
323-
elif not non_zero or cntr['totalpacket'] != '0' or cntr['totalbytes'] != '0' or \
324-
cntr['droppacket'] != '0' or cntr['dropbytes'] != '0':
325-
table.append((port, cntr['queuetype'] + str(cntr['queueindex']),
326-
cntr['totalpacket'], cntr['totalbytes'],
327-
cntr['droppacket'], cntr['dropbytes']))
328-
313+
table.append((port, cntr['queuetype'] + str(cntr['queueindex']),
314+
ns_diff(cntr['totalpacket'], old_cntr['totalpacket']),
315+
ns_diff(cntr['totalbytes'], old_cntr['totalbytes']),
316+
ns_diff(cntr['droppacket'], old_cntr['droppacket']),
317+
ns_diff(cntr['dropbytes'], old_cntr['dropbytes'])))
329318
if json_opt:
330319
json_output[port].update(build_json(port, table, self.voq))
331320
return json_output
@@ -346,8 +335,10 @@ class Queuestat(object):
346335
for port in natsorted(self.counter_port_name_map):
347336
json_output[port] = {}
348337
cnstat_dict = self.get_cnstat(self.port_queues_map[port])
349-
350-
cnstat_fqn_file_name = cnstat_fqn_file + port
338+
cache_ns = ''
339+
if self.voq and self.namespace is not None:
340+
cache_ns = '-' + self.namespace + '-'
341+
cnstat_fqn_file_name = cnstat_fqn_file + cache_ns + port
351342
if os.path.isfile(cnstat_fqn_file_name):
352343
try:
353344
cnstat_cached_dict = json.load(open(cnstat_fqn_file_name, 'r'))
@@ -378,7 +369,10 @@ class Queuestat(object):
378369

379370
# Get stat for the port queried
380371
cnstat_dict = self.get_cnstat(self.port_queues_map[port])
381-
cnstat_fqn_file_name = cnstat_fqn_file + port
372+
cache_ns = ''
373+
if self.voq and self.namespace is not None:
374+
cache_ns = '-' + self.namespace + '-'
375+
cnstat_fqn_file_name = cnstat_fqn_file + cache_ns + port
382376
json_output = {}
383377
json_output[port] = {}
384378
if os.path.isfile(cnstat_fqn_file_name):
@@ -403,10 +397,13 @@ class Queuestat(object):
403397

404398
def save_fresh_stats(self):
405399
# Get stat for each port and save
400+
cache_ns = ''
401+
if self.voq and self.namespace is not None:
402+
cache_ns = '-' + self.namespace + '-'
406403
for port in natsorted(self.counter_port_name_map):
407404
cnstat_dict = self.get_cnstat(self.port_queues_map[port])
408405
try:
409-
json.dump(cnstat_dict, open(cnstat_fqn_file + port, 'w'), default=json_serial)
406+
json.dump(cnstat_dict, open(cnstat_fqn_file + cache_ns + port, 'w'), default=json_serial)
410407
except IOError as e:
411408
print(e.errno, e)
412409
sys.exit(e.errno)

0 commit comments

Comments
 (0)