From 9e4b667292bd8ffd0c441249ddfd2ca4292fbadb Mon Sep 17 00:00:00 2001 From: Matteo Croce Date: Thu, 18 Oct 2018 23:25:20 +0200 Subject: [PATCH] ovs_stats: add macro to populate counters list Use a stringification macro to populate the counter array. Doing this instead of duplicating the tokens is less error prone. Signed-off-by: Matteo Croce --- src/ovs_stats.c | 70 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/ovs_stats.c b/src/ovs_stats.c index f513e72e..72c92b2f 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -94,42 +94,46 @@ typedef struct bridge_list_s { struct bridge_list_s *next; /* Next bridge*/ } bridge_list_t; +#define cnt_str(x) [x] = #x + static const char *const iface_counter_table[IFACE_COUNTER_COUNT] = { - [collisions] = "collisions", - [rx_bytes] = "rx_bytes", - [rx_crc_err] = "rx_crc_err", - [rx_dropped] = "rx_dropped", - [rx_errors] = "rx_errors", - [rx_frame_err] = "rx_frame_err", - [rx_over_err] = "rx_over_err", - [rx_packets] = "rx_packets", - [tx_bytes] = "tx_bytes", - [tx_dropped] = "tx_dropped", - [tx_errors] = "tx_errors", - [tx_packets] = "tx_packets", - [rx_1_to_64_packets] = "rx_1_to_64_packets", - [rx_65_to_127_packets] = "rx_65_to_127_packets", - [rx_128_to_255_packets] = "rx_128_to_255_packets", - [rx_256_to_511_packets] = "rx_256_to_511_packets", - [rx_512_to_1023_packets] = "rx_512_to_1023_packets", - [rx_1024_to_1522_packets] = "rx_1024_to_1518_packets", - [rx_1523_to_max_packets] = "rx_1523_to_max_packets", - [tx_1_to_64_packets] = "tx_1_to_64_packets", - [tx_65_to_127_packets] = "tx_65_to_127_packets", - [tx_128_to_255_packets] = "tx_128_to_255_packets", - [tx_256_to_511_packets] = "tx_256_to_511_packets", - [tx_512_to_1023_packets] = "tx_512_to_1023_packets", - [tx_1024_to_1522_packets] = "tx_1024_to_1518_packets", - [tx_1523_to_max_packets] = "tx_1523_to_max_packets", - [tx_multicast_packets] = "tx_multicast_packets", - [rx_broadcast_packets] = "rx_broadcast_packets", - [tx_broadcast_packets] = "tx_broadcast_packets", - [rx_undersized_errors] = "rx_undersized_errors", - [rx_oversize_errors] = "rx_oversize_errors", - [rx_fragmented_errors] = "rx_fragmented_errors", - [rx_jabber_errors] = "rx_jabber_errors", + cnt_str(collisions), + cnt_str(rx_bytes), + cnt_str(rx_crc_err), + cnt_str(rx_dropped), + cnt_str(rx_errors), + cnt_str(rx_frame_err), + cnt_str(rx_over_err), + cnt_str(rx_packets), + cnt_str(tx_bytes), + cnt_str(tx_dropped), + cnt_str(tx_errors), + cnt_str(tx_packets), + cnt_str(rx_1_to_64_packets), + cnt_str(rx_65_to_127_packets), + cnt_str(rx_128_to_255_packets), + cnt_str(rx_256_to_511_packets), + cnt_str(rx_512_to_1023_packets), + cnt_str(rx_1024_to_1522_packets), + cnt_str(rx_1523_to_max_packets), + cnt_str(tx_1_to_64_packets), + cnt_str(tx_65_to_127_packets), + cnt_str(tx_128_to_255_packets), + cnt_str(tx_256_to_511_packets), + cnt_str(tx_512_to_1023_packets), + cnt_str(tx_1024_to_1522_packets), + cnt_str(tx_1523_to_max_packets), + cnt_str(tx_multicast_packets), + cnt_str(rx_broadcast_packets), + cnt_str(tx_broadcast_packets), + cnt_str(rx_undersized_errors), + cnt_str(rx_oversize_errors), + cnt_str(rx_fragmented_errors), + cnt_str(rx_jabber_errors), }; +#undef cnt_str + /* Entry into the list of network bridges */ static bridge_list_t *g_bridge_list_head; -- 2.11.0