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