From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id AF54CF614 for ; Fri, 3 Mar 2017 12:24:57 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2017 03:24:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,236,1484035200"; d="scan'208";a="1117977582" Received: from gklab-246-019.igk.intel.com (HELO intel.com) ([10.217.246.19]) by fmsmga001.fm.intel.com with SMTP; 03 Mar 2017 03:24:54 -0800 Received: by intel.com (sSMTP sendmail emulation); Fri, 03 Mar 2017 14:18:49 +0100 From: Kuba Kozak To: dev@dpdk.org Cc: Jacek Piasecki , Kuba Kozak Date: Fri, 3 Mar 2017 13:54:32 +0100 Message-Id: <1488545672-5208-5-git-send-email-kubax.kozak@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1488545672-5208-1-git-send-email-kubax.kozak@intel.com> References: <1488545672-5208-1-git-send-email-kubax.kozak@intel.com> Subject: [dpdk-dev] [PATCH 4/4] app/proc_info: add support for xstats-name and xstats-group 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: , X-List-Received-Date: Fri, 03 Mar 2017 11:24:58 -0000 From: Jacek Piasecki This patch provides support for proc_info application to allow printing single xstat value specified by its name and printing xstats values specified by its group name. New proc_info arguments: --xstats-name NAME: to display single xstat value by NAME --xstats-group GROUPNAME: to display group of xstats by GROUPNAME Signed-off-by: Jacek Piasecki Signed-off-by: Kuba Kozak --- app/proc_info/main.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/app/proc_info/main.c b/app/proc_info/main.c index 2c56d10..8826090 100644 --- a/app/proc_info/main.c +++ b/app/proc_info/main.c @@ -74,6 +74,11 @@ static uint32_t reset_xstats; /**< Enable memory info. */ static uint32_t mem_info; +/**< Enable displaying xstat name. */ +static uint32_t enable_xstats_name; +static char *xstats_name; +/**< Enable displaying xstat group name. */ +static uint64_t enable_xstats_group; /**< display usage */ static void @@ -85,6 +90,8 @@ " --stats: to display port statistics, enabled by default\n" " --xstats: to display extended port statistics, disabled by " "default\n" + " --xstats-name NAME: to display single xstat value by NAME\n" + " --xstats-group GROUPNAME: to display group of xstats by GROUPNAME\n" " --stats-reset: to reset port statistics\n" " --xstats-reset: to reset port extended statistics\n", prgname); @@ -128,6 +135,8 @@ {"stats-reset", 0, NULL, 0}, {"xstats", 0, NULL, 0}, {"xstats-reset", 0, NULL, 0}, + {"xstats-name", required_argument, NULL, 1}, + {"xstats-group", required_argument, NULL, 1}, {NULL, 0, 0, 0} }; @@ -168,7 +177,27 @@ MAX_LONG_OPT_SZ)) reset_xstats = 1; break; - + case 1: + /* Print xstat single value given by name*/ + if (!strncmp(long_option[option_index].name, + "xstats-name", + MAX_LONG_OPT_SZ)) { + enable_xstats_name = 1; + xstats_name = optarg; + printf("name:%s:%s\n", + long_option[option_index].name, + optarg); + } + /* Print xstat group values given by group name*/ + else if (!strncmp(long_option[option_index].name, + "xstats-group", + MAX_LONG_OPT_SZ)) { + enable_xstats_group = atoi(optarg); + printf("name:%s:%s\n", + long_option[option_index].name, + optarg); + } + break; default: proc_info_usage(prgname); return -1; @@ -241,6 +270,82 @@ } static void +nic_xstats_by_name_display(__rte_unused uint8_t port_id, + __rte_unused char *name) +{ + struct rte_eth_xstat xstat; + + printf("###### NIC statistics for port %-2d, statistic name '%s':\n", + port_id, name); + + if (rte_eth_xstats_get_by_name(port_id, &xstat, name) == 0) + printf("%s: %"PRIu64"\n", name, xstat.value); + else + printf("Statistic not found...\n"); + +} + +static void +nic_xstats_by_group_display(__rte_unused uint8_t port_id, + __rte_unused uint64_t group_mask) +{ + struct rte_eth_xstat *xstats; + int cnt_xstats, idx_xstat; + struct rte_eth_xstat_name *xstats_names; + + printf("###### NIC extended statistics for port %-2d," + " group %-2lu #########\n", + port_id, group_mask); + + /* Get count */ + cnt_xstats = rte_eth_xstats_get_names_by_group(port_id, NULL, 0, + group_mask); + if (cnt_xstats < 0) { + printf("Error: Cannot get count of xstats\n"); + return; + } + + /* Get id-name lookup table */ + xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats); + if (xstats_names == NULL) { + printf("Cannot allocate memory for xstats lookup\n"); + return; + } + + if (cnt_xstats != rte_eth_xstats_get_names_by_group( + port_id, xstats_names, cnt_xstats, group_mask)) { + printf("Error: Cannot get xstats lookup\n"); + free(xstats_names); + return; + } + + /* Get stats themselves */ + xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats); + if (xstats == NULL) { + printf("Cannot allocate memory for xstats\n"); + free(xstats_names); + return; + } + + if (cnt_xstats != rte_eth_xstats_get_by_group(port_id, xstats, + cnt_xstats, group_mask)) { + printf("Error: Unable to get xstats\n"); + free(xstats_names); + free(xstats); + return; + } + + /* Display xstats */ + for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) + printf("%s: %"PRIu64"\n", + xstats_names[idx_xstat].name, + xstats[idx_xstat].value); + free(xstats_names); + free(xstats); + +} + +static void nic_xstats_display(uint8_t port_id) { struct rte_eth_xstat_name *xstats_names; @@ -360,6 +465,11 @@ nic_stats_clear(i); else if (reset_xstats) nic_xstats_clear(i); + else if (enable_xstats_group) + nic_xstats_by_group_display(i, + enable_xstats_group); + else if (enable_xstats_name) + nic_xstats_by_name_display(i, xstats_name); } } -- 1.9.1