Skip to content

CLI addition for PFC counters --history#3778

Merged
vmittal-msft merged 3 commits intosonic-net:masterfrom
peterbailey-arista:pfc-stat-hist-cli
Aug 4, 2025
Merged

CLI addition for PFC counters --history#3778
vmittal-msft merged 3 commits intosonic-net:masterfrom
peterbailey-arista:pfc-stat-hist-cli

Conversation

@peterbailey-arista
Copy link
Contributor

@peterbailey-arista peterbailey-arista commented Feb 25, 2025

What I did

  • Added a history option to pfcstat / show pfc counters
  • Added unit tests for single and multiasic cases of the history cli

These changes were made for the PFC Historical Statistics feature: sonic-net/SONiC#1904

How I did it

  • Additions made to pfcstat script with new --history option
  • Additions made to show CLI to take advantage of new --history option

How to verify it

  • Run the sonic-utilities unit tests
  • Run show pfc counters --history on a switch with these changes

New command output (if the output of a command-line utility has changed)

Example output of show pfc counters --history

     Port    Priority    RX Pause Transitions    Total RX Pause Time US    Recent RX Pause Time US    Recent RX Pause Timestamp
---------  ----------  ----------------------  ------------------------  -------------------------  ---------------------------
Ethernet0        PFC0                      12                    12,000                      1,200         01/10/2008, 21:20:00
Ethernet0        PFC1                      21                    20,001                      2,001         05/18/2033, 03:33:20
Ethernet0        PFC2                      22                    20,002                      2,002         05/18/2033, 03:33:20
Ethernet0        PFC3                      23                    20,003                      2,003         05/18/2033, 03:33:20
Ethernet0        PFC4                      24                    20,004                      2,004         05/18/2033, 03:33:20
Ethernet0        PFC5                      25                    20,005                      2,005         05/18/2033, 03:33:20
Ethernet0        PFC6                      26                    20,006                      2,006         05/18/2033, 03:33:20
Ethernet0        PFC7                      27                    20,007                      2,007         05/18/2033, 03:33:20

Ethernet4        PFC0                      14                    14,000                      1,400         05/13/2014, 16:53:20
Ethernet4        PFC1                      41                    40,001                      4,001         10/02/2096, 07:06:40
Ethernet4        PFC2                      42                    40,002                      4,002         10/02/2096, 07:06:40
Ethernet4        PFC3                      43                    40,003                      4,003         10/02/2096, 07:06:40
Ethernet4        PFC4                      44                    40,004                      4,004         10/02/2096, 07:06:40
Ethernet4        PFC5                      45                    40,005                      4,005         10/02/2096, 07:06:40
Ethernet4        PFC6                      46                    40,006                      4,006         10/02/2096, 07:06:40
Ethernet4        PFC7                      47                    40,007                      4,007         10/02/2096, 07:06:40

Ethernet8        PFC0                      18                    18,000                      1,800         01/15/2027, 08:00:00
Ethernet8        PFC1                      81                    80,001                      8,001         07/06/2223, 14:13:20
Ethernet8        PFC2                      82                    80,002                      8,002         07/06/2223, 14:13:20
Ethernet8        PFC3                      83                    80,003                      8,003         07/06/2223, 14:13:20
Ethernet8        PFC4                      84                    80,004                      8,004         07/06/2223, 14:13:20
Ethernet8        PFC5                      85                    80,005                      8,005         07/06/2223, 14:13:20
Ethernet8        PFC6                      86                    80,006                      8,006         07/06/2223, 14:13:20
Ethernet8        PFC7                      87                    80,007                      8,007         07/06/2223, 14:13:20

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

print("Last cached time was " + str(cnstat_cached_dict.get('time')))
pfcstat.cnstat_diff_print(cnstat_dict_rx, cnstat_cached_dict, True)
except IOError as e:
print(e.errno, e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(e.errno, e)

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing!
I updated to address the feedback, but the design has also changed a bit since your comments.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Please note the usage of `# flake8: noqa: E501` in assert_show_output.py
to account for the length of show command output strings.
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vmittal-msft vmittal-msft merged commit d3bc688 into sonic-net:master Aug 4, 2025
7 checks passed
@qiluo-msft
Copy link
Contributor

This change will break sonic-mgmt testcase. @peterbailey-arista Could you fix the testcase?

def extract_pfcwd_config(duthost, start_pfcwd):
    """
    Extract pfcwd info from running config

    Args:
        duthost: DUT host object

    Yields:
        pfcwd_config: dict of dicts with interface as the 1st level key and 'action', 'detect_time',
                      'restore_time' as the 2nd level keys
    """
    output = duthost.command('show pfcwd config')
    pytest_assert('Ethernet' in output['stdout'], 'No ports found in the pfcwd config')

    pfcwd_config = defaultdict()
    for line in output['stdout_lines']:
        if line.strip().startswith('Ethernet'):
            port, action, detect, restore = line.split()
            pfcwd_config.update({port: {'action': action,
                                        'detect_time': detect,
                                        'restore_time': restore}})

    yield pfcwd_config
12/09/2025 05:44:18 __init__._fixture_generator_decorator    L0088 ERROR  | 
ValueError('too many values to unpack (expected 4)')
Traceback (most recent call last):
  File "/var/src/sonic-mgmt/tests/common/plugins/log_section_start/__init__.py", line 84, in _fixture_generator_decorator
    res = next(it)
  File "/var/src/sonic-mgmt/tests/generic_config_updater/test_pfcwd_status.py", line 162, in extract_pfcwd_config
    port, action, detect, restore = line.split()
ValueError: too many values to unpack (expected 4)

YairRaviv pushed a commit to YairRaviv/sonic-utilities that referenced this pull request Jan 12, 2026
* Add history option to pfcstat cli
* Unit tests for pfcstat history cli
Please note the usage of `# flake8: noqa: E501` in assert_show_output.py
to account for the length of show command output strings.
* Add pfc counters history flag to utilities documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants