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 F1DC045A01; Mon, 23 Sep 2024 17:50:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 186B940608; Mon, 23 Sep 2024 17:50:03 +0200 (CEST) Received: from mail-pj1-f97.google.com (mail-pj1-f97.google.com [209.85.216.97]) by mails.dpdk.org (Postfix) with ESMTP id EF9D1402E3 for ; Mon, 23 Sep 2024 17:50:01 +0200 (CEST) Received: by mail-pj1-f97.google.com with SMTP id 98e67ed59e1d1-2d8a744aa9bso3051671a91.3 for ; Mon, 23 Sep 2024 08:50:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727106601; x=1727711401; 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=W0SbVrqd4Bo1FSWtCl6hG4raJ8WP+9oJf2tmRInToIX1ZXe5ZdhR/RhUZkntIrak9x TrgGZC8Ig3bSAZqD4/3gtUNvMUn1gNd0/OV9moDNOTdX/L6iPqVJ6AuMzBdzBPvtT0Bc cX2JbawJCw3XdShRo7e6vucVRfbXjErR32b60= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727106601; x=1727711401; 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=cdBqUqgTVn4n4HqqMNeT3n2gTjZlGp2ocXcJLdP/8qDRlYgmql5A6KlMA5FXVMwWRE 40keiivOhYFhAp6T6ShSuB6BfuLC9ExgzAgltUMUwa1X8S3OT+2BegHVSggs/EmQDsq7 6tE2cujovSbUhsbRuoygoX75Hz2bzl1mIP3Mvdgf+bUa1UfxtKE396TiUBk4NIdLAniP 7/Z/S70IEnbjuwhAw/yK1MLL+whU97aeG0BVhB7X157o6IfQTeAiokJy3rvHswZfuWSO IBowOn/+Y7TYJ/DJVgFXjQz4yEovuUDTk4H2CeODKoL+YcS7Qcv6STZI/mE0laGB7XUx edFQ== X-Gm-Message-State: AOJu0YyYAEzljn2zIDBahmiUyH7g0tIwRXeqEOGVYGYiQzt22LgeJ/rw bYswtaTWY/PmvJOPGX4KHip7Y9LfP8p1IOHnQfjAYhpnTR6uFI/DTzTAszCblAtqdh1CQB3Tu1e eLaUjBL9y4TksJapxyCZMD/DusCPXtYlITpimWxx0Pb62kuHX X-Google-Smtp-Source: AGHT+IHirOpaDd+c4IcX1Vghg2sT7YpbHaCcNSRC5/pyk36rJiVivAZ6EgiXI/QsnvtgKasrtp5SUC0V0k4B X-Received: by 2002:a17:90b:4b10:b0:2c4:b0f0:8013 with SMTP id 98e67ed59e1d1-2dd7f3cc29cmr15945787a91.11.1727106601075; Mon, 23 Sep 2024 08:50:01 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-2dd7f7a22c4sm462045a91.2.2024.09.23.08.50.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 08:50:01 -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 C6E6B605C351; Mon, 23 Sep 2024 11:49:59 -0400 (EDT) From: jspewock@iol.unh.edu To: paul.szczepanek@arm.com, thomas@monjalon.net, juraj.linkes@pantheon.tech, Honnappa.Nagarahalli@arm.com, npratte@iol.unh.edu, probb@iol.unh.edu, Luca.Vizzarro@arm.com, wathsala.vithanage@arm.com, yoan.picchi@foss.arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v3 1/2] dts: add clearing port stats to testpmd shell Date: Mon, 23 Sep 2024 11:49:35 -0400 Message-ID: <20240923154936.15952-2-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923154936.15952-1-jspewock@iol.unh.edu> References: <20240802172928.212277-1-jspewock@iol.unh.edu> <20240923154936.15952-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