[dpdk-dev] [PATCH v5] app/testpmd: print statistics periodically

Pablo de Lara pablo.de.lara.guarch at intel.com
Thu Jul 6 05:05:16 CEST 2017


Add parameter to print port statistics periodically
(disabled by default), if interactive mode is not enabled.

This is useful to allow the user to see port statistics
without having to get into the internal command line.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch at intel.com>
Acked-by: Jingjing Wu <jingjing.wu at intel.com>
Tested-by: Jerin Jacob <jerin.jacob at caviumnetworks.com>

---

Changes in v5:

- Rebased against dpdk master
- Modified parameter name from "T" to more explicit "stats-period"

Changes in v4:

- Removed CamelCase
- Used generic rte_get_timer_cycles() function, instead 
  of TSC API.

Changes in v3:

- Added missing "|" character in help

Changes in v2:

- Added extra argument in help 

 app/test-pmd/parameters.c             | 17 ++++++++++++++-
 app/test-pmd/testpmd.c                | 39 ++++++++++++++++++++++++++++++++++-
 app/test-pmd/testpmd.h                |  1 +
 doc/guides/testpmd_app_ug/run_app.rst |  5 +++++
 4 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 0a88844..958b3d0 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -89,7 +89,7 @@ usage(char* progname)
 	       "[--cmdline-file=FILENAME] "
 #endif
 	       "[--help|-h] | [--auto-start|-a] | ["
-	       "--tx-first | "
+	       "--tx-first | --stats-period=PERIOD | "
 	       "--coremask=COREMASK --portmask=PORTMASK --numa "
 	       "--mbuf-size= | --total-num-mbufs= | "
 	       "--nb-cores= | --nb-ports= | "
@@ -112,6 +112,8 @@ usage(char* progname)
 	printf("  --help: display this message and quit.\n");
 	printf("  --tx-first: start forwarding sending a burst first "
 	       "(only if interactive is disabled).\n");
+	printf("  --stats-period=PERIOD: statistics will be shown "
+	       "every PERIOD seconds (only if interactive is disabled).\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 "
@@ -570,6 +572,7 @@ launch_args_parse(int argc, char** argv)
 		{ "eth-peer",			1, 0, 0 },
 #endif
 		{ "tx-first",			0, 0, 0 },
+		{ "stats-period",		1, 0, 0 },
 		{ "ports",			1, 0, 0 },
 		{ "nb-cores",			1, 0, 0 },
 		{ "nb-ports",			1, 0, 0 },
@@ -683,6 +686,18 @@ launch_args_parse(int argc, char** argv)
 						"packets first\n");
 				tx_first = 1;
 			}
+			if (!strcmp(lgopts[opt_idx].name, "stats-period")) {
+				char *end = NULL;
+				unsigned int n;
+
+				n = strtoul(optarg, &end, 10);
+				if ((optarg[0] == '\0') || (end == NULL) ||
+						(*end != '\0'))
+					break;
+
+				stats_period = n;
+				break;
+			}
 			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 a7bad73..132ce81 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -181,7 +181,7 @@ uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
 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) */
 /*
  * Configuration of packet segments used by the "txonly" processing engine.
  */
@@ -2236,6 +2236,21 @@ force_quit(void)
 }
 
 static void
+print_stats(void)
+{
+	uint8_t i;
+	const char clr[] = { 27, '[', '2', 'J', '\0' };
+	const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
+
+	/* Clear screen and move to top left */
+	printf("%s%s", clr, top_left);
+
+	printf("\nPort statistics ====================================");
+	for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
+		nic_stats_display(fwd_ports_ids[i]);
+}
+
+static void
 signal_handler(int signum)
 {
 	if (signum == SIGINT || signum == SIGTERM) {
@@ -2361,6 +2376,28 @@ main(int argc, char** argv)
 
 		printf("No commandline core given, start packet forwarding\n");
 		start_packet_forwarding(tx_first);
+		if (stats_period != 0) {
+			uint64_t prev_time = 0, cur_time, diff_time = 0;
+			uint64_t timer_period;
+
+			/* Convert to number of cycles */
+			timer_period = stats_period * rte_get_timer_hz();
+
+			while (1) {
+				cur_time = rte_get_timer_cycles();
+				diff_time += cur_time - prev_time;
+
+				if (diff_time >= timer_period) {
+					print_stats();
+					/* Reset the timer */
+					diff_time = 0;
+				}
+				/* Sleep to avoid unnecessary checks */
+				prev_time = cur_time;
+				sleep(1);
+			}
+		}
+
 		printf("Press enter to exit\n");
 		rc = read(0, &c, 1);
 		pmd_test_exit();
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 5cabeef..c73196f 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -379,6 +379,7 @@ extern enum dcb_queue_mapping_mode dcb_q_mapping;
 extern uint16_t mbuf_data_size; /**< Mbuf data space size. */
 extern uint32_t param_total_num_mbufs;
 
+extern uint16_t stats_period;
 
 #ifdef RTE_LIBRTE_LATENCY_STATS
 extern uint8_t latencystats_enabled;
diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst
index 3159398..e50c47f 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -196,6 +196,11 @@ The commandline options are:
 
    This flag should be only used in non-interactive mode.
 
+*   ``--stats-period PERIOD``
+
+    Display statistics every PERIOD seconds, if interactive mode is disabled.
+    The default value is 0, which means that the statistics will not be displayed.
+
 *   ``--nb-cores=N``
 
     Set the number of forwarding cores,
-- 
2.9.4



More information about the dev mailing list