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 8155A43F7C; Thu, 9 May 2024 13:27:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D1A940DDA; Thu, 9 May 2024 13:26:55 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 2939F40A6F for ; Thu, 9 May 2024 13:26:52 +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 318CB12FC; Thu, 9 May 2024 04:27:17 -0700 (PDT) Received: from localhost.localdomain (unknown [10.1.194.74]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0B6313F6A8; Thu, 9 May 2024 04:26:50 -0700 (PDT) From: Luca Vizzarro To: dev@dpdk.org Cc: =?UTF-8?q?Juraj=20Linke=C5=A1?= , Jeremy Spewock , Luca Vizzarro , Paul Szczepanek Subject: [PATCH v2 5/5] dts: add `show port stats` command to TestPmdShell Date: Thu, 9 May 2024 12:26:35 +0100 Message-Id: <20240509112635.1170557-6-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240509112635.1170557-1-luca.vizzarro@arm.com> References: <20240412111136.3470304-1-luca.vizzarro@arm.com> <20240509112635.1170557-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 | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 7910e17fed..d0b6da50f0 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -531,6 +531,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. @@ -713,6 +749,38 @@ 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") + + # Sample output of the "all" command looks like: + # + # ########### NIC statistics for port 0 ########### + # values... + # ################################################# + # + # ########### NIC statistics for port 1 ########### + # values... + # ################################################# + # + 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}", 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