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 65A076945 for ; Mon, 30 May 2016 12:48:23 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP; 30 May 2016 03:48:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,389,1459839600"; d="scan'208";a="817650947" Received: from rhorton-mobl.ger.corp.intel.com (HELO VM.ir.intel.com) ([163.33.228.212]) by orsmga003.jf.intel.com with ESMTP; 30 May 2016 03:48:22 -0700 From: Remy Horton To: dev@dpdk.org, Pablo de Lara Date: Mon, 30 May 2016 11:48:09 +0100 Message-Id: <1464605292-4599-8-git-send-email-remy.horton@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464605292-4599-1-git-send-email-remy.horton@intel.com> References: <1464605292-4599-1-git-send-email-remy.horton@intel.com> Subject: [dpdk-dev] [PATCH v3 07/10] app/test-pmd: change xstats to use integer ids X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2016 10:48:23 -0000 The current extended ethernet statistics fetching involve doing several string operations, which causes performance issues if there are lots of statistics and/or network interfaces. This patch changes the test-pmd application to use the new API that seperates name string and value queries. Signed-off-by: Remy Horton --- app/test-pmd/config.c | 52 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 1c552e4..3ba5679 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -233,28 +233,56 @@ void nic_xstats_display(portid_t port_id) { struct rte_eth_xstats *xstats; - int len, ret, i; + int cnt_xstats, idx_xstat, idx_name; + struct rte_eth_xstats_name *ptr_names; printf("###### NIC extended statistics for port %-2d\n", port_id); + if (!rte_eth_dev_is_valid_port(port_id)) { + printf("Error: Invalid port number %i\n", port_id); + return; + } + + /* Get count */ + cnt_xstats = rte_eth_xstats_count(port_id); + if (cnt_xstats < 0) { + printf("Error: Cannot get count of xstats\n"); + return; + } - len = rte_eth_xstats_get(port_id, NULL, 0); - if (len < 0) { - printf("Cannot get xstats count\n"); + /* Get id-name lookup table */ + ptr_names = malloc(sizeof(struct rte_eth_xstats_name) * cnt_xstats); + if (ptr_names == NULL) { + printf("Cannot allocate memory for xstats lookup\n"); return; } - xstats = malloc(sizeof(xstats[0]) * len); + if (cnt_xstats != rte_eth_xstats_names( + port_id, ptr_names, cnt_xstats)) { + printf("Error: Cannot get xstats lookup\n"); + return; + } + + /* Get stats themselves */ + xstats = malloc(sizeof(struct rte_eth_xstats) * cnt_xstats); if (xstats == NULL) { printf("Cannot allocate memory for xstats\n"); + free(ptr_names); return; } - ret = rte_eth_xstats_get(port_id, xstats, len); - if (ret < 0 || ret > len) { - printf("Cannot get xstats\n"); - free(xstats); + if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) { + printf("Error: Unable to get xstats\n"); return; } - for (i = 0; i < len; i++) - printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value); + + /* Display xstats */ + for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) + for (idx_name = 0; idx_name < cnt_xstats; idx_name++) + if (ptr_names[idx_name].id == xstats[idx_xstat].id) { + printf("%s: %"PRIu64"\n", + ptr_names[idx_name].name, + xstats[idx_xstat].value); + break; + } + free(ptr_names); free(xstats); } -- 2.5.5