1 /**
2  * @file
3  * Statistics module
4  *
5  */
6 
7 /*
8  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  *    this list of conditions and the following disclaimer in the documentation
18  *    and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  *
35  * Author: Adam Dunkels <adam@sics.se>
36  *
37  */
38 
39 #include "lwip/opt.h"
40 
41 #if LWIP_STATS /* don't build if not configured for use in lwipopts.h */
42 
43 #include "lwip/def.h"
44 #include "lwip/stats.h"
45 #include "lwip/mem.h"
46 #include "lwip/debug.h"
47 
48 #include <string.h>
49 
50 struct stats_ lwip_stats;
51 
52 void
stats_init(void)53 stats_init(void)
54 {
55 #ifdef LWIP_DEBUG
56 #if MEM_STATS
57   lwip_stats.mem.name = "MEM";
58 #endif /* MEM_STATS */
59 #endif /* LWIP_DEBUG */
60 }
61 
62 #if LWIP_STATS_DISPLAY
63 void
stats_display_proto(struct stats_proto * proto,const char * name)64 stats_display_proto(struct stats_proto *proto, const char *name)
65 {
66   LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
67   LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit));
68   LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv));
69   LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw));
70   LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop));
71   LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", proto->chkerr));
72   LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", proto->lenerr));
73   LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", proto->memerr));
74   LWIP_PLATFORM_DIAG(("rterr: %"STAT_COUNTER_F"\n\t", proto->rterr));
75   LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", proto->proterr));
76   LWIP_PLATFORM_DIAG(("opterr: %"STAT_COUNTER_F"\n\t", proto->opterr));
77   LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", proto->err));
78   LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit));
79 }
80 
81 #if IGMP_STATS || MLD6_STATS
82 void
stats_display_igmp(struct stats_igmp * igmp,const char * name)83 stats_display_igmp(struct stats_igmp *igmp, const char *name)
84 {
85   LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
86   LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", igmp->xmit));
87   LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", igmp->recv));
88   LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", igmp->drop));
89   LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr));
90   LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr));
91   LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", igmp->memerr));
92   LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", igmp->proterr));
93   LWIP_PLATFORM_DIAG(("rx_v1: %"STAT_COUNTER_F"\n\t", igmp->rx_v1));
94   LWIP_PLATFORM_DIAG(("rx_group: %"STAT_COUNTER_F"\n\t", igmp->rx_group));
95   LWIP_PLATFORM_DIAG(("rx_general: %"STAT_COUNTER_F"\n\t", igmp->rx_general));
96   LWIP_PLATFORM_DIAG(("rx_report: %"STAT_COUNTER_F"\n\t", igmp->rx_report));
97   LWIP_PLATFORM_DIAG(("tx_join: %"STAT_COUNTER_F"\n\t", igmp->tx_join));
98   LWIP_PLATFORM_DIAG(("tx_leave: %"STAT_COUNTER_F"\n\t", igmp->tx_leave));
99   LWIP_PLATFORM_DIAG(("tx_report: %"STAT_COUNTER_F"\n\t", igmp->tx_report));
100 }
101 #endif /* IGMP_STATS || MLD6_STATS */
102 
103 #if MEM_STATS || MEMP_STATS
104 void
stats_display_mem(struct stats_mem * mem,const char * name)105 stats_display_mem(struct stats_mem *mem, const char *name)
106 {
107   LWIP_PLATFORM_DIAG(("\nMEM %s\n\t", name));
108   LWIP_PLATFORM_DIAG(("avail: %"U32_F"\n\t", (u32_t)mem->avail));
109   LWIP_PLATFORM_DIAG(("used: %"U32_F"\n\t", (u32_t)mem->used));
110   LWIP_PLATFORM_DIAG(("max: %"U32_F"\n\t", (u32_t)mem->max));
111   LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
112 }
113 
114 #if MEMP_STATS
115 void
stats_display_memp(struct stats_mem * mem,int index)116 stats_display_memp(struct stats_mem *mem, int index)
117 {
118   if (index < MEMP_MAX) {
119     stats_display_mem(mem, mem->name);
120   }
121 }
122 #endif /* MEMP_STATS */
123 #endif /* MEM_STATS || MEMP_STATS */
124 
125 #if SYS_STATS
126 void
stats_display_sys(struct stats_sys * sys)127 stats_display_sys(struct stats_sys *sys)
128 {
129   LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
130   LWIP_PLATFORM_DIAG(("sem.used:  %"U32_F"\n\t", (u32_t)sys->sem.used));
131   LWIP_PLATFORM_DIAG(("sem.max:   %"U32_F"\n\t", (u32_t)sys->sem.max));
132   LWIP_PLATFORM_DIAG(("sem.err:   %"U32_F"\n\t", (u32_t)sys->sem.err));
133   LWIP_PLATFORM_DIAG(("mutex.used: %"U32_F"\n\t", (u32_t)sys->mutex.used));
134   LWIP_PLATFORM_DIAG(("mutex.max:  %"U32_F"\n\t", (u32_t)sys->mutex.max));
135   LWIP_PLATFORM_DIAG(("mutex.err:  %"U32_F"\n\t", (u32_t)sys->mutex.err));
136   LWIP_PLATFORM_DIAG(("mbox.used:  %"U32_F"\n\t", (u32_t)sys->mbox.used));
137   LWIP_PLATFORM_DIAG(("mbox.max:   %"U32_F"\n\t", (u32_t)sys->mbox.max));
138   LWIP_PLATFORM_DIAG(("mbox.err:   %"U32_F"\n\t", (u32_t)sys->mbox.err));
139 }
140 #endif /* SYS_STATS */
141 
142 void
stats_display(void)143 stats_display(void)
144 {
145   s16_t i;
146 
147   LINK_STATS_DISPLAY();
148   ETHARP_STATS_DISPLAY();
149   IPFRAG_STATS_DISPLAY();
150   IP6_FRAG_STATS_DISPLAY();
151   IP_STATS_DISPLAY();
152   ND6_STATS_DISPLAY();
153   IP6_STATS_DISPLAY();
154   IGMP_STATS_DISPLAY();
155   MLD6_STATS_DISPLAY();
156   ICMP_STATS_DISPLAY();
157   ICMP6_STATS_DISPLAY();
158   UDP_STATS_DISPLAY();
159   TCP_STATS_DISPLAY();
160   MEM_STATS_DISPLAY();
161   for (i = 0; i < MEMP_MAX; i++) {
162     MEMP_STATS_DISPLAY(i);
163   }
164   SYS_STATS_DISPLAY();
165 }
166 #endif /* LWIP_STATS_DISPLAY */
167 
168 #endif /* LWIP_STATS */
169 
170