net: statistics: Move current statistics code to its own file
This file will own more statistics handling in a near future. Change-Id: Ifaf86852f5c7166e6878b5dc8f4cd4c166dbee90 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
2f9efd1a8e
commit
a533eb9b4f
4 changed files with 169 additions and 115 deletions
|
@ -18,6 +18,7 @@ obj-$(CONFIG_NET_RPL_OF0) += rpl-of0.o
|
|||
obj-$(CONFIG_NET_MGMT_EVENT) += net_mgmt.o
|
||||
obj-$(CONFIG_NET_TCP) += tcp.o
|
||||
obj-$(CONFIG_NET_SHELL) += net_shell.o
|
||||
obj-$(CONFIG_NET_STATISTICS) += net_stats.o
|
||||
|
||||
ifeq ($(CONFIG_NET_UDP),y)
|
||||
obj-$(CONFIG_NET_UDP) += connection.o
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include <net/arp.h>
|
||||
#include <net/nbuf.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_stats.h>
|
||||
|
||||
#include "net_private.h"
|
||||
#include "net_shell.h"
|
||||
|
@ -57,6 +56,8 @@
|
|||
#include "udp.h"
|
||||
#include "tcp.h"
|
||||
|
||||
#include "net_stats.h"
|
||||
|
||||
/* Stack for the rx thread.
|
||||
*/
|
||||
#if !defined(CONFIG_NET_RX_STACK_SIZE)
|
||||
|
@ -69,120 +70,6 @@ NET_STACK_DEFINE(RX, rx_stack, CONFIG_NET_RX_STACK_SIZE,
|
|||
static struct k_fifo rx_queue;
|
||||
static k_tid_t rx_tid;
|
||||
|
||||
#if defined(CONFIG_NET_STATISTICS)
|
||||
#define PRINT(fmt, ...) NET_INFO(fmt, ##__VA_ARGS__)
|
||||
struct net_stats net_stats;
|
||||
#define GET_STAT(s) net_stats.s
|
||||
#define PRINT_STATISTICS_INTERVAL (30 * MSEC_PER_SEC)
|
||||
#define net_print_statistics stats /* to make the debug print line shorter */
|
||||
|
||||
static inline void stats(void)
|
||||
{
|
||||
static int64_t next_print;
|
||||
int64_t curr = k_uptime_get();
|
||||
|
||||
if (!next_print || (next_print < curr &&
|
||||
(!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) {
|
||||
int64_t new_print;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
PRINT("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
|
||||
GET_STAT(ipv6.recv),
|
||||
GET_STAT(ipv6.sent),
|
||||
GET_STAT(ipv6.drop),
|
||||
GET_STAT(ipv6.forwarded));
|
||||
#if defined(CONFIG_NET_IPV6_ND)
|
||||
PRINT("IPv6 ND recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(ipv6_nd.recv),
|
||||
GET_STAT(ipv6_nd.sent),
|
||||
GET_STAT(ipv6_nd.drop));
|
||||
#endif /* CONFIG_NET_IPV6_ND */
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
PRINT("IPv4 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
|
||||
GET_STAT(ipv4.recv),
|
||||
GET_STAT(ipv4.sent),
|
||||
GET_STAT(ipv4.drop),
|
||||
GET_STAT(ipv4.forwarded));
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
|
||||
PRINT("IP vhlerr %d\thblener\t%d\tlblener\t%d",
|
||||
GET_STAT(ip_errors.vhlerr),
|
||||
GET_STAT(ip_errors.hblenerr),
|
||||
GET_STAT(ip_errors.lblenerr));
|
||||
PRINT("IP fragerr %d\tchkerr\t%d\tprotoer\t%d",
|
||||
GET_STAT(ip_errors.fragerr),
|
||||
GET_STAT(ip_errors.chkerr),
|
||||
GET_STAT(ip_errors.protoerr));
|
||||
|
||||
PRINT("ICMP recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(icmp.recv),
|
||||
GET_STAT(icmp.sent),
|
||||
GET_STAT(icmp.drop));
|
||||
PRINT("ICMP typeer %d\tchkerr\t%d",
|
||||
GET_STAT(icmp.typeerr),
|
||||
GET_STAT(icmp.chkerr));
|
||||
|
||||
#if defined(CONFIG_NET_UDP)
|
||||
PRINT("UDP recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(udp.recv),
|
||||
GET_STAT(udp.sent),
|
||||
GET_STAT(udp.drop));
|
||||
PRINT("UDP chkerr %d",
|
||||
GET_STAT(udp.chkerr));
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_RPL_STATS)
|
||||
PRINT("RPL DIS recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(rpl.dis.recv),
|
||||
GET_STAT(rpl.dis.sent),
|
||||
GET_STAT(rpl.dis.drop));
|
||||
PRINT("RPL DIO recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(rpl.dio.recv),
|
||||
GET_STAT(rpl.dio.sent),
|
||||
GET_STAT(rpl.dio.drop));
|
||||
PRINT("RPL DAO recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
|
||||
GET_STAT(rpl.dao.recv),
|
||||
GET_STAT(rpl.dao.sent),
|
||||
GET_STAT(rpl.dao.drop),
|
||||
GET_STAT(rpl.dao.forwarded));
|
||||
PRINT("RPL DAOACK rcv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(rpl.dao_ack.recv),
|
||||
GET_STAT(rpl.dao_ack.sent),
|
||||
GET_STAT(rpl.dao_ack.drop));
|
||||
PRINT("RPL overflows %d\tl-repairs\t%d\tg-repairs\t%d",
|
||||
GET_STAT(rpl.mem_overflows),
|
||||
GET_STAT(rpl.local_repairs),
|
||||
GET_STAT(rpl.global_repairs));
|
||||
PRINT("RPL malformed %d\tresets \t%d\tp-switch\t%d",
|
||||
GET_STAT(rpl.malformed_msgs),
|
||||
GET_STAT(rpl.resets),
|
||||
GET_STAT(rpl.parent_switch));
|
||||
PRINT("RPL f-errors %d\tl-errors\t%d\tl-warnings\t%d",
|
||||
GET_STAT(rpl.forward_errors),
|
||||
GET_STAT(rpl.loop_errors),
|
||||
GET_STAT(rpl.loop_warnings));
|
||||
PRINT("RPL r-repairs %d",
|
||||
GET_STAT(rpl.root_repairs));
|
||||
#endif
|
||||
|
||||
PRINT("Processing err %d", GET_STAT(processing_error));
|
||||
|
||||
new_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||
if (new_print > curr) {
|
||||
next_print = new_print;
|
||||
} else {
|
||||
/* Overflow */
|
||||
next_print = PRINT_STATISTICS_INTERVAL -
|
||||
(LLONG_MAX - curr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else /* CONFIG_NET_STATISTICS */
|
||||
#define net_print_statistics()
|
||||
#endif /* CONFIG_NET_STATISTICS */
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
static inline enum net_verdict process_icmpv6_pkt(struct net_buf *buf,
|
||||
struct net_ipv6_hdr *ipv6)
|
||||
|
|
133
subsys/net/ip/net_stats.c
Normal file
133
subsys/net/ip/net_stats.c
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_CORE)
|
||||
#define SYS_LOG_DOMAIN "net/core"
|
||||
#endif
|
||||
|
||||
#include <kernel.h>
|
||||
#include <string.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_stats.h>
|
||||
|
||||
struct net_stats net_stats;
|
||||
|
||||
#define GET_STAT(s) net_stats.s
|
||||
#define PRINT_STATISTICS_INTERVAL (30 * MSEC_PER_SEC)
|
||||
|
||||
void net_print_statistics(void)
|
||||
{
|
||||
static int64_t next_print;
|
||||
int64_t curr = k_uptime_get();
|
||||
|
||||
if (!next_print || (next_print < curr &&
|
||||
(!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) {
|
||||
int64_t new_print;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
NET_INFO("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
|
||||
GET_STAT(ipv6.recv),
|
||||
GET_STAT(ipv6.sent),
|
||||
GET_STAT(ipv6.drop),
|
||||
GET_STAT(ipv6.forwarded));
|
||||
#if defined(CONFIG_NET_IPV6_ND)
|
||||
NET_INFO("IPv6 ND recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(ipv6_nd.recv),
|
||||
GET_STAT(ipv6_nd.sent),
|
||||
GET_STAT(ipv6_nd.drop));
|
||||
#endif /* CONFIG_NET_IPV6_ND */
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
NET_INFO("IPv4 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
|
||||
GET_STAT(ipv4.recv),
|
||||
GET_STAT(ipv4.sent),
|
||||
GET_STAT(ipv4.drop),
|
||||
GET_STAT(ipv4.forwarded));
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
|
||||
NET_INFO("IP vhlerr %d\thblener\t%d\tlblener\t%d",
|
||||
GET_STAT(ip_errors.vhlerr),
|
||||
GET_STAT(ip_errors.hblenerr),
|
||||
GET_STAT(ip_errors.lblenerr));
|
||||
NET_INFO("IP fragerr %d\tchkerr\t%d\tprotoer\t%d",
|
||||
GET_STAT(ip_errors.fragerr),
|
||||
GET_STAT(ip_errors.chkerr),
|
||||
GET_STAT(ip_errors.protoerr));
|
||||
|
||||
NET_INFO("ICMP recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(icmp.recv),
|
||||
GET_STAT(icmp.sent),
|
||||
GET_STAT(icmp.drop));
|
||||
NET_INFO("ICMP typeer %d\tchkerr\t%d",
|
||||
GET_STAT(icmp.typeerr),
|
||||
GET_STAT(icmp.chkerr));
|
||||
|
||||
#if defined(CONFIG_NET_UDP)
|
||||
NET_INFO("UDP recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(udp.recv),
|
||||
GET_STAT(udp.sent),
|
||||
GET_STAT(udp.drop));
|
||||
NET_INFO("UDP chkerr %d",
|
||||
GET_STAT(udp.chkerr));
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_RPL_STATS)
|
||||
NET_INFO("RPL DIS recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(rpl.dis.recv),
|
||||
GET_STAT(rpl.dis.sent),
|
||||
GET_STAT(rpl.dis.drop));
|
||||
NET_INFO("RPL DIO recv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(rpl.dio.recv),
|
||||
GET_STAT(rpl.dio..sent),
|
||||
GET_STAT(rpl.dio.drop));
|
||||
NET_INFO("RPL DAO recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
|
||||
GET_STAT(rpl.dao.recv),
|
||||
GET_STAT(rpl.dao.sent),
|
||||
GET_STAT(rpl.dao.drop),
|
||||
GET_STAT(rpl.dao.forwarded));
|
||||
NET_INFO("RPL DAOACK rcv %d\tsent\t%d\tdrop\t%d",
|
||||
GET_STAT(rpl.dao_ack.recv),
|
||||
GET_STAT(rpl.dao_ack.sent),
|
||||
GET_STAT(rpl.dao_ack.drop));
|
||||
NET_INFO("RPL overflows %d\tl-repairs\t%d\tg-repairs\t%d",
|
||||
GET_STAT(rpl.mem_overflows),
|
||||
GET_STAT(rpl.local_repairs),
|
||||
GET_STAT(rpl.global_repairs));
|
||||
NET_INFO("RPL malformed %d\tresets \t%d\tp-switch\t%d",
|
||||
GET_STAT(rpl.malformed_msgs),
|
||||
GET_STAT(rpl.resets),
|
||||
GET_STAT(rpl.parent_switch));
|
||||
NET_INFO("RPL f-errors %d\tl-errors\t%d\tl-warnings\t%d",
|
||||
GET_STAT(rpl.forward_errors),
|
||||
GET_STAT(rpl.loop_errors),
|
||||
GET_STAT(rpl.loop_warnings));
|
||||
NET_INFO("RPL r-repairs %d",
|
||||
GET_STAT(rpl.root_repairs));
|
||||
#endif
|
||||
|
||||
NET_INFO("Processing err %d", GET_STAT(processing_error));
|
||||
|
||||
new_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||
if (new_print > curr) {
|
||||
next_print = new_print;
|
||||
} else {
|
||||
/* Overflow */
|
||||
next_print = PRINT_STATISTICS_INTERVAL -
|
||||
(LLONG_MAX - curr);
|
||||
}
|
||||
}
|
||||
}
|
33
subsys/net/ip/net_stats.h
Normal file
33
subsys/net/ip/net_stats.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __NET_STATS_H__
|
||||
#define __NET_STATS_H__
|
||||
|
||||
#if defined(CONFIG_NET_STATISTICS)
|
||||
|
||||
extern struct net_stats net_stats;
|
||||
|
||||
/* A simple periodic statistic printer, used only in net core */
|
||||
void net_print_statistics(void);
|
||||
|
||||
#else
|
||||
|
||||
#define net_print_statistics()
|
||||
|
||||
#endif /* CONFIG_NET_STATISTICS */
|
||||
|
||||
#endif /* __NET_STATS_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue