27 #include <rte_common.h>
28 #include <rte_malloc.h>
29 #include <rte_ether.h>
30 #include <rte_ethdev.h>
31 #include <rte_mempool.h>
42 #define NS_PER_SEC 1E9
43 #ifdef CLOCK_MONOTONIC_RAW
46 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
48 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
62 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
63 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
64 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
65 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
66 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
67 struct timespec cur_time;
68 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx, diff_ns;
69 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
70 struct rte_eth_stats ethernet_stats;
72 static const char *nic_stats_border =
"########################";
73 uint32_t max_rx_queues, max_tx_queues;
75 result = rte_eth_stats_get(port, ðernet_stats);
82 max_rx_queues =
dev_info.nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
dev_info.nb_rx_queues :
83 RTE_ETHDEV_QUEUE_STAT_CNTRS;
84 max_tx_queues =
dev_info.nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
dev_info.nb_tx_queues :
85 RTE_ETHDEV_QUEUE_STAT_CNTRS;
86 fprintf(f,
"\n %s NIC statistics for port %-2d %s\n", nic_stats_border, port, nic_stats_border);
89 " RX-packets: %-10" PRIu64
" RX-missed: %-10" PRIu64
" RX-bytes: %-" PRIu64
"\n",
90 ethernet_stats.ipackets,
91 ethernet_stats.imissed,
92 ethernet_stats.ibytes);
93 fprintf(f,
" RX-errors: %-" PRIu64
"\n", ethernet_stats.ierrors);
94 fprintf(f,
" RX-nombuf: %-10" PRIu64
"\n", ethernet_stats.rx_nombuf);
96 " TX-packets: %-10" PRIu64
" TX-errors: %-10" PRIu64
" TX-bytes: %-" PRIu64
"\n",
97 ethernet_stats.opackets,
98 ethernet_stats.oerrors,
99 ethernet_stats.obytes);
103 for (i = 0; i < max_rx_queues; i++) {
104 printf(
" ethernet_stats reg %2d RX-packets: %-10" PRIu64
" RX-errors: %-10" PRIu64
105 " RX-bytes: %-10" PRIu64
"\n",
107 ethernet_stats.q_ipackets[i],
108 ethernet_stats.q_errors[i],
109 ethernet_stats.q_ibytes[i]);
113 for (i = 0; i < max_tx_queues; i++) {
115 " ethernet_stats reg %2d TX-packets: %-10" PRIu64
" TX-bytes: %-10" PRIu64
"\n",
117 ethernet_stats.q_opackets[i],
118 ethernet_stats.q_obytes[i]);
126 ns += cur_time.tv_nsec;
128 if (prev_ns[port] != 0)
129 diff_ns = ns - prev_ns[port];
133 diff_pkts_rx = (ethernet_stats.ipackets > prev_pkts_rx[port]) ? (ethernet_stats.ipackets - prev_pkts_rx[port]) :
135 diff_pkts_tx = (ethernet_stats.opackets > prev_pkts_tx[port]) ? (ethernet_stats.opackets - prev_pkts_tx[port]) :
137 prev_pkts_rx[port] = ethernet_stats.ipackets;
138 prev_pkts_tx[port] = ethernet_stats.opackets;
139 mpps_rx = diff_ns > 0 ? (double)diff_pkts_rx / diff_ns *
NS_PER_SEC : 0;
140 mpps_tx = diff_ns > 0 ? (double)diff_pkts_tx / diff_ns *
NS_PER_SEC : 0;
142 diff_bytes_rx = (ethernet_stats.ibytes > prev_bytes_rx[port]) ? (ethernet_stats.ibytes - prev_bytes_rx[port]) :
144 diff_bytes_tx = (ethernet_stats.obytes > prev_bytes_tx[port]) ? (ethernet_stats.obytes - prev_bytes_tx[port]) :
146 prev_bytes_rx[port] = ethernet_stats.ibytes;
147 prev_bytes_tx[port] = ethernet_stats.obytes;
148 mbps_rx = diff_ns > 0 ? (double)diff_bytes_rx / diff_ns *
NS_PER_SEC : 0;
149 mbps_tx = diff_ns > 0 ? (double)diff_bytes_tx / diff_ns *
NS_PER_SEC : 0;
151 fprintf(f,
"\n Throughput (since last show)\n");
153 " Rx-pps: %12" PRIu64
" Rx-bps: %12" PRIu64
"\n Tx-pps: %12" PRIu64
154 " Tx-bps: %12" PRIu64
"\n",
160 fprintf(f,
" %s############################%s\n", nic_stats_border, nic_stats_border);
167 const char clr[] = {27,
'[',
'2',
'J',
'\0'};
168 const char topLeft[] = {27,
'[',
'1',
';',
'1',
'H',
'\0'};
170 fprintf(stdout,
"%s%s", clr, topLeft);
struct rte_eth_dev_info dev_info
DOCA_EXPERIMENTAL void doca_flow_port_pipes_dump(struct doca_flow_port *port, FILE *f)
Dump pipes of one port.
static int simple_fwd_port_stats_display(uint16_t port, FILE *f)
DOCA_LOG_REGISTER(SIMPLE_FWD_PORT)
int simple_fwd_dump_port_stats(uint16_t port_id, struct doca_flow_port *port)