New upstream version 17.11-rc3
[deb_dpdk.git] / app / proc_info / main.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdint.h>
37 #include <errno.h>
38 #include <stdarg.h>
39 #include <inttypes.h>
40 #include <sys/queue.h>
41 #include <stdlib.h>
42 #include <getopt.h>
43 #include <unistd.h>
44
45 #include <rte_eal.h>
46 #include <rte_common.h>
47 #include <rte_debug.h>
48 #include <rte_ethdev.h>
49 #include <rte_malloc.h>
50 #include <rte_memory.h>
51 #include <rte_memzone.h>
52 #include <rte_launch.h>
53 #include <rte_tailq.h>
54 #include <rte_per_lcore.h>
55 #include <rte_lcore.h>
56 #include <rte_log.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
59 #include <rte_string_fns.h>
60 #include <rte_metrics.h>
61
62 /* Maximum long option length for option parsing. */
63 #define MAX_LONG_OPT_SZ 64
64 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
65
66 #define MAX_STRING_LEN 256
67
68 /**< mask of enabled ports */
69 static uint32_t enabled_port_mask;
70 /**< Enable stats. */
71 static uint32_t enable_stats;
72 /**< Enable xstats. */
73 static uint32_t enable_xstats;
74 /**< Enable collectd format*/
75 static uint32_t enable_collectd_format;
76 /**< FD to send collectd format messages to STDOUT*/
77 static int stdout_fd;
78 /**< Host id process is running on */
79 static char host_id[MAX_LONG_OPT_SZ];
80 /**< Enable metrics. */
81 static uint32_t enable_metrics;
82 /**< Enable stats reset. */
83 static uint32_t reset_stats;
84 /**< Enable xstats reset. */
85 static uint32_t reset_xstats;
86 /**< Enable memory info. */
87 static uint32_t mem_info;
88 /**< Enable displaying xstat name. */
89 static uint32_t enable_xstats_name;
90 static char *xstats_name;
91
92 /**< Enable xstats by ids. */
93 #define MAX_NB_XSTATS_IDS 1024
94 static uint32_t nb_xstats_ids;
95 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS];
96
97 /**< display usage */
98 static void
99 proc_info_usage(const char *prgname)
100 {
101         printf("%s [EAL options] -- -p PORTMASK\n"
102                 "  -m to display DPDK memory zones, segments and TAILQ information\n"
103                 "  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
104                 "  --stats: to display port statistics, enabled by default\n"
105                 "  --xstats: to display extended port statistics, disabled by "
106                         "default\n"
107                 "  --metrics: to display derived metrics of the ports, disabled by "
108                         "default\n"
109                 "  --xstats-name NAME: to display single xstat id by NAME\n"
110                 "  --xstats-ids IDLIST: to display xstat values by id. "
111                         "The argument is comma-separated list of xstat ids to print out.\n"
112                 "  --stats-reset: to reset port statistics\n"
113                 "  --xstats-reset: to reset port extended statistics\n"
114                 "  --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
115                 "  --host-id STRING: host id used to identify the system process is running on\n",
116                 prgname);
117 }
118
119 /*
120  * Parse the portmask provided at run time.
121  */
122 static int
123 parse_portmask(const char *portmask)
124 {
125         char *end = NULL;
126         unsigned long pm;
127
128         errno = 0;
129
130         /* parse hexadecimal string */
131         pm = strtoul(portmask, &end, 16);
132         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
133                 (errno != 0)) {
134                 printf("%s ERROR parsing the port mask\n", __func__);
135                 return -1;
136         }
137
138         if (pm == 0)
139                 return -1;
140
141         return pm;
142
143 }
144
145 /*
146  * Parse ids value list into array
147  */
148 static int
149 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
150         int length;
151         char *token;
152         char *ctx = NULL;
153         char *endptr;
154
155         length = 0;
156         token = strtok_r(list, ",", &ctx);
157         while (token != NULL) {
158                 ids[length] = strtoull(token, &endptr, 10);
159                 if (*endptr != '\0')
160                         return -EINVAL;
161
162                 length++;
163                 if (length >= limit)
164                         return -E2BIG;
165
166                 token = strtok_r(NULL, ",", &ctx);
167         }
168
169         return length;
170 }
171
172 static int
173 proc_info_preparse_args(int argc, char **argv)
174 {
175         char *prgname = argv[0];
176         int i;
177
178         for (i = 0; i < argc; i++) {
179                 /* Print stats or xstats to STDOUT in collectd format */
180                 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
181                         enable_collectd_format = 1;
182                         stdout_fd = dup(STDOUT_FILENO);
183                         close(STDOUT_FILENO);
184                 }
185                 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
186                         if ((i + 1) == argc) {
187                                 printf("Invalid host id or not specified\n");
188                                 proc_info_usage(prgname);
189                                 return -1;
190                         }
191                         strncpy(host_id, argv[i+1], sizeof(host_id));
192                 }
193         }
194
195         if (!strlen(host_id)) {
196                 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
197
198                 if (err)
199                         strcpy(host_id, "unknown");
200         }
201
202         return 0;
203 }
204
205 /* Parse the argument given in the command line of the application */
206 static int
207 proc_info_parse_args(int argc, char **argv)
208 {
209         int opt;
210         int option_index;
211         char *prgname = argv[0];
212         static struct option long_option[] = {
213                 {"stats", 0, NULL, 0},
214                 {"stats-reset", 0, NULL, 0},
215                 {"xstats", 0, NULL, 0},
216                 {"metrics", 0, NULL, 0},
217                 {"xstats-reset", 0, NULL, 0},
218                 {"xstats-name", required_argument, NULL, 1},
219                 {"collectd-format", 0, NULL, 0},
220                 {"xstats-ids", 1, NULL, 1},
221                 {"host-id", 0, NULL, 0},
222                 {NULL, 0, 0, 0}
223         };
224
225         if (argc == 1)
226                 proc_info_usage(prgname);
227
228         /* Parse command line */
229         while ((opt = getopt_long(argc, argv, "p:m",
230                         long_option, &option_index)) != EOF) {
231                 switch (opt) {
232                 /* portmask */
233                 case 'p':
234                         enabled_port_mask = parse_portmask(optarg);
235                         if (enabled_port_mask == 0) {
236                                 printf("invalid portmask\n");
237                                 proc_info_usage(prgname);
238                                 return -1;
239                         }
240                         break;
241                 case 'm':
242                         mem_info = 1;
243                         break;
244                 case 0:
245                         /* Print stats */
246                         if (!strncmp(long_option[option_index].name, "stats",
247                                         MAX_LONG_OPT_SZ))
248                                 enable_stats = 1;
249                         /* Print xstats */
250                         else if (!strncmp(long_option[option_index].name, "xstats",
251                                         MAX_LONG_OPT_SZ))
252                                 enable_xstats = 1;
253                         else if (!strncmp(long_option[option_index].name,
254                                         "metrics",
255                                         MAX_LONG_OPT_SZ))
256                                 enable_metrics = 1;
257                         /* Reset stats */
258                         if (!strncmp(long_option[option_index].name, "stats-reset",
259                                         MAX_LONG_OPT_SZ))
260                                 reset_stats = 1;
261                         /* Reset xstats */
262                         else if (!strncmp(long_option[option_index].name, "xstats-reset",
263                                         MAX_LONG_OPT_SZ))
264                                 reset_xstats = 1;
265                         break;
266                 case 1:
267                         /* Print xstat single value given by name*/
268                         if (!strncmp(long_option[option_index].name,
269                                         "xstats-name", MAX_LONG_OPT_SZ)) {
270                                 enable_xstats_name = 1;
271                                 xstats_name = optarg;
272                                 printf("name:%s:%s\n",
273                                                 long_option[option_index].name,
274                                                 optarg);
275                         } else if (!strncmp(long_option[option_index].name,
276                                         "xstats-ids",
277                                         MAX_LONG_OPT_SZ))       {
278                                 nb_xstats_ids = parse_xstats_ids(optarg,
279                                                 xstats_ids, MAX_NB_XSTATS_IDS);
280
281                                 if (nb_xstats_ids <= 0) {
282                                         printf("xstats-id list parse error.\n");
283                                         return -1;
284                                 }
285
286                         }
287                         break;
288                 default:
289                         proc_info_usage(prgname);
290                         return -1;
291                 }
292         }
293         return 0;
294 }
295
296 static void
297 meminfo_display(void)
298 {
299         printf("----------- MEMORY_SEGMENTS -----------\n");
300         rte_dump_physmem_layout(stdout);
301         printf("--------- END_MEMORY_SEGMENTS ---------\n");
302
303         printf("------------ MEMORY_ZONES -------------\n");
304         rte_memzone_dump(stdout);
305         printf("---------- END_MEMORY_ZONES -----------\n");
306
307         printf("------------- TAIL_QUEUES -------------\n");
308         rte_dump_tailq(stdout);
309         printf("---------- END_TAIL_QUEUES ------------\n");
310 }
311
312 static void
313 nic_stats_display(uint16_t port_id)
314 {
315         struct rte_eth_stats stats;
316         uint8_t i;
317
318         static const char *nic_stats_border = "########################";
319
320         rte_eth_stats_get(port_id, &stats);
321         printf("\n  %s NIC statistics for port %-2d %s\n",
322                    nic_stats_border, port_id, nic_stats_border);
323
324         printf("  RX-packets: %-10"PRIu64"  RX-errors:  %-10"PRIu64
325                "  RX-bytes:  %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
326                stats.ibytes);
327         printf("  RX-nombuf:  %-10"PRIu64"\n", stats.rx_nombuf);
328         printf("  TX-packets: %-10"PRIu64"  TX-errors:  %-10"PRIu64
329                "  TX-bytes:  %-10"PRIu64"\n", stats.opackets, stats.oerrors,
330                stats.obytes);
331
332         printf("\n");
333         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
334                 printf("  Stats reg %2d RX-packets: %-10"PRIu64
335                        "  RX-errors: %-10"PRIu64
336                        "  RX-bytes: %-10"PRIu64"\n",
337                        i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
338         }
339
340         printf("\n");
341         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
342                 printf("  Stats reg %2d TX-packets: %-10"PRIu64
343                        "  TX-bytes: %-10"PRIu64"\n",
344                        i, stats.q_opackets[i], stats.q_obytes[i]);
345         }
346
347         printf("  %s############################%s\n",
348                    nic_stats_border, nic_stats_border);
349 }
350
351 static void
352 nic_stats_clear(uint16_t port_id)
353 {
354         printf("\n Clearing NIC stats for port %d\n", port_id);
355         rte_eth_stats_reset(port_id);
356         printf("\n  NIC statistics for port %d cleared\n", port_id);
357 }
358
359 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
360                                       const char *cnt_name) {
361         char *type_end = strrchr(cnt_name, '_');
362
363         if ((type_end != NULL) &&
364             (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
365                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
366                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
367                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
368                         strncpy(cnt_type, "if_rx_dropped", cnt_type_len);
369                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
370                         strncpy(cnt_type, "if_rx_octets", cnt_type_len);
371                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
372                         strncpy(cnt_type, "if_rx_packets", cnt_type_len);
373                 else if (strncmp(type_end, "_placement",
374                                  strlen("_placement")) == 0)
375                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
376                 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
377                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
378                 else
379                         /* Does not fit obvious type: use a more generic one */
380                         strncpy(cnt_type, "derive", cnt_type_len);
381         } else if ((type_end != NULL) &&
382                 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
383                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
384                         strncpy(cnt_type, "if_tx_errors", cnt_type_len);
385                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
386                         strncpy(cnt_type, "if_tx_dropped", cnt_type_len);
387                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
388                         strncpy(cnt_type, "if_tx_octets", cnt_type_len);
389                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
390                         strncpy(cnt_type, "if_tx_packets", cnt_type_len);
391                 else
392                         /* Does not fit obvious type: use a more generic one */
393                         strncpy(cnt_type, "derive", cnt_type_len);
394         } else if ((type_end != NULL) &&
395                    (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
396                 if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
397                         strncpy(cnt_type, "operations", cnt_type_len);
398                 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
399                         strncpy(cnt_type, "errors", cnt_type_len);
400                 else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
401                         strncpy(cnt_type, "filter_result", cnt_type_len);
402         } else if ((type_end != NULL) &&
403                    (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
404                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
405                         strncpy(cnt_type, "errors", cnt_type_len);
406         } else {
407                 /* Does not fit obvious type, or strrchr error: */
408                 /* use a more generic type */
409                 strncpy(cnt_type, "derive", cnt_type_len);
410         }
411 }
412
413 static void
414 nic_xstats_by_name_display(uint16_t port_id, char *name)
415 {
416         uint64_t id;
417
418         printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
419                            port_id, name);
420
421         if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
422                 printf("%s: %"PRIu64"\n", name, id);
423         else
424                 printf("Statistic not found...\n");
425
426 }
427
428 static void
429 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
430 {
431         struct rte_eth_xstat_name *xstats_names;
432         uint64_t *values;
433         int ret, i;
434         static const char *nic_stats_border = "########################";
435
436         values = malloc(sizeof(*values) * len);
437         if (values == NULL) {
438                 printf("Cannot allocate memory for xstats\n");
439                 return;
440         }
441
442         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
443         if (xstats_names == NULL) {
444                 printf("Cannot allocate memory for xstat names\n");
445                 free(values);
446                 return;
447         }
448
449         if (len != rte_eth_xstats_get_names_by_id(
450                         port_id, xstats_names, len, ids)) {
451                 printf("Cannot get xstat names\n");
452                 goto err;
453         }
454
455         printf("###### NIC extended statistics for port %-2d #########\n",
456                            port_id);
457         printf("%s############################\n", nic_stats_border);
458         ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
459         if (ret < 0 || ret > len) {
460                 printf("Cannot get xstats\n");
461                 goto err;
462         }
463
464         for (i = 0; i < len; i++)
465                 printf("%s: %"PRIu64"\n",
466                         xstats_names[i].name,
467                         values[i]);
468
469         printf("%s############################\n", nic_stats_border);
470 err:
471         free(values);
472         free(xstats_names);
473 }
474
475 static void
476 nic_xstats_display(uint16_t port_id)
477 {
478         struct rte_eth_xstat_name *xstats_names;
479         uint64_t *values;
480         int len, ret, i;
481         static const char *nic_stats_border = "########################";
482
483         len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
484         if (len < 0) {
485                 printf("Cannot get xstats count\n");
486                 return;
487         }
488         values = malloc(sizeof(*values) * len);
489         if (values == NULL) {
490                 printf("Cannot allocate memory for xstats\n");
491                 return;
492         }
493
494         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
495         if (xstats_names == NULL) {
496                 printf("Cannot allocate memory for xstat names\n");
497                 free(values);
498                 return;
499         }
500         if (len != rte_eth_xstats_get_names_by_id(
501                         port_id, xstats_names, len, NULL)) {
502                 printf("Cannot get xstat names\n");
503                 goto err;
504         }
505
506         printf("###### NIC extended statistics for port %-2d #########\n",
507                            port_id);
508         printf("%s############################\n",
509                            nic_stats_border);
510         ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
511         if (ret < 0 || ret > len) {
512                 printf("Cannot get xstats\n");
513                 goto err;
514         }
515
516         for (i = 0; i < len; i++) {
517                 if (enable_collectd_format) {
518                         char counter_type[MAX_STRING_LEN];
519                         char buf[MAX_STRING_LEN];
520
521                         collectd_resolve_cnt_type(counter_type,
522                                                   sizeof(counter_type),
523                                                   xstats_names[i].name);
524                         sprintf(buf, "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
525                                 PRIu64"\n", host_id, port_id, counter_type,
526                                 xstats_names[i].name, values[i]);
527                         ret = write(stdout_fd, buf, strlen(buf));
528                         if (ret < 0)
529                                 goto err;
530                 } else {
531                         printf("%s: %"PRIu64"\n", xstats_names[i].name,
532                                         values[i]);
533                 }
534         }
535
536         printf("%s############################\n",
537                            nic_stats_border);
538 err:
539         free(values);
540         free(xstats_names);
541 }
542
543 static void
544 nic_xstats_clear(uint16_t port_id)
545 {
546         printf("\n Clearing NIC xstats for port %d\n", port_id);
547         rte_eth_xstats_reset(port_id);
548         printf("\n  NIC extended statistics for port %d cleared\n", port_id);
549 }
550
551 static void
552 metrics_display(int port_id)
553 {
554         struct rte_metric_value *metrics;
555         struct rte_metric_name *names;
556         int len, ret;
557         static const char *nic_stats_border = "########################";
558
559         len = rte_metrics_get_names(NULL, 0);
560         if (len < 0) {
561                 printf("Cannot get metrics count\n");
562                 return;
563         }
564         if (len == 0) {
565                 printf("No metrics to display (none have been registered)\n");
566                 return;
567         }
568
569         metrics = rte_malloc("proc_info_metrics",
570                 sizeof(struct rte_metric_value) * len, 0);
571         if (metrics == NULL) {
572                 printf("Cannot allocate memory for metrics\n");
573                 return;
574         }
575
576         names =  rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
577         if (names == NULL) {
578                 printf("Cannot allocate memory for metrcis names\n");
579                 rte_free(metrics);
580                 return;
581         }
582
583         if (len != rte_metrics_get_names(names, len)) {
584                 printf("Cannot get metrics names\n");
585                 rte_free(metrics);
586                 rte_free(names);
587                 return;
588         }
589
590         if (port_id == RTE_METRICS_GLOBAL)
591                 printf("###### Non port specific metrics  #########\n");
592         else
593                 printf("###### metrics for port %-2d #########\n", port_id);
594         printf("%s############################\n", nic_stats_border);
595         ret = rte_metrics_get_values(port_id, metrics, len);
596         if (ret < 0 || ret > len) {
597                 printf("Cannot get metrics values\n");
598                 rte_free(metrics);
599                 rte_free(names);
600                 return;
601         }
602
603         int i;
604         for (i = 0; i < len; i++)
605                 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
606
607         printf("%s############################\n", nic_stats_border);
608         rte_free(metrics);
609         rte_free(names);
610 }
611
612 int
613 main(int argc, char **argv)
614 {
615         int ret;
616         int i;
617         char c_flag[] = "-c1";
618         char n_flag[] = "-n4";
619         char mp_flag[] = "--proc-type=secondary";
620         char *argp[argc + 3];
621         uint16_t nb_ports;
622
623         /* preparse app arguments */
624         ret = proc_info_preparse_args(argc, argv);
625         if (ret < 0) {
626                 printf("Failed to parse arguments\n");
627                 return -1;
628         }
629
630         argp[0] = argv[0];
631         argp[1] = c_flag;
632         argp[2] = n_flag;
633         argp[3] = mp_flag;
634
635         for (i = 1; i < argc; i++)
636                 argp[i + 3] = argv[i];
637
638         argc += 3;
639
640         ret = rte_eal_init(argc, argp);
641         if (ret < 0)
642                 rte_panic("Cannot init EAL\n");
643
644         argc -= ret;
645         argv += (ret - 3);
646
647         if (!rte_eal_primary_proc_alive(NULL))
648                 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
649
650         /* parse app arguments */
651         ret = proc_info_parse_args(argc, argv);
652         if (ret < 0)
653                 rte_exit(EXIT_FAILURE, "Invalid argument\n");
654
655         if (mem_info) {
656                 meminfo_display();
657                 return 0;
658         }
659
660         nb_ports = rte_eth_dev_count();
661         if (nb_ports == 0)
662                 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
663
664         /* If no port mask was specified*/
665         if (enabled_port_mask == 0)
666                 enabled_port_mask = 0xffff;
667
668         for (i = 0; i < nb_ports; i++) {
669                 if (enabled_port_mask & (1 << i)) {
670                         if (enable_stats)
671                                 nic_stats_display(i);
672                         else if (enable_xstats)
673                                 nic_xstats_display(i);
674                         else if (reset_stats)
675                                 nic_stats_clear(i);
676                         else if (reset_xstats)
677                                 nic_xstats_clear(i);
678                         else if (enable_xstats_name)
679                                 nic_xstats_by_name_display(i, xstats_name);
680                         else if (nb_xstats_ids > 0)
681                                 nic_xstats_by_ids_display(i, xstats_ids,
682                                                 nb_xstats_ids);
683                         else if (enable_metrics)
684                                 metrics_display(i);
685                 }
686         }
687
688         /* print port independent stats */
689         if (enable_metrics)
690                 metrics_display(RTE_METRICS_GLOBAL);
691
692         return 0;
693 }