samples: net: stats: Print ethernet statistics
If ethernet statistics collection is enabled, then print it to the user. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
3e048f6d3e
commit
435d173870
|
@ -11,6 +11,7 @@ CONFIG_NET_TCP=y
|
|||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_STATISTICS_USER_API=y
|
||||
CONFIG_NET_STATISTICS_PER_INTERFACE=y
|
||||
CONFIG_NET_STATISTICS_ETHERNET=y
|
||||
|
||||
# How often to print current statistics
|
||||
CONFIG_SAMPLE_PERIOD=30
|
||||
|
|
|
@ -159,6 +159,41 @@ static void iface_cb(struct net_if *iface, void *user_data)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_STATISTICS_ETHERNET)
|
||||
static void print_eth_stats(struct net_if *iface, struct net_stats_eth *data)
|
||||
{
|
||||
printk("Statistics for Ethernet interface %p [%d]\n", iface,
|
||||
net_if_get_by_iface(iface));
|
||||
|
||||
printk("Bytes received : %u\n", data->bytes.received);
|
||||
printk("Bytes sent : %u\n", data->bytes.sent);
|
||||
printk("Packets received : %u\n", data->pkts.rx);
|
||||
printk("Packets sent : %u\n", data->pkts.tx);
|
||||
printk("Bcast received : %u\n", data->broadcast.rx);
|
||||
printk("Bcast sent : %u\n", data->broadcast.tx);
|
||||
printk("Mcast received : %u\n", data->multicast.rx);
|
||||
printk("Mcast sent : %u\n", data->multicast.tx);
|
||||
}
|
||||
|
||||
static void eth_iface_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
struct net_stats_eth eth_data;
|
||||
int ret;
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ret = net_mgmt(NET_REQUEST_STATS_GET_ETHERNET, iface, ð_data,
|
||||
sizeof(eth_data));
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
print_eth_stats(iface, ð_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void stats(struct k_work *work)
|
||||
{
|
||||
struct net_stats data;
|
||||
|
@ -175,6 +210,10 @@ static void stats(struct k_work *work)
|
|||
net_if_foreach(iface_cb, &data);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_STATISTICS_ETHERNET)
|
||||
net_if_foreach(eth_iface_cb, &data);
|
||||
#endif
|
||||
|
||||
k_delayed_work_submit(&stats_timer, K_SECONDS(CONFIG_SAMPLE_PERIOD));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue