From patchwork Sun May 28 21:38:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "De Lara Guarch, Pablo" X-Patchwork-Id: 24856 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 87964532C; Sun, 28 May 2017 23:38:37 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 0330F152A for ; Sun, 28 May 2017 23:38:35 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP; 28 May 2017 14:38:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,411,1491289200"; d="scan'208";a="106472393" Received: from silpixa00381631.ir.intel.com (HELO silpixa00381631.ger.corp.intel.com) ([10.237.222.122]) by orsmga005.jf.intel.com with ESMTP; 28 May 2017 14:38:33 -0700 From: Pablo de Lara To: jingjing.wu@intel.com Cc: dev@dpdk.org, Pablo de Lara Date: Sun, 28 May 2017 22:38:54 +0100 Message-Id: <1496007534-182470-1-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] app/testpmd: print statistics periodically X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- app/test-pmd/parameters.c | 15 ++++++++++++- app/test-pmd/testpmd.c | 40 ++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 1 + doc/guides/testpmd_app_ug/run_app.rst | 5 +++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index fbe6284..a758b25 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -89,6 +89,7 @@ usage(char* progname) "[--cmdline-file=FILENAME] " #endif "[--help|-h] | [--auto-start|-a] | [" + "-T PERIOD: statistics will be shown every PERIOD seconds (only if interactive is disabled)" "--coremask=COREMASK --portmask=PORTMASK --numa " "--mbuf-size= | --total-num-mbufs= | " "--nb-cores= | --nb-ports= | " @@ -639,7 +640,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 +654,18 @@ 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]); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index d1041af..2ab783d 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -177,7 +177,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. */ @@ -2229,6 +2229,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) { @@ -2351,8 +2366,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; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index e6c43ba..8de3379 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -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; diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst index 2a43214..bebe46a 100644 --- a/doc/guides/testpmd_app_ug/run_app.rst +++ b/doc/guides/testpmd_app_ug/run_app.rst @@ -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,