Skip to content

Commit a533eb9

Browse files
author
Tomasz Bursztyka
committed
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 <[email protected]>
1 parent 2f9efd1 commit a533eb9

File tree

4 files changed

+169
-115
lines changed

4 files changed

+169
-115
lines changed

subsys/net/ip/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ obj-$(CONFIG_NET_RPL_OF0) += rpl-of0.o
1818
obj-$(CONFIG_NET_MGMT_EVENT) += net_mgmt.o
1919
obj-$(CONFIG_NET_TCP) += tcp.o
2020
obj-$(CONFIG_NET_SHELL) += net_shell.o
21+
obj-$(CONFIG_NET_STATISTICS) += net_stats.o
2122

2223
ifeq ($(CONFIG_NET_UDP),y)
2324
obj-$(CONFIG_NET_UDP) += connection.o

subsys/net/ip/net_core.c

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <net/arp.h>
3939
#include <net/nbuf.h>
4040
#include <net/net_core.h>
41-
#include <net/net_stats.h>
4241

4342
#include "net_private.h"
4443
#include "net_shell.h"
@@ -57,6 +56,8 @@
5756
#include "udp.h"
5857
#include "tcp.h"
5958

59+
#include "net_stats.h"
60+
6061
/* Stack for the rx thread.
6162
*/
6263
#if !defined(CONFIG_NET_RX_STACK_SIZE)
@@ -69,120 +70,6 @@ NET_STACK_DEFINE(RX, rx_stack, CONFIG_NET_RX_STACK_SIZE,
6970
static struct k_fifo rx_queue;
7071
static k_tid_t rx_tid;
7172

72-
#if defined(CONFIG_NET_STATISTICS)
73-
#define PRINT(fmt, ...) NET_INFO(fmt, ##__VA_ARGS__)
74-
struct net_stats net_stats;
75-
#define GET_STAT(s) net_stats.s
76-
#define PRINT_STATISTICS_INTERVAL (30 * MSEC_PER_SEC)
77-
#define net_print_statistics stats /* to make the debug print line shorter */
78-
79-
static inline void stats(void)
80-
{
81-
static int64_t next_print;
82-
int64_t curr = k_uptime_get();
83-
84-
if (!next_print || (next_print < curr &&
85-
(!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) {
86-
int64_t new_print;
87-
88-
#if defined(CONFIG_NET_IPV6)
89-
PRINT("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
90-
GET_STAT(ipv6.recv),
91-
GET_STAT(ipv6.sent),
92-
GET_STAT(ipv6.drop),
93-
GET_STAT(ipv6.forwarded));
94-
#if defined(CONFIG_NET_IPV6_ND)
95-
PRINT("IPv6 ND recv %d\tsent\t%d\tdrop\t%d",
96-
GET_STAT(ipv6_nd.recv),
97-
GET_STAT(ipv6_nd.sent),
98-
GET_STAT(ipv6_nd.drop));
99-
#endif /* CONFIG_NET_IPV6_ND */
100-
#endif /* CONFIG_NET_IPV6 */
101-
102-
#if defined(CONFIG_NET_IPV4)
103-
PRINT("IPv4 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
104-
GET_STAT(ipv4.recv),
105-
GET_STAT(ipv4.sent),
106-
GET_STAT(ipv4.drop),
107-
GET_STAT(ipv4.forwarded));
108-
#endif /* CONFIG_NET_IPV4 */
109-
110-
PRINT("IP vhlerr %d\thblener\t%d\tlblener\t%d",
111-
GET_STAT(ip_errors.vhlerr),
112-
GET_STAT(ip_errors.hblenerr),
113-
GET_STAT(ip_errors.lblenerr));
114-
PRINT("IP fragerr %d\tchkerr\t%d\tprotoer\t%d",
115-
GET_STAT(ip_errors.fragerr),
116-
GET_STAT(ip_errors.chkerr),
117-
GET_STAT(ip_errors.protoerr));
118-
119-
PRINT("ICMP recv %d\tsent\t%d\tdrop\t%d",
120-
GET_STAT(icmp.recv),
121-
GET_STAT(icmp.sent),
122-
GET_STAT(icmp.drop));
123-
PRINT("ICMP typeer %d\tchkerr\t%d",
124-
GET_STAT(icmp.typeerr),
125-
GET_STAT(icmp.chkerr));
126-
127-
#if defined(CONFIG_NET_UDP)
128-
PRINT("UDP recv %d\tsent\t%d\tdrop\t%d",
129-
GET_STAT(udp.recv),
130-
GET_STAT(udp.sent),
131-
GET_STAT(udp.drop));
132-
PRINT("UDP chkerr %d",
133-
GET_STAT(udp.chkerr));
134-
#endif
135-
136-
#if defined(CONFIG_NET_RPL_STATS)
137-
PRINT("RPL DIS recv %d\tsent\t%d\tdrop\t%d",
138-
GET_STAT(rpl.dis.recv),
139-
GET_STAT(rpl.dis.sent),
140-
GET_STAT(rpl.dis.drop));
141-
PRINT("RPL DIO recv %d\tsent\t%d\tdrop\t%d",
142-
GET_STAT(rpl.dio.recv),
143-
GET_STAT(rpl.dio.sent),
144-
GET_STAT(rpl.dio.drop));
145-
PRINT("RPL DAO recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
146-
GET_STAT(rpl.dao.recv),
147-
GET_STAT(rpl.dao.sent),
148-
GET_STAT(rpl.dao.drop),
149-
GET_STAT(rpl.dao.forwarded));
150-
PRINT("RPL DAOACK rcv %d\tsent\t%d\tdrop\t%d",
151-
GET_STAT(rpl.dao_ack.recv),
152-
GET_STAT(rpl.dao_ack.sent),
153-
GET_STAT(rpl.dao_ack.drop));
154-
PRINT("RPL overflows %d\tl-repairs\t%d\tg-repairs\t%d",
155-
GET_STAT(rpl.mem_overflows),
156-
GET_STAT(rpl.local_repairs),
157-
GET_STAT(rpl.global_repairs));
158-
PRINT("RPL malformed %d\tresets \t%d\tp-switch\t%d",
159-
GET_STAT(rpl.malformed_msgs),
160-
GET_STAT(rpl.resets),
161-
GET_STAT(rpl.parent_switch));
162-
PRINT("RPL f-errors %d\tl-errors\t%d\tl-warnings\t%d",
163-
GET_STAT(rpl.forward_errors),
164-
GET_STAT(rpl.loop_errors),
165-
GET_STAT(rpl.loop_warnings));
166-
PRINT("RPL r-repairs %d",
167-
GET_STAT(rpl.root_repairs));
168-
#endif
169-
170-
PRINT("Processing err %d", GET_STAT(processing_error));
171-
172-
new_print = curr + PRINT_STATISTICS_INTERVAL;
173-
if (new_print > curr) {
174-
next_print = new_print;
175-
} else {
176-
/* Overflow */
177-
next_print = PRINT_STATISTICS_INTERVAL -
178-
(LLONG_MAX - curr);
179-
}
180-
}
181-
}
182-
#else /* CONFIG_NET_STATISTICS */
183-
#define net_print_statistics()
184-
#endif /* CONFIG_NET_STATISTICS */
185-
18673
#if defined(CONFIG_NET_IPV6)
18774
static inline enum net_verdict process_icmpv6_pkt(struct net_buf *buf,
18875
struct net_ipv6_hdr *ipv6)

subsys/net/ip/net_stats.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#if defined(CONFIG_NET_DEBUG_CORE)
18+
#define SYS_LOG_DOMAIN "net/core"
19+
#endif
20+
21+
#include <kernel.h>
22+
#include <string.h>
23+
#include <net/net_core.h>
24+
#include <net/net_stats.h>
25+
26+
struct net_stats net_stats;
27+
28+
#define GET_STAT(s) net_stats.s
29+
#define PRINT_STATISTICS_INTERVAL (30 * MSEC_PER_SEC)
30+
31+
void net_print_statistics(void)
32+
{
33+
static int64_t next_print;
34+
int64_t curr = k_uptime_get();
35+
36+
if (!next_print || (next_print < curr &&
37+
(!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) {
38+
int64_t new_print;
39+
40+
#if defined(CONFIG_NET_IPV6)
41+
NET_INFO("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
42+
GET_STAT(ipv6.recv),
43+
GET_STAT(ipv6.sent),
44+
GET_STAT(ipv6.drop),
45+
GET_STAT(ipv6.forwarded));
46+
#if defined(CONFIG_NET_IPV6_ND)
47+
NET_INFO("IPv6 ND recv %d\tsent\t%d\tdrop\t%d",
48+
GET_STAT(ipv6_nd.recv),
49+
GET_STAT(ipv6_nd.sent),
50+
GET_STAT(ipv6_nd.drop));
51+
#endif /* CONFIG_NET_IPV6_ND */
52+
#endif /* CONFIG_NET_IPV6 */
53+
54+
#if defined(CONFIG_NET_IPV4)
55+
NET_INFO("IPv4 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
56+
GET_STAT(ipv4.recv),
57+
GET_STAT(ipv4.sent),
58+
GET_STAT(ipv4.drop),
59+
GET_STAT(ipv4.forwarded));
60+
#endif /* CONFIG_NET_IPV4 */
61+
62+
NET_INFO("IP vhlerr %d\thblener\t%d\tlblener\t%d",
63+
GET_STAT(ip_errors.vhlerr),
64+
GET_STAT(ip_errors.hblenerr),
65+
GET_STAT(ip_errors.lblenerr));
66+
NET_INFO("IP fragerr %d\tchkerr\t%d\tprotoer\t%d",
67+
GET_STAT(ip_errors.fragerr),
68+
GET_STAT(ip_errors.chkerr),
69+
GET_STAT(ip_errors.protoerr));
70+
71+
NET_INFO("ICMP recv %d\tsent\t%d\tdrop\t%d",
72+
GET_STAT(icmp.recv),
73+
GET_STAT(icmp.sent),
74+
GET_STAT(icmp.drop));
75+
NET_INFO("ICMP typeer %d\tchkerr\t%d",
76+
GET_STAT(icmp.typeerr),
77+
GET_STAT(icmp.chkerr));
78+
79+
#if defined(CONFIG_NET_UDP)
80+
NET_INFO("UDP recv %d\tsent\t%d\tdrop\t%d",
81+
GET_STAT(udp.recv),
82+
GET_STAT(udp.sent),
83+
GET_STAT(udp.drop));
84+
NET_INFO("UDP chkerr %d",
85+
GET_STAT(udp.chkerr));
86+
#endif
87+
88+
#if defined(CONFIG_NET_RPL_STATS)
89+
NET_INFO("RPL DIS recv %d\tsent\t%d\tdrop\t%d",
90+
GET_STAT(rpl.dis.recv),
91+
GET_STAT(rpl.dis.sent),
92+
GET_STAT(rpl.dis.drop));
93+
NET_INFO("RPL DIO recv %d\tsent\t%d\tdrop\t%d",
94+
GET_STAT(rpl.dio.recv),
95+
GET_STAT(rpl.dio..sent),
96+
GET_STAT(rpl.dio.drop));
97+
NET_INFO("RPL DAO recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
98+
GET_STAT(rpl.dao.recv),
99+
GET_STAT(rpl.dao.sent),
100+
GET_STAT(rpl.dao.drop),
101+
GET_STAT(rpl.dao.forwarded));
102+
NET_INFO("RPL DAOACK rcv %d\tsent\t%d\tdrop\t%d",
103+
GET_STAT(rpl.dao_ack.recv),
104+
GET_STAT(rpl.dao_ack.sent),
105+
GET_STAT(rpl.dao_ack.drop));
106+
NET_INFO("RPL overflows %d\tl-repairs\t%d\tg-repairs\t%d",
107+
GET_STAT(rpl.mem_overflows),
108+
GET_STAT(rpl.local_repairs),
109+
GET_STAT(rpl.global_repairs));
110+
NET_INFO("RPL malformed %d\tresets \t%d\tp-switch\t%d",
111+
GET_STAT(rpl.malformed_msgs),
112+
GET_STAT(rpl.resets),
113+
GET_STAT(rpl.parent_switch));
114+
NET_INFO("RPL f-errors %d\tl-errors\t%d\tl-warnings\t%d",
115+
GET_STAT(rpl.forward_errors),
116+
GET_STAT(rpl.loop_errors),
117+
GET_STAT(rpl.loop_warnings));
118+
NET_INFO("RPL r-repairs %d",
119+
GET_STAT(rpl.root_repairs));
120+
#endif
121+
122+
NET_INFO("Processing err %d", GET_STAT(processing_error));
123+
124+
new_print = curr + PRINT_STATISTICS_INTERVAL;
125+
if (new_print > curr) {
126+
next_print = new_print;
127+
} else {
128+
/* Overflow */
129+
next_print = PRINT_STATISTICS_INTERVAL -
130+
(LLONG_MAX - curr);
131+
}
132+
}
133+
}

subsys/net/ip/net_stats.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __NET_STATS_H__
18+
#define __NET_STATS_H__
19+
20+
#if defined(CONFIG_NET_STATISTICS)
21+
22+
extern struct net_stats net_stats;
23+
24+
/* A simple periodic statistic printer, used only in net core */
25+
void net_print_statistics(void);
26+
27+
#else
28+
29+
#define net_print_statistics()
30+
31+
#endif /* CONFIG_NET_STATISTICS */
32+
33+
#endif /* __NET_STATS_H__ */

0 commit comments

Comments
 (0)