uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
stats.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef __LWIP_STATS_H__
33 #define __LWIP_STATS_H__
34 
35 #include "lwip/opt.h"
36 
37 #include "lwip/mem.h"
38 #include "lwip/memp.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #if LWIP_STATS
45 
46 #ifndef LWIP_STATS_LARGE
47 #define LWIP_STATS_LARGE 0
48 #endif
49 
50 #if LWIP_STATS_LARGE
51 #define STAT_COUNTER u32_t
52 #define STAT_COUNTER_F U32_F
53 #else
54 #define STAT_COUNTER u16_t
55 #define STAT_COUNTER_F U16_F
56 #endif
57 
58 struct stats_proto {
59  STAT_COUNTER xmit; /* Transmitted packets. */
60  STAT_COUNTER recv; /* Received packets. */
61  STAT_COUNTER fw; /* Forwarded packets. */
62  STAT_COUNTER drop; /* Dropped packets. */
63  STAT_COUNTER chkerr; /* Checksum error. */
64  STAT_COUNTER lenerr; /* Invalid length error. */
65  STAT_COUNTER memerr; /* Out of memory error. */
66  STAT_COUNTER rterr; /* Routing error. */
67  STAT_COUNTER proterr; /* Protocol error. */
68  STAT_COUNTER opterr; /* Error in options. */
69  STAT_COUNTER err; /* Misc error. */
70  STAT_COUNTER cachehit;
71 };
72 
73 struct stats_igmp {
74  STAT_COUNTER xmit; /* Transmitted packets. */
75  STAT_COUNTER recv; /* Received packets. */
76  STAT_COUNTER drop; /* Dropped packets. */
77  STAT_COUNTER chkerr; /* Checksum error. */
78  STAT_COUNTER lenerr; /* Invalid length error. */
79  STAT_COUNTER memerr; /* Out of memory error. */
80  STAT_COUNTER proterr; /* Protocol error. */
81  STAT_COUNTER rx_v1; /* Received v1 frames. */
82  STAT_COUNTER rx_group; /* Received group-specific queries. */
83  STAT_COUNTER rx_general; /* Received general queries. */
84  STAT_COUNTER rx_report; /* Received reports. */
85  STAT_COUNTER tx_join; /* Sent joins. */
86  STAT_COUNTER tx_leave; /* Sent leaves. */
87  STAT_COUNTER tx_report; /* Sent reports. */
88 };
89 
90 struct stats_mem {
91 #ifdef LWIP_DEBUG
92  const char *name;
93 #endif /* LWIP_DEBUG */
94  mem_size_t avail;
95  mem_size_t used;
96  mem_size_t max;
97  STAT_COUNTER err;
98  STAT_COUNTER illegal;
99 };
100 
101 struct stats_syselem {
102  STAT_COUNTER used;
103  STAT_COUNTER max;
104  STAT_COUNTER err;
105 };
106 
107 struct stats_sys {
108  struct stats_syselem sem;
109  struct stats_syselem mutex;
110  struct stats_syselem mbox;
111 };
112 
113 struct stats_ {
114 #if LINK_STATS
115  struct stats_proto link;
116 #endif
117 #if ETHARP_STATS
118  struct stats_proto etharp;
119 #endif
120 #if IPFRAG_STATS
121  struct stats_proto ip_frag;
122 #endif
123 #if IP_STATS
124  struct stats_proto ip;
125 #endif
126 #if ICMP_STATS
127  struct stats_proto icmp;
128 #endif
129 #if IGMP_STATS
130  struct stats_igmp igmp;
131 #endif
132 #if UDP_STATS
133  struct stats_proto udp;
134 #endif
135 #if TCP_STATS
136  struct stats_proto tcp;
137 #endif
138 #if MEM_STATS
139  struct stats_mem mem;
140 #endif
141 #if MEMP_STATS
142  struct stats_mem memp[MEMP_MAX];
143 #endif
144 #if SYS_STATS
145  struct stats_sys sys;
146 #endif
147 };
148 
149 extern struct stats_ lwip_stats;
150 
151 void stats_init(void);
152 
153 #define STATS_INC(x) ++lwip_stats.x
154 #define STATS_DEC(x) --lwip_stats.x
155 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
156  if (lwip_stats.x.max < lwip_stats.x.used) { \
157  lwip_stats.x.max = lwip_stats.x.used; \
158  } \
159  } while(0)
160 #else /* LWIP_STATS */
161 #define stats_init()
162 #define STATS_INC(x)
163 #define STATS_DEC(x)
164 #define STATS_INC_USED(x)
165 #endif /* LWIP_STATS */
166 
167 #if TCP_STATS
168 #define TCP_STATS_INC(x) STATS_INC(x)
169 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
170 #else
171 #define TCP_STATS_INC(x)
172 #define TCP_STATS_DISPLAY()
173 #endif
174 
175 #if UDP_STATS
176 #define UDP_STATS_INC(x) STATS_INC(x)
177 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
178 #else
179 #define UDP_STATS_INC(x)
180 #define UDP_STATS_DISPLAY()
181 #endif
182 
183 #if ICMP_STATS
184 #define ICMP_STATS_INC(x) STATS_INC(x)
185 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
186 #else
187 #define ICMP_STATS_INC(x)
188 #define ICMP_STATS_DISPLAY()
189 #endif
190 
191 #if IGMP_STATS
192 #define IGMP_STATS_INC(x) STATS_INC(x)
193 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
194 #else
195 #define IGMP_STATS_INC(x)
196 #define IGMP_STATS_DISPLAY()
197 #endif
198 
199 #if IP_STATS
200 #define IP_STATS_INC(x) STATS_INC(x)
201 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
202 #else
203 #define IP_STATS_INC(x)
204 #define IP_STATS_DISPLAY()
205 #endif
206 
207 #if IPFRAG_STATS
208 #define IPFRAG_STATS_INC(x) STATS_INC(x)
209 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
210 #else
211 #define IPFRAG_STATS_INC(x)
212 #define IPFRAG_STATS_DISPLAY()
213 #endif
214 
215 #if ETHARP_STATS
216 #define ETHARP_STATS_INC(x) STATS_INC(x)
217 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
218 #else
219 #define ETHARP_STATS_INC(x)
220 #define ETHARP_STATS_DISPLAY()
221 #endif
222 
223 #if LINK_STATS
224 #define LINK_STATS_INC(x) STATS_INC(x)
225 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
226 #else
227 #define LINK_STATS_INC(x)
228 #define LINK_STATS_DISPLAY()
229 #endif
230 
231 #if MEM_STATS
232 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
233 #define MEM_STATS_INC(x) STATS_INC(mem.x)
234 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
235 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
236 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
237 #else
238 #define MEM_STATS_AVAIL(x, y)
239 #define MEM_STATS_INC(x)
240 #define MEM_STATS_INC_USED(x, y)
241 #define MEM_STATS_DEC_USED(x, y)
242 #define MEM_STATS_DISPLAY()
243 #endif
244 
245 #if MEMP_STATS
246 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
247 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
248 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
249 #define MEMP_STATS_INC_USED(x, i) STATS_INC_USED(memp[i], 1)
250 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
251 #else
252 #define MEMP_STATS_AVAIL(x, i, y)
253 #define MEMP_STATS_INC(x, i)
254 #define MEMP_STATS_DEC(x, i)
255 #define MEMP_STATS_INC_USED(x, i)
256 #define MEMP_STATS_DISPLAY(i)
257 #endif
258 
259 #if SYS_STATS
260 #define SYS_STATS_INC(x) STATS_INC(sys.x)
261 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
262 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
263 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
264 #else
265 #define SYS_STATS_INC(x)
266 #define SYS_STATS_DEC(x)
267 #define SYS_STATS_INC_USED(x)
268 #define SYS_STATS_DISPLAY()
269 #endif
270 
271 /* Display of statistics */
272 #if LWIP_STATS_DISPLAY
273 void stats_display(void);
274 void stats_display_proto(struct stats_proto *proto, char *name);
275 void stats_display_igmp(struct stats_igmp *igmp);
276 void stats_display_mem(struct stats_mem *mem, char *name);
277 void stats_display_memp(struct stats_mem *mem, int index);
278 void stats_display_sys(struct stats_sys *sys);
279 #else /* LWIP_STATS_DISPLAY */
280 #define stats_display()
281 #define stats_display_proto(proto, name)
282 #define stats_display_igmp(igmp)
283 #define stats_display_mem(mem, name)
284 #define stats_display_memp(mem, index)
285 #define stats_display_sys(sys)
286 #endif /* LWIP_STATS_DISPLAY */
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* __LWIP_STATS_H__ */