diff mbox series

[v2,11/11] app/testpmd: add option to display extended statistics

Message ID 20210722095433.1898589-12-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers show
Series net/sfc: provide Rx/Tx doorbells stats | expand

Checks

Context Check Description
ci/iol-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot success github build: passed
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko July 22, 2021, 9:54 a.m. UTC
From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>

Add 'display-xstats' option for using in accompanying with Rx/Tx statistics
(i.e. 'stats-period' option or 'show port stats' interactive command) to
display specified list of extended statistics.

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/test-pmd/cmdline.c                |  56 ++++++++++++
 app/test-pmd/config.c                 |  66 ++++++++++++++
 app/test-pmd/parameters.c             |  18 ++++
 app/test-pmd/testpmd.c                | 122 ++++++++++++++++++++++++++
 app/test-pmd/testpmd.h                |  21 +++++
 doc/guides/testpmd_app_ug/run_app.rst |   5 ++
 6 files changed, 288 insertions(+)

Comments

David Marchand July 22, 2021, 7:43 p.m. UTC | #1
On Thu, Jul 22, 2021 at 11:55 AM Andrew Rybchenko
<andrew.rybchenko@oktetlabs.ru> wrote:
>
> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
>
> Add 'display-xstats' option for using in accompanying with Rx/Tx statistics
> (i.e. 'stats-period' option or 'show port stats' interactive command) to
> display specified list of extended statistics.
>
> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

$ build/app/dpdk-testpmd -c 3 --no-huge -m 20 -a 0:0.0 --vdev
net_null1 --vdev net_null2 -- --no-mlockall --total-num-mbufs=2048
--stats-period 1 --display-xstats a,
EAL: Detected 8 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Detected static linkage of DPDK
EAL: Multi-process socket /run/user/114840/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'VA'
max names is 2
^^^^^^^^^^^^^^

Useless printf debug.
I can remove it when applying.


testpmd: create a new mbuf pool <mb_pool_0>: n=2048, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Configuring Port 0 (socket 0)
Port 0: 26:45:E7:40:23:6E
Configuring Port 1 (socket 0)
Port 1: BA:5B:47:48:E6:AC
Checking link statuses...
No xstat 'a' on port 0 - skip it
No xstat 'a' on port 1 - skip it
Done
No xstat 'a' on port 0 - skip it
No xstat 'a' on port 1 - skip it
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

xstats are resolved twice (at least?) per port.
This is harmless afaics.
Can you double check?


No commandline core given, start packet forwarding
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support
enabled, MP allocation mode: native
David Marchand July 22, 2021, 8:15 p.m. UTC | #2
On Thu, Jul 22, 2021 at 11:55 AM Andrew Rybchenko
<andrew.rybchenko@oktetlabs.ru> wrote:
>
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 8468018cf3..baffef1642 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -3609,6 +3609,62 @@ cmdline_parse_inst_t cmd_stop = {
>
>  /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
>
> +int
> +parse_xstats_list(char *in_str, struct rte_eth_xstat_name **xstats,
> +                 unsigned int *xstats_num)

I had saved this comment as it seemed harmless, but in_str can be constified.
And well, mingw build seems picky about it:

[5/20] Compiling C object app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj
FAILED: app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj
x86_64-w64-mingw32-gcc -Iapp/dpdk-testpmd.exe.p -Iapp -I../../dpdk/app
-Ilib/ethdev -I../../dpdk/lib/ethdev -I. -I../../dpdk -Iconfig
-I../../dpdk/config -Ilib/eal/include -I../../dpdk/lib/eal/include
-Ilib/eal/windows/include -I../../dpdk/lib/eal/windows/include
-Ilib/eal/x86/include -I../../dpdk/lib/eal/x86/include
-Ilib/eal/common -I../../dpdk/lib/eal/common -Ilib/eal
-I../../dpdk/lib/eal -Ilib/kvargs -I../../dpdk/lib/kvargs -Ilib/net
-I../../dpdk/lib/net -Ilib/mbuf -I../../dpdk/lib/mbuf -Ilib/mempool
-I../../dpdk/lib/mempool -Ilib/ring -I../../dpdk/lib/ring -Ilib/meter
-I../../dpdk/lib/meter -Ilib/metrics -I../../dpdk/lib/metrics
-Ilib/telemetry -I../../dpdk/lib/telemetry -Ilib/gro
-I../../dpdk/lib/gro -Ilib/gso -I../../dpdk/lib/gso -Ilib/cmdline
-I../../dpdk/lib/cmdline -Idrivers/bus/pci
-I../../dpdk/drivers/bus/pci -I../../dpdk/drivers/bus/pci/windows
-Ilib/pci -I../../dpdk/lib/pci -Ilib/bitratestats
-I../../dpdk/lib/bitratestats -Ilib/pdump -I../../dpdk/lib/pdump
-Ilib/latencystats -I../../dpdk/lib/latencystats -Idrivers/net/i40e
-I../../dpdk/drivers/net/i40e -Idrivers/net/i40e/base
-I../../dpdk/drivers/net/i40e/base -Idrivers/bus/vdev
-I../../dpdk/drivers/bus/vdev -Ilib/hash -I../../dpdk/lib/hash
-Ilib/rcu -I../../dpdk/lib/rcu -fdiagnostics-color=always -pipe
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O2 -g -include
rte_config.h -Wextra -Wcast-qual -Wdeprecated -Wformat
-Wformat-nonliteral -Wformat-security -Wmissing-declarations
-Wmissing-prototypes -Wnested-externs -Wold-style-definition
-Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wundef
-Wwrite-strings -Wno-address-of-packed-member -Wno-packed-not-aligned
-Wno-missing-field-initializers -D_GNU_SOURCE -D_WIN32_WINNT=0x0A00
-D__USE_MINGW_ANSI_STDIO -mno-avx512f -march=native
-DALLOW_EXPERIMENTAL_API -Wno-deprecated-declarations -MD -MQ
app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj -MF
app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj.d -o
app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj -c
../../dpdk/app/test-pmd/parameters.c
In file included from ../../dpdk/app/test-pmd/parameters.c:6:
../../dpdk/app/test-pmd/parameters.c: In function 'launch_args_parse':
../../dpdk/lib/eal/windows/include/getopt.h:38:16: error: passing
argument 1 of 'parse_xstats_list' discards 'const' qualifier from
pointer target type [-Werror=discarded-qualifiers]
   38 | #define optarg usual_optarg
      |                ^~~~~~~~~~~~
../../dpdk/app/test-pmd/parameters.c:699:28: note: in expansion of
macro 'optarg'
  699 |     rc = parse_xstats_list(optarg, &xstats_display,
      |                            ^~~~~~
In file included from ../../dpdk/app/test-pmd/parameters.c:46:
../../dpdk/app/test-pmd/testpmd.h:787:29: note: expected 'char *' but
argument is of type 'const char *'
  787 | int parse_xstats_list(char *in_str, struct rte_eth_xstat_name **xstats,
      |                       ~~~~~~^~~~~~
cc1: all warnings being treated as errors
[19/20] Compiling C object app/dpdk-testpmd.exe.p/test-pmd_cmdline.c.obj
Andrew Rybchenko July 23, 2021, 1:08 p.m. UTC | #3
Hi David,

On 7/22/21 11:15 PM, David Marchand wrote:
> On Thu, Jul 22, 2021 at 11:55 AM Andrew Rybchenko
> <andrew.rybchenko@oktetlabs.ru> wrote:
>>
>> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
>> index 8468018cf3..baffef1642 100644
>> --- a/app/test-pmd/cmdline.c
>> +++ b/app/test-pmd/cmdline.c
>> @@ -3609,6 +3609,62 @@ cmdline_parse_inst_t cmd_stop = {
>>
>>   /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
>>
>> +int
>> +parse_xstats_list(char *in_str, struct rte_eth_xstat_name **xstats,
>> +                 unsigned int *xstats_num)
> 
> I had saved this comment as it seemed harmless, but in_str can be constified.
> And well, mingw build seems picky about it:
> 
> [5/20] Compiling C object app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj
> FAILED: app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj
> x86_64-w64-mingw32-gcc -Iapp/dpdk-testpmd.exe.p -Iapp -I../../dpdk/app
> -Ilib/ethdev -I../../dpdk/lib/ethdev -I. -I../../dpdk -Iconfig
> -I../../dpdk/config -Ilib/eal/include -I../../dpdk/lib/eal/include
> -Ilib/eal/windows/include -I../../dpdk/lib/eal/windows/include
> -Ilib/eal/x86/include -I../../dpdk/lib/eal/x86/include
> -Ilib/eal/common -I../../dpdk/lib/eal/common -Ilib/eal
> -I../../dpdk/lib/eal -Ilib/kvargs -I../../dpdk/lib/kvargs -Ilib/net
> -I../../dpdk/lib/net -Ilib/mbuf -I../../dpdk/lib/mbuf -Ilib/mempool
> -I../../dpdk/lib/mempool -Ilib/ring -I../../dpdk/lib/ring -Ilib/meter
> -I../../dpdk/lib/meter -Ilib/metrics -I../../dpdk/lib/metrics
> -Ilib/telemetry -I../../dpdk/lib/telemetry -Ilib/gro
> -I../../dpdk/lib/gro -Ilib/gso -I../../dpdk/lib/gso -Ilib/cmdline
> -I../../dpdk/lib/cmdline -Idrivers/bus/pci
> -I../../dpdk/drivers/bus/pci -I../../dpdk/drivers/bus/pci/windows
> -Ilib/pci -I../../dpdk/lib/pci -Ilib/bitratestats
> -I../../dpdk/lib/bitratestats -Ilib/pdump -I../../dpdk/lib/pdump
> -Ilib/latencystats -I../../dpdk/lib/latencystats -Idrivers/net/i40e
> -I../../dpdk/drivers/net/i40e -Idrivers/net/i40e/base
> -I../../dpdk/drivers/net/i40e/base -Idrivers/bus/vdev
> -I../../dpdk/drivers/bus/vdev -Ilib/hash -I../../dpdk/lib/hash
> -Ilib/rcu -I../../dpdk/lib/rcu -fdiagnostics-color=always -pipe
> -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O2 -g -include
> rte_config.h -Wextra -Wcast-qual -Wdeprecated -Wformat
> -Wformat-nonliteral -Wformat-security -Wmissing-declarations
> -Wmissing-prototypes -Wnested-externs -Wold-style-definition
> -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wundef
> -Wwrite-strings -Wno-address-of-packed-member -Wno-packed-not-aligned
> -Wno-missing-field-initializers -D_GNU_SOURCE -D_WIN32_WINNT=0x0A00
> -D__USE_MINGW_ANSI_STDIO -mno-avx512f -march=native
> -DALLOW_EXPERIMENTAL_API -Wno-deprecated-declarations -MD -MQ
> app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj -MF
> app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj.d -o
> app/dpdk-testpmd.exe.p/test-pmd_parameters.c.obj -c
> ../../dpdk/app/test-pmd/parameters.c
> In file included from ../../dpdk/app/test-pmd/parameters.c:6:
> ../../dpdk/app/test-pmd/parameters.c: In function 'launch_args_parse':
> ../../dpdk/lib/eal/windows/include/getopt.h:38:16: error: passing
> argument 1 of 'parse_xstats_list' discards 'const' qualifier from
> pointer target type [-Werror=discarded-qualifiers]
>     38 | #define optarg usual_optarg
>        |                ^~~~~~~~~~~~
> ../../dpdk/app/test-pmd/parameters.c:699:28: note: in expansion of
> macro 'optarg'
>    699 |     rc = parse_xstats_list(optarg, &xstats_display,
>        |                            ^~~~~~
> In file included from ../../dpdk/app/test-pmd/parameters.c:46:
> ../../dpdk/app/test-pmd/testpmd.h:787:29: note: expected 'char *' but
> argument is of type 'const char *'
>    787 | int parse_xstats_list(char *in_str, struct rte_eth_xstat_name **xstats,
>        |                       ~~~~~~^~~~~~
> cc1: all warnings being treated as errors
> [19/20] Compiling C object app/dpdk-testpmd.exe.p/test-pmd_cmdline.c.obj


Many thanks, I'll send v3 shortly with fixes applied to avoid
dup resolution, remove debug printout and make mingw build happy.

Andrew.
diff mbox series

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 8468018cf3..baffef1642 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -3609,6 +3609,62 @@  cmdline_parse_inst_t cmd_stop = {
 
 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
 
+int
+parse_xstats_list(char *in_str, struct rte_eth_xstat_name **xstats,
+		  unsigned int *xstats_num)
+{
+	int max_names_nb, names_nb;
+	int stringlen;
+	char **names;
+	char *str;
+	int ret;
+	int i;
+
+	names = NULL;
+	str = strdup(in_str);
+	if (str == NULL) {
+		ret = ENOMEM;
+		goto out;
+	}
+	stringlen = strlen(str);
+
+	for (i = 0, max_names_nb = 1; str[i] != '\0'; i++) {
+		if (str[i] == ',')
+			max_names_nb++;
+	}
+
+	names = calloc(max_names_nb, sizeof(*names));
+	if (names == NULL) {
+		ret = ENOMEM;
+		goto out;
+	}
+
+	names_nb = rte_strsplit(str, stringlen, names, max_names_nb, ',');
+	printf("max names is %d\n", max_names_nb);
+	if (names_nb < 0) {
+		ret = EINVAL;
+		goto out;
+	}
+
+	*xstats = calloc(names_nb, sizeof(**xstats));
+	if (*xstats == NULL) {
+		ret = ENOMEM;
+		goto out;
+	}
+
+	for (i = 0; i < names_nb; i++)
+		rte_strscpy((*xstats)[i].name, names[i],
+			    sizeof((*xstats)[i].name));
+
+	*xstats_num = names_nb;
+	ret = 0;
+
+out:
+	free(names);
+	free(str);
+	return ret;
+}
+
 unsigned int
 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
 		unsigned int *parsed_items, int check_unique_values)
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 04ae0feb58..6d604145bd 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -173,6 +173,70 @@  print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
 	printf("%s%s", name, buf);
 }
 
+static void
+nic_xstats_display_periodic(portid_t port_id)
+{
+	struct xstat_display_info *xstats_info;
+	uint64_t *prev_values, *curr_values;
+	uint64_t diff_value, value_rate;
+	uint64_t *ids, *ids_supp;
+	struct timespec cur_time;
+	unsigned int i, i_supp;
+	size_t ids_supp_sz;
+	uint64_t diff_ns;
+	int rc;
+
+	xstats_info = &xstats_per_port[port_id];
+
+	ids_supp_sz = xstats_info->ids_supp_sz;
+	if (xstats_display_num == 0 || ids_supp_sz == 0)
+		return;
+
+	printf("\n");
+
+	ids = xstats_info->ids;
+	ids_supp = xstats_info->ids_supp;
+	prev_values = xstats_info->prev_values;
+	curr_values = xstats_info->curr_values;
+
+	rc = rte_eth_xstats_get_by_id(port_id, ids_supp, curr_values,
+				      ids_supp_sz);
+	if (rc != (int)ids_supp_sz) {
+		fprintf(stderr, "%s: Failed to get values of %zu supported xstats for port %u - return code %d\n",
+			__func__, ids_supp_sz, port_id, rc);
+		return;
+	}
+
+	diff_ns = 0;
+	if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
+		uint64_t ns;
+
+		ns = cur_time.tv_sec * NS_PER_SEC;
+		ns += cur_time.tv_nsec;
+
+		if (xstats_info->prev_ns != 0)
+			diff_ns = ns - xstats_info->prev_ns;
+		xstats_info->prev_ns = ns;
+	}
+
+	printf("%-31s%-17s%s\n", " ", "Value", "Rate (since last show)");
+	for (i = i_supp = 0; i < xstats_display_num; i++) {
+		if (ids[i] == XSTAT_ID_INVALID)
+			continue;
+
+		diff_value = (curr_values[i_supp] > prev_values[i]) ?
+			     (curr_values[i_supp] - prev_values[i]) : 0;
+		prev_values[i] = curr_values[i_supp];
+		value_rate = diff_ns > 0 ?
+				(double)diff_value / diff_ns * NS_PER_SEC : 0;
+
+		printf("  %-25s%12"PRIu64" %15"PRIu64"\n",
+		       xstats_display[i].name, curr_values[i_supp], value_rate);
+
+		i_supp++;
+	}
+}
+
 void
 nic_stats_display(portid_t port_id)
 {
@@ -243,6 +307,8 @@  nic_stats_display(portid_t port_id)
 	       PRIu64"          Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
 	       mpps_tx, mbps_tx * 8);
 
+	nic_xstats_display_periodic(port_id);
+
 	printf("  %s############################%s\n",
 	       nic_stats_border, nic_stats_border);
 }
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 5e69d2aa8c..d4c032cb56 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -61,6 +61,9 @@  usage(char* progname)
 	       "(only if interactive is disabled).\n");
 	printf("  --stats-period=PERIOD: statistics will be shown "
 	       "every PERIOD seconds (only if interactive is disabled).\n");
+	printf("  --display-xstats xstat1[,...]: extended statistics to show. "
+	       "Used with --stats-period specified or interactive commands "
+	       "that show Rx/Tx statistics (i.e. 'show port stats').\n");
 	printf("  --nb-cores=N: set the number of forwarding cores "
 	       "(1 <= N <= %d).\n", nb_lcores);
 	printf("  --nb-ports=N: set the number of forwarding ports "
@@ -532,6 +535,7 @@  launch_args_parse(int argc, char** argv)
 #endif
 		{ "tx-first",			0, 0, 0 },
 		{ "stats-period",		1, 0, 0 },
+		{ "display-xstats",		1, 0, 0 },
 		{ "nb-cores",			1, 0, 0 },
 		{ "nb-ports",			1, 0, 0 },
 		{ "coremask",			1, 0, 0 },
@@ -689,6 +693,20 @@  launch_args_parse(int argc, char** argv)
 				stats_period = n;
 				break;
 			}
+			if (!strcmp(lgopts[opt_idx].name, "display-xstats")) {
+				char rc;
+
+				rc = parse_xstats_list(optarg, &xstats_display,
+						       &xstats_display_num);
+				if (rc != 0)
+					rte_exit(EXIT_FAILURE,
+						 "Failed to fill xstats to display: %d\n",
+						 rc);
+
+				if (alloc_display_xstats_info() != 0)
+					rte_exit(EXIT_FAILURE,
+						 "Failed to alloc xstats display memory\n");
+			}
 			if (!strcmp(lgopts[opt_idx].name,
 				    "eth-peers-configfile")) {
 				if (init_peer_eth_addrs(optarg) != 0)
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index a48f70962f..aebb1d6135 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -208,6 +208,14 @@  uint32_t param_total_num_mbufs = 0;  /**< number of mbufs in all pools - if
                                       * specified on command-line. */
 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
 
+/** Extended statistics to show. */
+struct rte_eth_xstat_name *xstats_display;
+
+unsigned int xstats_display_num; /**< Size of extended statistics to show */
+
+/** Helper structures for each port to show extended statistics. */
+struct xstat_display_info xstats_per_port[RTE_MAX_ETHPORTS];
+
 /*
  * In container, it cannot terminate the process which running with 'stats-period'
  * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
@@ -542,6 +550,12 @@  uint16_t gso_max_segment_size = RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN;
 /* Holds the registered mbuf dynamic flags names. */
 char dynf_names[64][RTE_MBUF_DYN_NAMESIZE];
 
+/** Fill helper structures for specified port to show extended statistics. */
+static void fill_display_xstats_info_for_port(portid_t pi);
+
+/** Fill helper structures for all ports to show extended statistics. */
+static void fill_display_xstats_info(void);
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -2673,6 +2687,8 @@  start_port(portid_t pid)
 		}
 	}
 
+	fill_display_xstats_info_for_port(pid);
+
 	printf("Done\n");
 	return 0;
 }
@@ -3693,6 +3709,110 @@  force_quit(void)
 	prompt_exit();
 }
 
+int
+alloc_display_xstats_info(void)
+{
+	portid_t port;
+	uint64_t *mem;
+	size_t mem_size;
+
+	if (xstats_display_num == 0)
+		return 0;
+
+	memset(xstats_per_port, 0, sizeof(xstats_per_port));
+
+	for (port = 0; port < RTE_MAX_ETHPORTS; port++) {
+		uint64_t **ids = &xstats_per_port[port].ids;
+		uint64_t **ids_supp = &xstats_per_port[port].ids_supp;
+		uint64_t **prev_values = &xstats_per_port[port].prev_values;
+		uint64_t **curr_values = &xstats_per_port[port].curr_values;
+
+		if (port == 0) {
+			mem_size = RTE_MAX_ETHPORTS * xstats_display_num *
+				   (sizeof(**ids) + sizeof(**ids_supp) +
+				    sizeof(**prev_values) +
+				    sizeof(**curr_values));
+
+			mem = malloc(mem_size);
+			if (mem == NULL)
+				return -ENOMEM;
+
+			memset(mem, 0, mem_size);
+		}
+
+		*ids = mem;
+		mem += xstats_display_num * sizeof(**ids);
+
+		*ids_supp = mem;
+		mem += xstats_display_num * sizeof(**ids_supp);
+
+		*prev_values = mem;
+		mem += xstats_display_num * sizeof(**prev_values);
+
+		*curr_values = mem;
+		mem += xstats_display_num * sizeof(**curr_values);
+	}
+
+	return 0;
+}
+
+static void
+fill_display_xstats_info_for_port(portid_t pi)
+{
+	unsigned int stat, stat_supp;
+	uint64_t *ids, *ids_supp;
+	const char *xstat_name;
+	struct rte_port *port;
+	int rc;
+
+	if (xstats_display_num == 0)
+		return;
+
+	if (pi == (portid_t)RTE_PORT_ALL) {
+		fill_display_xstats_info();
+		return;
+	}
+
+	port = &ports[pi];
+	if (port->port_status != RTE_PORT_STARTED)
+		return;
+
+	ids = xstats_per_port[pi].ids;
+	ids_supp = xstats_per_port[pi].ids_supp;
+
+	for (stat = stat_supp = 0; stat < xstats_display_num; stat++) {
+		xstat_name = xstats_display[stat].name;
+
+		rc = rte_eth_xstats_get_id_by_name(pi, xstat_name,
+						   ids + stat);
+		if (rc != 0) {
+			ids[stat] = XSTAT_ID_INVALID;
+			printf("No xstat '%s' on port %u - skip it\n",
+			       xstat_name, pi);
+			continue;
+		}
+		ids_supp[stat_supp++] = ids[stat];
+	}
+
+	xstats_per_port[pi].ids_supp_sz = stat_supp;
+}
+
+static void
+fill_display_xstats_info(void)
+{
+	portid_t pi;
+
+	if (xstats_display_num == 0)
+		return;
+
+	RTE_ETH_FOREACH_DEV(pi) {
+		if (pi == (portid_t)RTE_PORT_ALL)
+			continue;
+
+		fill_display_xstats_info_for_port(pi);
+	}
+}
+
 static void
 print_stats(void)
 {
@@ -3893,6 +4013,8 @@  main(int argc, char** argv)
 	}
 #endif
 
+	fill_display_xstats_info();
+
 #ifdef RTE_LIB_CMDLINE
 	if (strlen(cmdline_filename) != 0)
 		cmdline_read_from_file(cmdline_filename);
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index d61a055bdd..d66232dfa4 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -434,6 +434,24 @@  extern uint32_t param_total_num_mbufs;
 
 extern uint16_t stats_period;
 
+extern struct rte_eth_xstat_name *xstats_display;
+extern unsigned int xstats_display_num;
+
+#define XSTAT_ID_INVALID UINT64_MAX
+
+/** Information for an extended statistics to show. */
+struct xstat_display_info {
+	/** IDs of xstats in the order of xstats_display */
+	uint64_t *ids;
+	/** Supported xstats IDs in the order of xstats_display */
+	uint64_t *ids_supp;
+	size_t   ids_supp_sz;
+	uint64_t *prev_values;
+	uint64_t *curr_values;
+	uint64_t prev_ns;
+};
+extern struct xstat_display_info xstats_per_port[];
+
 extern uint16_t hairpin_mode;
 
 #ifdef RTE_LIB_LATENCYSTATS
@@ -766,6 +784,8 @@  inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 unsigned int parse_item_list(const char *str, const char *item_name,
 			unsigned int max_items,
 			unsigned int *parsed_items, int check_unique_values);
+int parse_xstats_list(char *in_str, struct rte_eth_xstat_name **xstats,
+		      unsigned int *xstats_num);
 void launch_args_parse(int argc, char** argv);
 void cmdline_read_from_file(const char *filename);
 void prompt(void);
@@ -978,6 +998,7 @@  enum print_warning {
 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
 void print_valid_ports(void);
 int new_socket_id(unsigned int socket_id);
+int alloc_display_xstats_info(void);
 
 queueid_t get_allowed_max_nb_rxq(portid_t *pid);
 int check_nb_rxq(queueid_t rxq);
diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst
index eb48318353..3e5ba81f18 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -56,6 +56,11 @@  The command line options are:
     Display statistics every PERIOD seconds, if interactive mode is disabled.
     The default value is 0, which means that the statistics will not be displayed.
 
+*   ``--display-xstats xstat1[,...]``
+
+    Display extended statistics every PERIOD seconds as specified in ``--stats-period``
+    or when used with interactive commands that show Rx/Tx statistics (i.e. 'show port stats').
+
 *   ``--nb-cores=N``
 
     Set the number of forwarding cores,