The Pedigree Project  0.1
stats.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
25 /*
26  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without modification,
30  * are permitted provided that the following conditions are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright notice,
33  * this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright notice,
35  * this list of conditions and the following disclaimer in the documentation
36  * and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote products
38  * derived from this software without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49  * OF SUCH DAMAGE.
50  *
51  * This file is part of the lwIP TCP/IP stack.
52  *
53  * Author: Adam Dunkels <adam@sics.se>
54  *
55  */
56 #ifndef LWIP_HDR_STATS_H
57 #define LWIP_HDR_STATS_H
58 
59 #include "lwip/opt.h"
60 
61 #include "lwip/mem.h"
62 #include "lwip/memp.h"
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 #if LWIP_STATS
69 
70 #ifndef LWIP_STATS_LARGE
71 #define LWIP_STATS_LARGE 0
72 #endif
73 
74 #if LWIP_STATS_LARGE
75 #define STAT_COUNTER u32_t
76 #define STAT_COUNTER_F U32_F
77 #else
78 #define STAT_COUNTER u16_t
79 #define STAT_COUNTER_F U16_F
80 #endif
81 
83 struct stats_proto {
84  STAT_COUNTER xmit; /* Transmitted packets. */
85  STAT_COUNTER recv; /* Received packets. */
86  STAT_COUNTER fw; /* Forwarded packets. */
87  STAT_COUNTER drop; /* Dropped packets. */
88  STAT_COUNTER chkerr; /* Checksum error. */
89  STAT_COUNTER lenerr; /* Invalid length error. */
90  STAT_COUNTER memerr; /* Out of memory error. */
91  STAT_COUNTER rterr; /* Routing error. */
92  STAT_COUNTER proterr; /* Protocol error. */
93  STAT_COUNTER opterr; /* Error in options. */
94  STAT_COUNTER err; /* Misc error. */
95  STAT_COUNTER cachehit;
96 };
97 
99 struct stats_igmp {
100  STAT_COUNTER xmit; /* Transmitted packets. */
101  STAT_COUNTER recv; /* Received packets. */
102  STAT_COUNTER drop; /* Dropped packets. */
103  STAT_COUNTER chkerr; /* Checksum error. */
104  STAT_COUNTER lenerr; /* Invalid length error. */
105  STAT_COUNTER memerr; /* Out of memory error. */
106  STAT_COUNTER proterr; /* Protocol error. */
107  STAT_COUNTER rx_v1; /* Received v1 frames. */
108  STAT_COUNTER rx_group; /* Received group-specific queries. */
109  STAT_COUNTER rx_general; /* Received general queries. */
110  STAT_COUNTER rx_report; /* Received reports. */
111  STAT_COUNTER tx_join; /* Sent joins. */
112  STAT_COUNTER tx_leave; /* Sent leaves. */
113  STAT_COUNTER tx_report; /* Sent reports. */
114 };
115 
117 struct stats_mem {
118 #if defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY
119  const char *name;
120 #endif /* defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY */
121  STAT_COUNTER err;
122  mem_size_t avail;
123  mem_size_t used;
124  mem_size_t max;
125  STAT_COUNTER illegal;
126 };
127 
129 struct stats_syselem {
130  STAT_COUNTER used;
131  STAT_COUNTER max;
132  STAT_COUNTER err;
133 };
134 
136 struct stats_sys {
137  struct stats_syselem sem;
138  struct stats_syselem mutex;
139  struct stats_syselem mbox;
140 };
141 
143 struct stats_mib2 {
144  /* IP */
145  u32_t ipinhdrerrors;
146  u32_t ipinaddrerrors;
147  u32_t ipinunknownprotos;
148  u32_t ipindiscards;
149  u32_t ipindelivers;
150  u32_t ipoutrequests;
151  u32_t ipoutdiscards;
152  u32_t ipoutnoroutes;
153  u32_t ipreasmoks;
154  u32_t ipreasmfails;
155  u32_t ipfragoks;
156  u32_t ipfragfails;
157  u32_t ipfragcreates;
158  u32_t ipreasmreqds;
159  u32_t ipforwdatagrams;
160  u32_t ipinreceives;
161 
162  /* TCP */
163  u32_t tcpactiveopens;
164  u32_t tcppassiveopens;
165  u32_t tcpattemptfails;
166  u32_t tcpestabresets;
167  u32_t tcpoutsegs;
168  u32_t tcpretranssegs;
169  u32_t tcpinsegs;
170  u32_t tcpinerrs;
171  u32_t tcpoutrsts;
172 
173  /* UDP */
174  u32_t udpindatagrams;
175  u32_t udpnoports;
176  u32_t udpinerrors;
177  u32_t udpoutdatagrams;
178 
179  /* ICMP */
180  u32_t icmpinmsgs;
181  u32_t icmpinerrors;
182  u32_t icmpindestunreachs;
183  u32_t icmpintimeexcds;
184  u32_t icmpinparmprobs;
185  u32_t icmpinsrcquenchs;
186  u32_t icmpinredirects;
187  u32_t icmpinechos;
188  u32_t icmpinechoreps;
189  u32_t icmpintimestamps;
190  u32_t icmpintimestampreps;
191  u32_t icmpinaddrmasks;
192  u32_t icmpinaddrmaskreps;
193  u32_t icmpoutmsgs;
194  u32_t icmpouterrors;
195  u32_t icmpoutdestunreachs;
196  u32_t icmpouttimeexcds;
197  u32_t icmpoutechos; /* can be incremented by user application ('ping') */
198  u32_t icmpoutechoreps;
199 };
200 
205 struct stats_mib2_netif_ctrs {
207  u32_t ifinoctets;
210  u32_t ifinucastpkts;
213  u32_t ifinnucastpkts;
217  u32_t ifindiscards;
222  u32_t ifinerrors;
229  u32_t ifinunknownprotos;
231  u32_t ifoutoctets;
235  u32_t ifoutucastpkts;
239  u32_t ifoutnucastpkts;
243  u32_t ifoutdiscards;
247  u32_t ifouterrors;
248 };
249 
251 struct stats_ {
252 #if LINK_STATS
253 
254  struct stats_proto link;
255 #endif
256 #if ETHARP_STATS
257 
258  struct stats_proto etharp;
259 #endif
260 #if IPFRAG_STATS
261 
262  struct stats_proto ip_frag;
263 #endif
264 #if IP_STATS
265 
266  struct stats_proto ip;
267 #endif
268 #if ICMP_STATS
269 
270  struct stats_proto icmp;
271 #endif
272 #if IGMP_STATS
273 
274  struct stats_igmp igmp;
275 #endif
276 #if UDP_STATS
277 
278  struct stats_proto udp;
279 #endif
280 #if TCP_STATS
281 
282  struct stats_proto tcp;
283 #endif
284 #if MEM_STATS
285 
286  struct stats_mem mem;
287 #endif
288 #if MEMP_STATS
289 
290  struct stats_mem *memp[MEMP_MAX];
291 #endif
292 #if SYS_STATS
293 
294  struct stats_sys sys;
295 #endif
296 #if IP6_STATS
297 
298  struct stats_proto ip6;
299 #endif
300 #if ICMP6_STATS
301 
302  struct stats_proto icmp6;
303 #endif
304 #if IP6_FRAG_STATS
305 
306  struct stats_proto ip6_frag;
307 #endif
308 #if MLD6_STATS
309 
310  struct stats_igmp mld6;
311 #endif
312 #if ND6_STATS
313 
314  struct stats_proto nd6;
315 #endif
316 #if MIB2_STATS
317 
318  struct stats_mib2 mib2;
319 #endif
320 };
321 
323 extern struct stats_ lwip_stats;
324 
326 void stats_init(void);
327 
328 #define STATS_INC(x) ++lwip_stats.x
329 #define STATS_DEC(x) --lwip_stats.x
330 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
331  if (lwip_stats.x.max < lwip_stats.x.used) { \
332  lwip_stats.x.max = lwip_stats.x.used; \
333  } \
334  } while(0)
335 #define STATS_GET(x) lwip_stats.x
336 #else /* LWIP_STATS */
337 #define stats_init()
338 #define STATS_INC(x)
339 #define STATS_DEC(x)
340 #define STATS_INC_USED(x)
341 #endif /* LWIP_STATS */
342 
343 #if TCP_STATS
344 #define TCP_STATS_INC(x) STATS_INC(x)
345 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
346 #else
347 #define TCP_STATS_INC(x)
348 #define TCP_STATS_DISPLAY()
349 #endif
350 
351 #if UDP_STATS
352 #define UDP_STATS_INC(x) STATS_INC(x)
353 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
354 #else
355 #define UDP_STATS_INC(x)
356 #define UDP_STATS_DISPLAY()
357 #endif
358 
359 #if ICMP_STATS
360 #define ICMP_STATS_INC(x) STATS_INC(x)
361 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
362 #else
363 #define ICMP_STATS_INC(x)
364 #define ICMP_STATS_DISPLAY()
365 #endif
366 
367 #if IGMP_STATS
368 #define IGMP_STATS_INC(x) STATS_INC(x)
369 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP")
370 #else
371 #define IGMP_STATS_INC(x)
372 #define IGMP_STATS_DISPLAY()
373 #endif
374 
375 #if IP_STATS
376 #define IP_STATS_INC(x) STATS_INC(x)
377 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
378 #else
379 #define IP_STATS_INC(x)
380 #define IP_STATS_DISPLAY()
381 #endif
382 
383 #if IPFRAG_STATS
384 #define IPFRAG_STATS_INC(x) STATS_INC(x)
385 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
386 #else
387 #define IPFRAG_STATS_INC(x)
388 #define IPFRAG_STATS_DISPLAY()
389 #endif
390 
391 #if ETHARP_STATS
392 #define ETHARP_STATS_INC(x) STATS_INC(x)
393 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
394 #else
395 #define ETHARP_STATS_INC(x)
396 #define ETHARP_STATS_DISPLAY()
397 #endif
398 
399 #if LINK_STATS
400 #define LINK_STATS_INC(x) STATS_INC(x)
401 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
402 #else
403 #define LINK_STATS_INC(x)
404 #define LINK_STATS_DISPLAY()
405 #endif
406 
407 #if MEM_STATS
408 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
409 #define MEM_STATS_INC(x) STATS_INC(mem.x)
410 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
411 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
412 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
413 #else
414 #define MEM_STATS_AVAIL(x, y)
415 #define MEM_STATS_INC(x)
416 #define MEM_STATS_INC_USED(x, y)
417 #define MEM_STATS_DEC_USED(x, y)
418 #define MEM_STATS_DISPLAY()
419 #endif
420 
421  #if MEMP_STATS
422 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i]->x)
423 #define MEMP_STATS_DISPLAY(i) stats_display_memp(lwip_stats.memp[i], i)
424 #define MEMP_STATS_GET(x, i) STATS_GET(memp[i]->x)
425  #else
426 #define MEMP_STATS_DEC(x, i)
427 #define MEMP_STATS_DISPLAY(i)
428 #define MEMP_STATS_GET(x, i) 0
429 #endif
430 
431 #if SYS_STATS
432 #define SYS_STATS_INC(x) STATS_INC(sys.x)
433 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
434 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
435 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
436 #else
437 #define SYS_STATS_INC(x)
438 #define SYS_STATS_DEC(x)
439 #define SYS_STATS_INC_USED(x)
440 #define SYS_STATS_DISPLAY()
441 #endif
442 
443 #if IP6_STATS
444 #define IP6_STATS_INC(x) STATS_INC(x)
445 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6")
446 #else
447 #define IP6_STATS_INC(x)
448 #define IP6_STATS_DISPLAY()
449 #endif
450 
451 #if ICMP6_STATS
452 #define ICMP6_STATS_INC(x) STATS_INC(x)
453 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6")
454 #else
455 #define ICMP6_STATS_INC(x)
456 #define ICMP6_STATS_DISPLAY()
457 #endif
458 
459 #if IP6_FRAG_STATS
460 #define IP6_FRAG_STATS_INC(x) STATS_INC(x)
461 #define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG")
462 #else
463 #define IP6_FRAG_STATS_INC(x)
464 #define IP6_FRAG_STATS_DISPLAY()
465 #endif
466 
467 #if MLD6_STATS
468 #define MLD6_STATS_INC(x) STATS_INC(x)
469 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1")
470 #else
471 #define MLD6_STATS_INC(x)
472 #define MLD6_STATS_DISPLAY()
473 #endif
474 
475 #if ND6_STATS
476 #define ND6_STATS_INC(x) STATS_INC(x)
477 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND")
478 #else
479 #define ND6_STATS_INC(x)
480 #define ND6_STATS_DISPLAY()
481 #endif
482 
483 #if MIB2_STATS
484 #define MIB2_STATS_INC(x) STATS_INC(x)
485 #else
486 #define MIB2_STATS_INC(x)
487 #endif
488 
489 /* Display of statistics */
490 #if LWIP_STATS_DISPLAY
491 void stats_display(void);
492 void stats_display_proto(struct stats_proto *proto, const char *name);
493 void stats_display_igmp(struct stats_igmp *igmp, const char *name);
494 void stats_display_mem(struct stats_mem *mem, const char *name);
495 void stats_display_memp(struct stats_mem *mem, int index);
496 void stats_display_sys(struct stats_sys *sys);
497 #else /* LWIP_STATS_DISPLAY */
498 #define stats_display()
499 #define stats_display_proto(proto, name)
500 #define stats_display_igmp(igmp, name)
501 #define stats_display_mem(mem, name)
502 #define stats_display_memp(mem, index)
503 #define stats_display_sys(sys)
504 #endif /* LWIP_STATS_DISPLAY */
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 #endif /* LWIP_HDR_STATS_H */
Definition: mem.c:283