[dpdk-dev,v3] app/testpmd: print statistics periodically
Checks
Commit Message
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@intel.com>
---
Changes in v3:
- Added missing "|" character in help
Changes in v2:
- Added extra argument in help
app/test-pmd/parameters.c | 19 +++++++++++++++--
app/test-pmd/testpmd.c | 40 ++++++++++++++++++++++++++++++++++-
app/test-pmd/testpmd.h | 1 +
doc/guides/testpmd_app_ug/run_app.rst | 5 +++++
4 files changed, 62 insertions(+), 3 deletions(-)
Comments
> -----Original Message-----
> From: De Lara Guarch, Pablo
> Sent: Thursday, June 15, 2017 9:48 AM
> To: Wu, Jingjing <jingjing.wu@intel.com>
> Cc: dev@dpdk.org; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Subject: [PATCH v3] app/testpmd: print statistics periodically
>
> 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@intel.com>
> ---
>
> Changes in v3:
>
> - Added missing "|" character in help
Acked-by: Jingjing Wu <jingjing.wu@intel.com>
15/06/2017 03:48, Pablo de Lara:
> +print_stats(void)
> +{
> + uint8_t i;
> + const char clr[] = { 27, '[', '2', 'J', '\0' };
> + const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' };
Spotted a CamelCase ;)
Is there a punishment planned in the contributor's guide?
> + if (stats_period != 0) {
> + uint64_t prev_tsc = 0, cur_tsc, timer_tsc = 0;
> + uint64_t timer_period;
> +
> + /* Convert to number of cycles */
> + timer_period = stats_period * rte_get_timer_hz();
> +
> + while (1) {
> + cur_tsc = rte_rdtsc();
> + timer_tsc += cur_tsc - prev_tsc;
Please forget (Intel) TSC wording and prefer the more generic
rte_get_timer_cycles() function.
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Monday, June 19, 2017 10:22 PM
> To: De Lara Guarch, Pablo
> Cc: dev@dpdk.org; Wu, Jingjing
> Subject: Re: [dpdk-dev] [PATCH v3] app/testpmd: print statistics
> periodically
>
> 15/06/2017 03:48, Pablo de Lara:
> > +print_stats(void)
> > +{
> > + uint8_t i;
> > + const char clr[] = { 27, '[', '2', 'J', '\0' };
> > + const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' };
>
> Spotted a CamelCase ;)
> Is there a punishment planned in the contributor's guide?
Sorry, got this from another app, will fix this.
>
> > + if (stats_period != 0) {
> > + uint64_t prev_tsc = 0, cur_tsc, timer_tsc = 0;
> > + uint64_t timer_period;
> > +
> > + /* Convert to number of cycles */
> > + timer_period = stats_period * rte_get_timer_hz();
> > +
> > + while (1) {
> > + cur_tsc = rte_rdtsc();
> > + timer_tsc += cur_tsc - prev_tsc;
>
> Please forget (Intel) TSC wording and prefer the more generic
> rte_get_timer_cycles() function.
Good point, will fix in the v4.
Thanks,
Pablo
20/06/2017 10:34, De Lara Guarch, Pablo:
> > > + if (stats_period != 0) {
> > > + uint64_t prev_tsc = 0, cur_tsc, timer_tsc = 0;
> > > + uint64_t timer_period;
> > > +
> > > + /* Convert to number of cycles */
> > > + timer_period = stats_period * rte_get_timer_hz();
> > > +
> > > + while (1) {
> > > + cur_tsc = rte_rdtsc();
> > > + timer_tsc += cur_tsc - prev_tsc;
> >
> > Please forget (Intel) TSC wording and prefer the more generic
> > rte_get_timer_cycles() function.
>
> Good point, will fix in the v4.
Waiting for v4.
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> Sent: Thursday, July 6, 2017 12:52 AM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Cc: dev@dpdk.org; Wu, Jingjing <jingjing.wu@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v3] app/testpmd: print statistics
> periodically
>
> 20/06/2017 10:34, De Lara Guarch, Pablo:
> > > > + if (stats_period != 0) {
> > > > + uint64_t prev_tsc = 0, cur_tsc, timer_tsc = 0;
> > > > + uint64_t timer_period;
> > > > +
> > > > + /* Convert to number of cycles */
> > > > + timer_period = stats_period * rte_get_timer_hz();
> > > > +
> > > > + while (1) {
> > > > + cur_tsc = rte_rdtsc();
> > > > + timer_tsc += cur_tsc - prev_tsc;
> > >
> > > Please forget (Intel) TSC wording and prefer the more generic
> > > rte_get_timer_cycles() function.
> >
> > Good point, will fix in the v4.
>
> Waiting for v4.
Just sent it, sorry for the delay.
Pablo
@@ -88,7 +88,7 @@ usage(char* progname)
"[--interactive|-i] "
"[--cmdline-file=FILENAME] "
#endif
- "[--help|-h] | [--auto-start|-a] | ["
+ "[--help|-h] | [--auto-start|-a] | [-T PERIOD] | ["
"--coremask=COREMASK --portmask=PORTMASK --numa "
"--mbuf-size= | --total-num-mbufs= | "
"--nb-cores= | --nb-ports= | "
@@ -109,6 +109,8 @@ usage(char* progname)
printf(" --auto-start: start forwarding on init "
"[always when non-interactive].\n");
printf(" --help: display this message and quit.\n");
+ printf(" -T 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 "
@@ -639,7 +641,7 @@ launch_args_parse(int argc, char** argv)
#else
#define SHORTOPTS ""
#endif
- while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah",
+ while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ahT:",
lgopts, &opt_idx)) != EOF) {
switch (opt) {
#ifdef RTE_LIBRTE_CMDLINE
@@ -653,6 +655,19 @@ launch_args_parse(int argc, char** argv)
auto_start = 1;
break;
+ case 'T':
+ {
+ char *end = NULL;
+ unsigned int n;
+
+ n = strtoul(optarg, &end, 10);
+ if ((optarg[0] == '\0') || (end == NULL) ||
+ (*end != '\0'))
+ break;
+
+ stats_period = n;
+ break;
+ }
case 0: /*long options */
if (!strcmp(lgopts[opt_idx].name, "help")) {
usage(argv[0]);
@@ -180,7 +180,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.
*/
@@ -2232,6 +2232,21 @@ force_quit(void)
}
static void
+print_stats(void)
+{
+ uint8_t i;
+ const char clr[] = { 27, '[', '2', 'J', '\0' };
+ const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' };
+
+ /* Clear screen and move to top left */
+ printf("%s%s", clr, topLeft);
+
+ 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) {
@@ -2354,8 +2369,31 @@ main(int argc, char** argv)
printf("No commandline core given, start packet forwarding\n");
start_packet_forwarding(0);
+ if (stats_period != 0) {
+ uint64_t prev_tsc = 0, cur_tsc, timer_tsc = 0;
+ uint64_t timer_period;
+
+ /* Convert to number of cycles */
+ timer_period = stats_period * rte_get_timer_hz();
+
+ while (1) {
+ cur_tsc = rte_rdtsc();
+ timer_tsc += cur_tsc - prev_tsc;
+
+ if (timer_tsc >= timer_period) {
+ print_stats();
+ /* Reset the timer */
+ timer_tsc = 0;
+ }
+ /* Sleep to avoid unnecessary checks */
+ sleep(1);
+ prev_tsc = cur_tsc;
+ }
+ }
+
printf("Press enter to exit\n");
rc = read(0, &c, 1);
+
pmd_test_exit();
if (rc < 0)
return 1;
@@ -378,6 +378,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;
@@ -188,6 +188,11 @@ The commandline options are:
Start forwarding on initialization.
+* ``-T 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,