app/testpmd: print statistics periodically
[dpdk.git] / app / test-pmd / testpmd.c
index a7bad73..132ce81 100644 (file)
@@ -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.
  */
@@ -2235,6 +2235,21 @@ force_quit(void)
        prompt_exit();
 }
 
+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)
 {
@@ -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();