app/testpmd: new command to get extended statistics

Add a new token in "show port" command to dump the extended statistics
of a device. It validates the new xstats framework added in previous commit.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
This commit is contained in:
Olivier Matz 2014-07-23 14:28:54 +02:00 committed by Thomas Monjalon
parent ce757f5c9a
commit bfd5051b43
3 changed files with 52 additions and 6 deletions

View File

@ -183,14 +183,14 @@ static void cmd_help_long_parsed(void *parsed_result,
"Display:\n" "Display:\n"
"--------\n\n" "--------\n\n"
"show port (info|stats|fdir|stat_qmap) (port_id|all)\n" "show port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
" Display information for port_id, or all.\n\n" " Display information for port_id, or all.\n\n"
"show port rss-hash [key]\n" "show port rss-hash [key]\n"
" Display the RSS hash functions and RSS hash key" " Display the RSS hash functions and RSS hash key"
" of port X\n\n" " of port X\n\n"
"clear port (info|stats|fdir|stat_qmap) (port_id|all)\n" "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
" Clear information for port_id, or all.\n\n" " Clear information for port_id, or all.\n\n"
"show config (rxtx|cores|fwd)\n" "show config (rxtx|cores|fwd)\n"
@ -5114,12 +5114,18 @@ static void cmd_showportall_parsed(void *parsed_result,
if (!strcmp(res->what, "stats")) if (!strcmp(res->what, "stats"))
for (i = 0; i < nb_ports; i++) for (i = 0; i < nb_ports; i++)
nic_stats_clear(i); nic_stats_clear(i);
else if (!strcmp(res->what, "xstats"))
for (i = 0; i < nb_ports; i++)
nic_xstats_clear(i);
} else if (!strcmp(res->what, "info")) } else if (!strcmp(res->what, "info"))
for (i = 0; i < nb_ports; i++) for (i = 0; i < nb_ports; i++)
port_infos_display(i); port_infos_display(i);
else if (!strcmp(res->what, "stats")) else if (!strcmp(res->what, "stats"))
for (i = 0; i < nb_ports; i++) for (i = 0; i < nb_ports; i++)
nic_stats_display(i); nic_stats_display(i);
else if (!strcmp(res->what, "xstats"))
for (i = 0; i < nb_ports; i++)
nic_xstats_display(i);
else if (!strcmp(res->what, "fdir")) else if (!strcmp(res->what, "fdir"))
for (i = 0; i < nb_ports; i++) for (i = 0; i < nb_ports; i++)
fdir_get_infos(i); fdir_get_infos(i);
@ -5135,13 +5141,13 @@ cmdline_parse_token_string_t cmd_showportall_port =
TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
cmdline_parse_token_string_t cmd_showportall_what = cmdline_parse_token_string_t cmd_showportall_what =
TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
"info#stats#fdir#stat_qmap"); "info#stats#xstats#fdir#stat_qmap");
cmdline_parse_token_string_t cmd_showportall_all = cmdline_parse_token_string_t cmd_showportall_all =
TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
cmdline_parse_inst_t cmd_showportall = { cmdline_parse_inst_t cmd_showportall = {
.f = cmd_showportall_parsed, .f = cmd_showportall_parsed,
.data = NULL, .data = NULL,
.help_str = "show|clear port info|stats|fdir|stat_qmap all", .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap all",
.tokens = { .tokens = {
(void *)&cmd_showportall_show, (void *)&cmd_showportall_show,
(void *)&cmd_showportall_port, (void *)&cmd_showportall_port,
@ -5167,10 +5173,14 @@ static void cmd_showport_parsed(void *parsed_result,
if (!strcmp(res->show, "clear")) { if (!strcmp(res->show, "clear")) {
if (!strcmp(res->what, "stats")) if (!strcmp(res->what, "stats"))
nic_stats_clear(res->portnum); nic_stats_clear(res->portnum);
else if (!strcmp(res->what, "xstats"))
nic_xstats_clear(res->portnum);
} else if (!strcmp(res->what, "info")) } else if (!strcmp(res->what, "info"))
port_infos_display(res->portnum); port_infos_display(res->portnum);
else if (!strcmp(res->what, "stats")) else if (!strcmp(res->what, "stats"))
nic_stats_display(res->portnum); nic_stats_display(res->portnum);
else if (!strcmp(res->what, "xstats"))
nic_xstats_display(res->portnum);
else if (!strcmp(res->what, "fdir")) else if (!strcmp(res->what, "fdir"))
fdir_get_infos(res->portnum); fdir_get_infos(res->portnum);
else if (!strcmp(res->what, "stat_qmap")) else if (!strcmp(res->what, "stat_qmap"))
@ -5184,14 +5194,14 @@ cmdline_parse_token_string_t cmd_showport_port =
TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
cmdline_parse_token_string_t cmd_showport_what = cmdline_parse_token_string_t cmd_showport_what =
TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
"info#stats#fdir#stat_qmap"); "info#stats#xstats#fdir#stat_qmap");
cmdline_parse_token_num_t cmd_showport_portnum = cmdline_parse_token_num_t cmd_showport_portnum =
TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32); TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
cmdline_parse_inst_t cmd_showport = { cmdline_parse_inst_t cmd_showport = {
.f = cmd_showport_parsed, .f = cmd_showport_parsed,
.data = NULL, .data = NULL,
.help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)", .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap X (X = port number)",
.tokens = { .tokens = {
(void *)&cmd_showport_show, (void *)&cmd_showport_show,
(void *)&cmd_showport_port, (void *)&cmd_showport_port,

View File

@ -199,6 +199,40 @@ nic_stats_clear(portid_t port_id)
printf("\n NIC statistics for port %d cleared\n", port_id); printf("\n NIC statistics for port %d cleared\n", port_id);
} }
void
nic_xstats_display(portid_t port_id)
{
struct rte_eth_xstats *xstats;
int len, ret, i;
printf("###### NIC extended statistics for port %-2d\n", port_id);
len = rte_eth_xstats_get(port_id, NULL, 0);
if (len < 0) {
printf("Cannot get xstats count\n");
return;
}
xstats = malloc(sizeof(xstats[0]) * len);
if (xstats == NULL) {
printf("Cannot allocate memory for xstats\n");
return;
}
ret = rte_eth_xstats_get(port_id, xstats, len);
if (ret < 0 || ret > len) {
printf("Cannot get xstats\n");
free(xstats);
return;
}
for (i = 0; i < len; i++)
printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
free(xstats);
}
void
nic_xstats_clear(portid_t port_id)
{
rte_eth_xstats_reset(port_id);
}
void void
nic_stats_mapping_display(portid_t port_id) nic_stats_mapping_display(portid_t port_id)

View File

@ -448,6 +448,8 @@ void launch_args_parse(int argc, char** argv);
void prompt(void); void prompt(void);
void nic_stats_display(portid_t port_id); void nic_stats_display(portid_t port_id);
void nic_stats_clear(portid_t port_id); void nic_stats_clear(portid_t port_id);
void nic_xstats_display(portid_t port_id);
void nic_xstats_clear(portid_t port_id);
void nic_stats_mapping_display(portid_t port_id); void nic_stats_mapping_display(portid_t port_id);
void port_infos_display(portid_t port_id); void port_infos_display(portid_t port_id);
void fwd_lcores_config_display(void); void fwd_lcores_config_display(void);