| 387 | } |
| 388 | |
| 389 | void |
| 390 | nic_xstats_display(portid_t port_id) |
| 391 | { |
| 392 | struct rte_eth_xstat *xstats; |
| 393 | int cnt_xstats, idx_xstat; |
| 394 | struct rte_eth_xstat_name *xstats_names; |
| 395 | |
| 396 | if (port_id_is_invalid(port_id, ENABLED_WARN)) { |
| 397 | print_valid_ports(); |
| 398 | return; |
| 399 | } |
| 400 | printf("###### NIC extended statistics for port %-2d\n", port_id); |
| 401 | if (!rte_eth_dev_is_valid_port(port_id)) { |
| 402 | fprintf(stderr, "Error: Invalid port number %i\n", port_id); |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | /* Get count */ |
| 407 | cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0); |
| 408 | if (cnt_xstats < 0) { |
| 409 | fprintf(stderr, "Error: Cannot get count of xstats\n"); |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | /* Get id-name lookup table */ |
| 414 | xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats); |
| 415 | if (xstats_names == NULL) { |
| 416 | fprintf(stderr, "Cannot allocate memory for xstats lookup\n"); |
| 417 | return; |
| 418 | } |
| 419 | if (cnt_xstats != rte_eth_xstats_get_names( |
| 420 | port_id, xstats_names, cnt_xstats)) { |
| 421 | fprintf(stderr, "Error: Cannot get xstats lookup\n"); |
| 422 | free(xstats_names); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | /* Get stats themselves */ |
| 427 | xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats); |
| 428 | if (xstats == NULL) { |
| 429 | fprintf(stderr, "Cannot allocate memory for xstats\n"); |
| 430 | free(xstats_names); |
| 431 | return; |
| 432 | } |
| 433 | if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) { |
| 434 | fprintf(stderr, "Error: Unable to get xstats\n"); |
| 435 | free(xstats_names); |
| 436 | free(xstats); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | /* Display xstats */ |
| 441 | for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { |
| 442 | if (xstats_hide_zero && !xstats[idx_xstat].value) |
| 443 | continue; |
| 444 | printf("%s: %"PRIu64"\n", |
| 445 | xstats_names[idx_xstat].name, |
| 446 | xstats[idx_xstat].value); |
no test coverage detected