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 <remy.horton at intel.com> --- 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