From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 2D97A4CE4 for ; Fri, 15 Apr 2016 16:44:27 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 15 Apr 2016 07:44:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,487,1455004800"; d="scan'208";a="686820478" Received: from rhorton-mobl.ger.corp.intel.com (HELO VM.ir.intel.com) ([163.33.228.84]) by FMSMGA003.fm.intel.com with ESMTP; 15 Apr 2016 07:44:25 -0700 From: Remy Horton To: dev@dpdk.org Date: Fri, 15 Apr 2016 15:44:22 +0100 Message-Id: <1460731462-21229-4-git-send-email-remy.horton@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460731462-21229-1-git-send-email-remy.horton@intel.com> References: <1460731462-21229-1-git-send-email-remy.horton@intel.com> Subject: [dpdk-dev] [RFC PATCH v1 3/3] examples/ethtool: add xstats display command 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: Fri, 15 Apr 2016 14:44:27 -0000 Signed-off-by: Remy Horton --- examples/ethtool/ethtool-app/ethapp.c | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/examples/ethtool/ethtool-app/ethapp.c b/examples/ethtool/ethtool-app/ethapp.c index 2ed4796..16ae4e9 100644 --- a/examples/ethtool/ethtool-app/ethapp.c +++ b/examples/ethtool/ethtool-app/ethapp.c @@ -98,6 +98,8 @@ cmdline_parse_token_string_t pcmd_rxmode_token_cmd = TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "rxmode"); cmdline_parse_token_string_t pcmd_portstats_token_cmd = TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "portstats"); +cmdline_parse_token_string_t pcmd_xstats_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "xstats"); cmdline_parse_token_num_t pcmd_int_token_port = TOKEN_NUM_INITIALIZER(struct pcmd_int_params, port, UINT16); @@ -552,6 +554,49 @@ static void pcmd_portstats_callback(__rte_unused void *ptr_params, printf("Port %i: Error fetching statistics\n", params->port); } +static void pcmd_xstats_callback(__rte_unused void *ptr_params, + __rte_unused struct cmdline *ctx, + __rte_unused void *ptr_data) +{ + struct rte_eth_xstats xstats[256]; + struct pcmd_int_params *params = ptr_params; + int cnt_xstats, idx_xstat; + struct rte_eth_xstats_name *ptr_names; + + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + + cnt_xstats = rte_eth_xstats_names(params->port, NULL, 0); + if (cnt_xstats < 0) { + printf("Port %i: %s\n", params->port, strerror(-cnt_xstats)); + return; + } + printf("Number of xstats: %i\n", cnt_xstats); + ptr_names = malloc(sizeof(struct rte_eth_xstats_name) * cnt_xstats); + if (cnt_xstats != rte_eth_xstats_names( + params->port, ptr_names, cnt_xstats)) { + printf("Error: Fetched and expected counts mismatch\n"); + return; + } + + cnt_xstats = rte_eth_xstats_get(params->port, xstats, 256); + if (cnt_xstats < 0) { + printf("Error: Unable to get xstats (%s)\n", + strerror(-cnt_xstats)); + return; + } + for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { + /* Assume ptr_names[x].id = x */ + printf("%s: %lu\n", ptr_names[xstats[idx_xstat].key].name, + xstats[idx_xstat].value); + } + free(ptr_names); +} + + static void pcmd_ringparam_callback(__rte_unused void *ptr_params, __rte_unused struct cmdline *ctx, void *ptr_data) @@ -790,6 +835,17 @@ cmdline_parse_inst_t pcmd_portstats = { NULL }, }; +cmdline_parse_inst_t pcmd_xstats = { + .f = pcmd_xstats_callback, + .data = NULL, + .help_str = "xstats \n" + " Print port eth xstats", + .tokens = { + (void *)&pcmd_xstats_token_cmd, + (void *)&pcmd_int_token_port, + NULL + }, +}; cmdline_parse_inst_t pcmd_ringparam = { .f = pcmd_ringparam_callback, .data = NULL, @@ -858,6 +914,7 @@ cmdline_parse_ctx_t list_prompt_commands[] = { (cmdline_parse_inst_t *)&pcmd_stop, (cmdline_parse_inst_t *)&pcmd_validate, (cmdline_parse_inst_t *)&pcmd_vlan, + (cmdline_parse_inst_t *)&pcmd_xstats, (cmdline_parse_inst_t *)&pcmd_quit, NULL }; -- 2.5.5