[v2] app/procinfo: add xstats parameter to hide zero

Message ID 20250207031333.1782995-1-huangdengdui@huawei.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series [v2] app/procinfo: add xstats parameter to 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/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-sample-apps-testing warning Testing issues

Commit Message

Dengdui Huang Feb. 7, 2025, 3:13 a.m. UTC
The number of xstats may be large, after the hide zero parameter to
hide zero only non-zero values can be displayed.

So display xstats with hide zero:
    dpdk-proc-info --proc-type=secondary -- --xstats
and without hide zero:
    dpdk-proc-info --proc-type=secondary -- --xstats=hide_zero

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/proc-info/main.c           | 20 ++++++++++++++------
 doc/guides/tools/proc_info.rst |  7 ++++---
 2 files changed, 18 insertions(+), 9 deletions(-)
  

Comments

Thomas Monjalon Feb. 12, 2025, 1:21 p.m. UTC | #1
07/02/2025 04:13, Dengdui Huang:
> The number of xstats may be large, after the hide zero parameter to
> hide zero only non-zero values can be displayed.
> 
> So display xstats with hide zero:
>     dpdk-proc-info --proc-type=secondary -- --xstats
> and without hide zero:
>     dpdk-proc-info --proc-type=secondary -- --xstats=hide_zero
> 
> Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
> Acked-by: Chengwen Feng <fengchengwen@huawei.com>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Applied, thanks.
  

Patch

diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index e1272164b1..be67386658 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -61,6 +61,7 @@  static unsigned long enabled_port_mask;
 static uint32_t enable_stats;
 /* Enable xstats. */
 static uint32_t enable_xstats;
+static uint32_t enable_xstats_hide_zero;
 /* Enable collectd format */
 static uint32_t enable_collectd_format;
 /* FD to send collectd format messages to STDOUT */
@@ -162,8 +163,8 @@  proc_info_usage(const char *prgname)
 		"  -m to display DPDK memory zones, segments and TAILQ information\n"
 		"  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
 		"  --stats: to display port statistics, enabled by default\n"
-		"  --xstats: to display extended port statistics, disabled by "
-			"default\n"
+		"  --xstats[=hide_zero]: to display extended port statistics, disabled by default, "
+			"support hide zero.\n"
 #ifdef RTE_LIB_METRICS
 		"  --metrics: to display derived metrics of the ports, disabled by "
 			"default\n"
@@ -425,7 +426,7 @@  proc_info_parse_args(int argc, char **argv)
 	static struct option long_option[] = {
 		{"stats", 0, NULL, 0},
 		{"stats-reset", 0, NULL, 0},
-		{"xstats", 0, NULL, 0},
+		{"xstats", optional_argument, NULL, 0},
 #ifdef RTE_LIB_METRICS
 		{"metrics", 0, NULL, 0},
 #endif
@@ -476,12 +477,17 @@  proc_info_parse_args(int argc, char **argv)
 		case 0:
 			/* Print stats */
 			if (!strncmp(long_option[option_index].name, "stats",
-					MAX_LONG_OPT_SZ))
+					MAX_LONG_OPT_SZ)) {
 				enable_stats = 1;
 			/* Print xstats */
-			else if (!strncmp(long_option[option_index].name, "xstats",
-					MAX_LONG_OPT_SZ))
+			} else if (!strncmp(long_option[option_index].name, "xstats",
+					MAX_LONG_OPT_SZ)) {
 				enable_xstats = 1;
+				if (optarg != NULL && !strncmp(optarg, "hide_zero",
+				    MAX_LONG_OPT_SZ))
+					enable_xstats_hide_zero = 1;
+
+			}
 #ifdef RTE_LIB_METRICS
 			else if (!strncmp(long_option[option_index].name,
 					"metrics",
@@ -850,6 +856,8 @@  nic_xstats_display(uint16_t port_id)
 	}
 
 	for (i = 0; i < len; i++) {
+		if (enable_xstats_hide_zero && values[i] == 0)
+			continue;
 		if (enable_collectd_format) {
 			char counter_type[MAX_STRING_LEN];
 			char buf[MAX_STRING_LEN];
diff --git a/doc/guides/tools/proc_info.rst b/doc/guides/tools/proc_info.rst
index bb483afbce..e623d71785 100644
--- a/doc/guides/tools/proc_info.rst
+++ b/doc/guides/tools/proc_info.rst
@@ -17,7 +17,7 @@  The application has a number of command line options:
 
 .. code-block:: console
 
-   ./<build_dir>/app/dpdk-proc-info -- -m | [-p PORTMASK] [--stats | --xstats |
+   ./<build_dir>/app/dpdk-proc-info -- -m | [-p PORTMASK] [--stats | --xstats[=hide_zero] |
    --stats-reset | --xstats-reset] [ --show-port | --show-tm | --show-crypto |
    --show-ring[=name] | --show-mempool[=name] | --iter-mempool=name |
    --show-port-private | --version | --firmware-version | --show-rss-reta |
@@ -34,9 +34,10 @@  Parameters
 The stats parameter controls the printing of generic port statistics. If no
 port mask is specified stats are printed for all DPDK ports.
 
-**--xstats**
+**--xstats[=hide_zero]**
 The xstats parameter controls the printing of extended port statistics. If no
-port mask is specified xstats are printed for all DPDK ports.
+port mask is specified xstats are printed for all DPDK ports. Specifying the
+hide_zero value to display xstats with hide zero.
 
 **--stats-reset**
 The stats-reset parameter controls the resetting of generic port statistics. If