From patchwork Fri Apr 12 11:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luca Vizzarro X-Patchwork-Id: 139241 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 94EF943E51; Fri, 12 Apr 2024 13:12:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F094D40DCD; Fri, 12 Apr 2024 13:12:00 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id F0BEF40A75 for ; Fri, 12 Apr 2024 13:11:58 +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 A97DA113E; Fri, 12 Apr 2024 04:12:27 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.19.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 734A33F766; Fri, 12 Apr 2024 04:11:57 -0700 (PDT) From: Luca Vizzarro To: dev@dpdk.org Cc: =?utf-8?q?Juraj_Linke=C5=A1?= , Jeremy Spewock , Luca Vizzarro , Paul Szczepanek Subject: [PATCH 5/5] dts: add `show port stats` command to TestPmdShell Date: Fri, 12 Apr 2024 12:11:36 +0100 Message-Id: <20240412111136.3470304-6-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412111136.3470304-1-luca.vizzarro@arm.com> References: <20240412111136.3470304-1-luca.vizzarro@arm.com> MIME-Version: 1.0 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 Acked-by: Juraj Linkeš --- dts/framework/remote_session/testpmd_shell.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 3cf123ff57..baf47d1a32 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -519,6 +519,42 @@ class TestPmdPort(TextParser): ) +@dataclass +class TestPmdPortStats(TextParser): + """Port statistics.""" + + #: + port_id: int = field(metadata=parser.to_int(parser.regex(r"NIC statistics for port (\d+)"))) + + #: + rx_packets: int = field(metadata=parser.to_int(parser.regex(r"RX-packets:\s+(\d+)"))) + #: + rx_missed: int = field(metadata=parser.to_int(parser.regex(r"RX-missed:\s+(\d+)"))) + #: + rx_bytes: int = field(metadata=parser.to_int(parser.regex(r"RX-bytes:\s+(\d+)"))) + #: + rx_errors: int = field(metadata=parser.to_int(parser.regex(r"RX-errors:\s+(\d+)"))) + #: + rx_nombuf: int = field(metadata=parser.to_int(parser.regex(r"RX-nombuf:\s+(\d+)"))) + + #: + tx_packets: int = field(metadata=parser.to_int(parser.regex(r"TX-packets:\s+(\d+)"))) + #: + tx_errors: int = field(metadata=parser.to_int(parser.regex(r"TX-errors:\s+(\d+)"))) + #: + tx_bytes: int = field(metadata=parser.to_int(parser.regex(r"TX-bytes:\s+(\d+)"))) + + #: + rx_pps: int = field(metadata=parser.to_int(parser.regex(r"Rx-pps:\s+(\d+)"))) + #: + rx_bps: int = field(metadata=parser.to_int(parser.regex(r"Rx-bps:\s+(\d+)"))) + + #: + tx_pps: int = field(metadata=parser.to_int(parser.regex(r"Tx-pps:\s+(\d+)"))) + #: + tx_bps: int = field(metadata=parser.to_int(parser.regex(r"Tx-bps:\s+(\d+)"))) + + class TestPmdShell(InteractiveShell): """Testpmd interactive shell. @@ -696,6 +732,28 @@ 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.""" + output = self.send_command("show port stats all") + + iter = re.finditer(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. + """ + output = self.send_command(f"show port stats {port_id}") + 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", "")