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 B33EC45A11; Mon, 23 Sep 2024 17:44:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F536402D5; Mon, 23 Sep 2024 17:44:01 +0200 (CEST) Received: from mail-qv1-f97.google.com (mail-qv1-f97.google.com [209.85.219.97]) by mails.dpdk.org (Postfix) with ESMTP id DE0FD40274 for ; Mon, 23 Sep 2024 17:43:58 +0200 (CEST) Received: by mail-qv1-f97.google.com with SMTP id 6a1803df08f44-6c3603292abso44326206d6.1 for ; Mon, 23 Sep 2024 08:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727106238; x=1727711038; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YHFcd/IexCAx8lksOEgJWOBfC+tz0BKD+32InHtd3nc=; b=jq54Bz9evzgQnUJfQ6n0Vy6qWSLkgJKFaCmhBPTdx0JaVRuAj6oeblcXW4DPoy5Nib Fpz1590GreSb/I+YNvcsjCDCrcFBxTVXAfx3yG2fppkOK+MKeNXmTiEISUyoIftErwA8 0bOemWdf/VsyOvRvVCyCivAOdpw5c8YDRecbo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727106238; x=1727711038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YHFcd/IexCAx8lksOEgJWOBfC+tz0BKD+32InHtd3nc=; b=Ww72h9cH0hqtrVyQn4oFPXwvVMvlaRjWCMJP7Fb1lrVMQOHN+N1hsYvMCNeRpsVui+ kcNGzRqxhZ7FWwjhxpMc6xUzKDFOJeywvS46XuyboOx1bOFbq9924cgrerYOlRJxOcRM pNClEpeogVXUAOrJ4zIRfKZsflzDj8WCG6fFV9m9WiPDGgCWqo1gTFthEfjqqEMiBw/t 2b9e3iL86p8j25SxaF7R7xoiw6ay0QRuwN4ikQ5q0TLj/HtsDMa3amkzLGClneQlk4ZI 6DcSfuX4zL5ZNAJpnPKGI/mFgVD8CAhrn6dGr6SaJhsuz0gRr9eFZk2IRrVWKEwpM6Vw joZA== X-Gm-Message-State: AOJu0YwUci+QTvsLy8LxxpXbbPMQW+ch9jT7M0NmqmwykzMBsRMgIgnS MnedWDwe2DCua0BGzPnNqiFxFAq2h7cZOEpF3DqezzGWD7OhmkY7D8puWEiBkWnkbXz0Ac5SoUp 7bu/QIFQ05pf9MpCEtcDIfI2/AbeCN8qj X-Google-Smtp-Source: AGHT+IFELx0KqYVFc/2rFnXWvwx3JKtvOfmgaKMayVtEeaCfG3/yNVipQGcd7HiXfcp1IgGcUM2kXv4KntF8 X-Received: by 2002:a05:6214:281:b0:6c7:c034:f732 with SMTP id 6a1803df08f44-6c7c034f749mr155442496d6.21.1727106238237; Mon, 23 Sep 2024 08:43:58 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [132.177.123.84]) by smtp-relay.gmail.com with ESMTPS id 6a1803df08f44-6c75e491713sm4575276d6.33.2024.09.23.08.43.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 08:43:58 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id 722F0605C351; Mon, 23 Sep 2024 11:43:57 -0400 (EDT) From: jspewock@iol.unh.edu To: wathsala.vithanage@arm.com, thomas@monjalon.net, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, probb@iol.unh.edu, npratte@iol.unh.edu, alex.chapman@arm.com, Honnappa.Nagarahalli@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v2 1/2] dts: add clearing port stats and verbose mode to testpmd Date: Mon, 23 Sep 2024 11:43:45 -0400 Message-ID: <20240923154346.15390-2-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923154346.15390-1-jspewock@iol.unh.edu> References: <20240802172928.212277-1-jspewock@iol.unh.edu> <20240923154346.15390-1-jspewock@iol.unh.edu> 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 From: Jeremy Spewock Methods currently exist for querying the statistics of a port in testpmd, but there weren't methods added for clearing the current statistics on a port. This patch adds methods that allow you to clear the statistics of a single port or all ports to account for situations where the user only wants the port statistics after a certain point and does not care about any existing prior values. This patch also modifies the show_port_stats_all method to allow for it to return the raw testpmd output gathered from sending the command as well as the parsed output. This allows users to access and examine additional information provided by the raw output if needed. Depends-on: patch-144268 ("dts: add text parser for testpmd verbose output") Depends-on: patch-144270 ("dts: add VLAN methods to testpmd shell) Signed-off-by: Jeremy Spewock --- dts/framework/remote_session/testpmd_shell.py | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index affd37ba5b..c2267a7662 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -20,7 +20,7 @@ from dataclasses import dataclass, field from enum import Flag, auto from pathlib import PurePath -from typing import Any, Callable, ClassVar, Concatenate, ParamSpec +from typing import Any, Callable, ClassVar, Concatenate, ParamSpec, Tuple from typing_extensions import Self, Unpack @@ -1393,11 +1393,13 @@ def _update_port(self, port: TestPmdPort) -> None: for existing_port in self._ports ] - def show_port_stats_all(self) -> list[TestPmdPortStats]: + def show_port_stats_all(self) -> Tuple[list[TestPmdPortStats], str]: """Returns the statistics of all the ports. Returns: - list[TestPmdPortStats]: A list containing all the ports stats as `TestPmdPortStats`. + Tuple[str, list[TestPmdPortStats]]: A tuple where the first element is the stats of all + ports as `TestPmdPortStats` and second is the raw testpmd output that was collected + from the sent command. """ output = self.send_command("show port stats all") @@ -1412,7 +1414,7 @@ def show_port_stats_all(self) -> list[TestPmdPortStats]: # ################################################# # iter = re.finditer(r"(^ #*.+#*$[^#]+)^ #*\r$", output, re.MULTILINE) - return [TestPmdPortStats.parse(block.group(1)) for block in iter] + return ([TestPmdPortStats.parse(block.group(1)) for block in iter], output) def show_port_stats(self, port_id: int) -> TestPmdPortStats: """Returns the given port statistics. @@ -1675,6 +1677,45 @@ def set_verbose(self, level: int, verify: bool = True) -> None: f"Testpmd failed to set verbose level to {level}." ) + def clear_port_stats(self, port_id: int, verify: bool = True) -> None: + """Clear statistics of a given port. + + Args: + port_id: ID of the port to clear the statistics on. + verify: If :data:`True` the output of the command will be scanned to verify that it was + successful, otherwise failures will be ignored. Defaults to :data:`True`. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and testpmd fails to + clear the statistics of the given port. + """ + clear_output = self.send_command(f"clear port stats {port_id}") + if verify and f"NIC statistics for port {port_id} cleared" not in clear_output: + raise InteractiveCommandExecutionError( + f"Test pmd failed to set clear forwarding stats on port {port_id}" + ) + + def clear_port_stats_all(self, verify: bool = True) -> None: + """Clear the statistics of all ports that testpmd is aware of. + + Args: + verify: If :data:`True` the output of the command will be scanned to verify that all + ports had their statistics cleared, otherwise failures will be ignored. Defaults to + :data:`True`. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and testpmd fails to + clear the statistics of any of its ports. + """ + clear_output = self.send_command("clear port stats all") + if verify: + if type(self._app_params.ports) is list: + for port_id in range(len(self._app_params.ports)): + if f"NIC statistics for port {port_id} cleared" not in clear_output: + raise InteractiveCommandExecutionError( + f"Test pmd failed to set clear forwarding stats on port {port_id}" + ) + def _close(self) -> None: """Overrides :meth:`~.interactive_shell.close`.""" self.stop() -- 2.46.0