[v3] ethdev: telemetry xstats support hide zero

Message ID 20230214013506.49152-1-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v3] ethdev: telemetry xstats support hide zero |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

fengchengwen Feb. 14, 2023, 1:35 a.m. UTC
  The number of xstats may be large, after the hide zero option is added,
only non-zero values can be displayed.

So display xstats with hide zero:
	/ethdev/xstats,0,hide_zero=true
and without hide zero:
	/ethdev/xstats,0,hide_zero=false  or
	/ethdev/xstats,0

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>

---
v3: fix only hide_zero cause segment fault, support hide_zero=false,
    and these address Ferruh's comments.
v2: using hide_zero=true optional parameter which address Ferruh's
    comments.

---
 lib/ethdev/rte_ethdev.c | 43 +++++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)
  

Comments

Ferruh Yigit Feb. 14, 2023, 12:59 p.m. UTC | #1
On 2/14/2023 1:35 AM, Chengwen Feng wrote:
> The number of xstats may be large, after the hide zero option is added,
> only non-zero values can be displayed.
> 
> So display xstats with hide zero:
> 	/ethdev/xstats,0,hide_zero=true
> and without hide zero:
> 	/ethdev/xstats,0,hide_zero=false  or
> 	/ethdev/xstats,0
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>


Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>


Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index d25db35f7f..fa98af1f91 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -15,6 +15,7 @@ 
 #include <bus_driver.h>
 #include <rte_log.h>
 #include <rte_interrupts.h>
+#include <rte_kvargs.h>
 #include <rte_memcpy.h>
 #include <rte_common.h>
 #include <rte_mempool.h>
@@ -5863,27 +5864,54 @@  eth_dev_handle_port_stats(const char *cmd __rte_unused,
 	return 0;
 }
 
+static int
+eth_dev_parse_hide_zero(const char *key, const char *value, void *extra_args)
+{
+	RTE_SET_USED(key);
+
+	if (value == NULL)
+		return -1;
+
+	if (strcmp(value, "true") == 0)
+		*(bool *)extra_args = true;
+	else if (strcmp(value, "false") == 0)
+		*(bool *)extra_args = false;
+	else
+		return -1;
+
+	return 0;
+}
+
 static int
 eth_dev_handle_port_xstats(const char *cmd __rte_unused,
 		const char *params,
 		struct rte_tel_data *d)
 {
+	const char *const valid_keys[] = { "hide_zero", NULL };
 	struct rte_eth_xstat *eth_xstats;
 	struct rte_eth_xstat_name *xstat_names;
+	struct rte_kvargs *kvlist;
 	int port_id, num_xstats;
-	int i, ret;
+	bool hide_zero = false;
 	char *end_param;
+	int i, ret;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
 
 	port_id = strtoul(params, &end_param, 0);
-	if (*end_param != '\0')
-		RTE_ETHDEV_LOG(NOTICE,
-			"Extra parameters passed to ethdev telemetry command, ignoring");
 	if (!rte_eth_dev_is_valid_port(port_id))
 		return -1;
 
+	if (*end_param != '\0') {
+		kvlist = rte_kvargs_parse(end_param, valid_keys);
+		ret = rte_kvargs_process(kvlist, NULL, eth_dev_parse_hide_zero, &hide_zero);
+		if (kvlist == NULL || ret != 0)
+			RTE_ETHDEV_LOG(NOTICE,
+				"Unknown extra parameters passed to ethdev telemetry command, ignoring\n");
+		rte_kvargs_free(kvlist);
+	}
+
 	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
 	if (num_xstats < 0)
 		return -1;
@@ -5908,9 +5936,12 @@  eth_dev_handle_port_xstats(const char *cmd __rte_unused,
 	}
 
 	rte_tel_data_start_dict(d);
-	for (i = 0; i < num_xstats; i++)
+	for (i = 0; i < num_xstats; i++) {
+		if (hide_zero && eth_xstats[i].value == 0)
+			continue;
 		rte_tel_data_add_dict_uint(d, xstat_names[i].name,
 					   eth_xstats[i].value);
+	}
 	free(eth_xstats);
 	return 0;
 }
@@ -6328,7 +6359,7 @@  RTE_INIT(ethdev_init_telemetry)
 	rte_telemetry_register_cmd("/ethdev/stats", eth_dev_handle_port_stats,
 			"Returns the common stats for a port. Parameters: int port_id");
 	rte_telemetry_register_cmd("/ethdev/xstats", eth_dev_handle_port_xstats,
-			"Returns the extended stats for a port. Parameters: int port_id");
+			"Returns the extended stats for a port. Parameters: int port_id,hide_zero=true|false(Optional for indicates hide zero xstats)");
 #ifndef RTE_EXEC_ENV_WINDOWS
 	rte_telemetry_register_cmd("/ethdev/dump_priv", eth_dev_handle_port_dump_priv,
 			"Returns dump private information for a port. Parameters: int port_id");