From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2B86C4415E; Wed, 5 Jun 2024 16:45:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7BC6D427DE; Wed, 5 Jun 2024 16:45:24 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 45A32410E8 for ; Wed, 5 Jun 2024 16:45:22 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1C1DCDA7; Wed, 5 Jun 2024 07:45:46 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.40.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C6DE43F792; Wed, 5 Jun 2024 07:45:20 -0700 (PDT) From: Luca Vizzarro To: dev@dpdk.org Cc: Jeremy Spewock , =?UTF-8?q?Juraj=20Linke=C5=A1?= , Luca Vizzarro , Paul Szczepanek Subject: [PATCH v3 5/5] dts: add `show port stats` command to TestPmdShell Date: Wed, 5 Jun 2024 15:45:04 +0100 Message-Id: <20240605144504.361438-6-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605144504.361438-1-luca.vizzarro@arm.com> References: <20240412111136.3470304-1-luca.vizzarro@arm.com> <20240605144504.361438-1-luca.vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add a new TestPmdPortStats data structure to represent the output returned by `show port stats`, which is implemented as part of TestPmdShell. Bugzilla ID: 1407 Signed-off-by: Luca Vizzarro Reviewed-by: Paul Szczepanek --- dts/framework/remote_session/testpmd_shell.py | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index ab9a1f86a9..d413bf2cc7 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -571,6 +571,42 @@ class TestPmdPort(TextParser): ) +@dataclass +class TestPmdPortStats(TextParser): + """Port statistics.""" + + #: + port_id: int = field(metadata=TextParser.find_int(r"NIC statistics for port (\d+)")) + + #: + rx_packets: int = field(metadata=TextParser.find_int(r"RX-packets:\s+(\d+)")) + #: + rx_missed: int = field(metadata=TextParser.find_int(r"RX-missed:\s+(\d+)")) + #: + rx_bytes: int = field(metadata=TextParser.find_int(r"RX-bytes:\s+(\d+)")) + #: + rx_errors: int = field(metadata=TextParser.find_int(r"RX-errors:\s+(\d+)")) + #: + rx_nombuf: int = field(metadata=TextParser.find_int(r"RX-nombuf:\s+(\d+)")) + + #: + tx_packets: int = field(metadata=TextParser.find_int(r"TX-packets:\s+(\d+)")) + #: + tx_errors: int = field(metadata=TextParser.find_int(r"TX-errors:\s+(\d+)")) + #: + tx_bytes: int = field(metadata=TextParser.find_int(r"TX-bytes:\s+(\d+)")) + + #: + rx_pps: int = field(metadata=TextParser.find_int(r"Rx-pps:\s+(\d+)")) + #: + rx_bps: int = field(metadata=TextParser.find_int(r"Rx-bps:\s+(\d+)")) + + #: + tx_pps: int = field(metadata=TextParser.find_int(r"Tx-pps:\s+(\d+)")) + #: + tx_bps: int = field(metadata=TextParser.find_int(r"Tx-bps:\s+(\d+)")) + + class TestPmdShell(InteractiveShell): """Testpmd interactive shell. @@ -760,6 +796,45 @@ def show_port_info(self, port_id: int) -> TestPmdPort: return TestPmdPort.parse(output) + def show_port_stats_all(self) -> list[TestPmdPortStats]: + """Returns the statistics of all the ports. + + Returns: + list[TestPmdPortStats]: A list containing all the ports stats as `TestPmdPortStats`. + """ + output = self.send_command("show port stats all") + + # Sample output of the "all" command looks like: + # + # ########### NIC statistics for port 0 ########### + # values... + # ################################################# + # + # ########### NIC statistics for port 1 ########### + # values... + # ################################################# + # + iter = re.finditer(r"(^ #*.+#*$[^#]+)^ #*\r$", output, re.MULTILINE) + return [TestPmdPortStats.parse(block.group(1)) for block in iter] + + def show_port_stats(self, port_id: int) -> TestPmdPortStats: + """Returns the given port statistics. + + Args: + port_id: The port ID to gather information for. + + Raises: + InteractiveCommandExecutionError: If `port_id` is invalid. + + Returns: + TestPmdPortStats: An instance of `TestPmdPortStats` containing the given port's stats. + """ + output = self.send_command(f"show port stats {port_id}", skip_first_line=True) + if output.startswith("Invalid port"): + raise InteractiveCommandExecutionError("invalid port given") + + return TestPmdPortStats.parse(output) + def close(self) -> None: """Overrides :meth:`~.interactive_shell.close`.""" self.send_command("quit", "") -- 2.34.1