A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stats.h Source File

stats.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_STATS_H__
00033 #define __LWIP_STATS_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #include "lwip/mem.h"
00038 #include "lwip/memp.h"
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 #if LWIP_STATS
00045 
00046 #ifndef LWIP_STATS_LARGE
00047 #define LWIP_STATS_LARGE 0
00048 #endif
00049 
00050 #if LWIP_STATS_LARGE
00051 #define STAT_COUNTER     u32_t
00052 #define STAT_COUNTER_F   U32_F
00053 #else
00054 #define STAT_COUNTER     u16_t
00055 #define STAT_COUNTER_F   U16_F
00056 #endif 
00057 
00058 struct stats_proto {
00059   STAT_COUNTER xmit;             /* Transmitted packets. */
00060   STAT_COUNTER recv;             /* Received packets. */
00061   STAT_COUNTER fw;               /* Forwarded packets. */
00062   STAT_COUNTER drop;             /* Dropped packets. */
00063   STAT_COUNTER chkerr;           /* Checksum error. */
00064   STAT_COUNTER lenerr;           /* Invalid length error. */
00065   STAT_COUNTER memerr;           /* Out of memory error. */
00066   STAT_COUNTER rterr;            /* Routing error. */
00067   STAT_COUNTER proterr;          /* Protocol error. */
00068   STAT_COUNTER opterr;           /* Error in options. */
00069   STAT_COUNTER err;              /* Misc error. */
00070   STAT_COUNTER cachehit;
00071 };
00072 
00073 struct stats_igmp {
00074   STAT_COUNTER lenerr;           /* Invalid length error. */
00075   STAT_COUNTER chkerr;           /* Checksum error. */
00076   STAT_COUNTER v1_rxed;          /* */
00077   STAT_COUNTER join_sent;        /* */
00078   STAT_COUNTER leave_sent;       /* */
00079   STAT_COUNTER unicast_query;    /* */
00080   STAT_COUNTER report_sent;      /* */
00081   STAT_COUNTER report_rxed;      /* */
00082   STAT_COUNTER group_query_rxed; /* */
00083 };
00084 
00085 struct stats_mem {
00086   mem_size_t avail;
00087   mem_size_t used;
00088   mem_size_t max;
00089   STAT_COUNTER err;
00090   STAT_COUNTER illegal;
00091 };
00092 
00093 struct stats_syselem {
00094   STAT_COUNTER used;
00095   STAT_COUNTER max;
00096   STAT_COUNTER err;
00097 };
00098 
00099 struct stats_sys {
00100   struct stats_syselem sem;
00101   struct stats_syselem mbox;
00102 };
00103 
00104 struct stats_ {
00105 #if LINK_STATS
00106   struct stats_proto link;
00107 #endif
00108 #if ETHARP_STATS
00109   struct stats_proto etharp;
00110 #endif
00111 #if IPFRAG_STATS
00112   struct stats_proto ip_frag;
00113 #endif
00114 #if IP_STATS
00115   struct stats_proto ip;
00116 #endif
00117 #if ICMP_STATS
00118   struct stats_proto icmp;
00119 #endif
00120 #if IGMP_STATS
00121   struct stats_igmp igmp;
00122 #endif
00123 #if UDP_STATS
00124   struct stats_proto udp;
00125 #endif
00126 #if TCP_STATS
00127   struct stats_proto tcp;
00128 #endif
00129 #if MEM_STATS
00130   struct stats_mem mem;
00131 #endif
00132 #if MEMP_STATS
00133   struct stats_mem memp[MEMP_MAX];
00134 #endif
00135 #if SYS_STATS
00136   struct stats_sys sys;
00137 #endif
00138 };
00139 
00140 extern struct stats_ lwip_stats;
00141 
00142 #define stats_init() /* Compatibility define, not init needed. */
00143 
00144 #define STATS_INC(x) ++lwip_stats.x
00145 #define STATS_DEC(x) --lwip_stats.x
00146 #else
00147 #define stats_init()
00148 #define STATS_INC(x)
00149 #define STATS_DEC(x)
00150 #endif /* LWIP_STATS */
00151 
00152 #if TCP_STATS
00153 #define TCP_STATS_INC(x) STATS_INC(x)
00154 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
00155 #else
00156 #define TCP_STATS_INC(x)
00157 #define TCP_STATS_DISPLAY()
00158 #endif
00159 
00160 #if UDP_STATS
00161 #define UDP_STATS_INC(x) STATS_INC(x)
00162 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
00163 #else
00164 #define UDP_STATS_INC(x)
00165 #define UDP_STATS_DISPLAY()
00166 #endif
00167 
00168 #if ICMP_STATS
00169 #define ICMP_STATS_INC(x) STATS_INC(x)
00170 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
00171 #else
00172 #define ICMP_STATS_INC(x)
00173 #define ICMP_STATS_DISPLAY()
00174 #endif
00175 
00176 #if IGMP_STATS
00177 #define IGMP_STATS_INC(x) STATS_INC(x)
00178 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
00179 #else
00180 #define IGMP_STATS_INC(x)
00181 #define IGMP_STATS_DISPLAY()
00182 #endif
00183 
00184 #if IP_STATS
00185 #define IP_STATS_INC(x) STATS_INC(x)
00186 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
00187 #else
00188 #define IP_STATS_INC(x)
00189 #define IP_STATS_DISPLAY()
00190 #endif
00191 
00192 #if IPFRAG_STATS
00193 #define IPFRAG_STATS_INC(x) STATS_INC(x)
00194 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
00195 #else
00196 #define IPFRAG_STATS_INC(x)
00197 #define IPFRAG_STATS_DISPLAY()
00198 #endif
00199 
00200 #if ETHARP_STATS
00201 #define ETHARP_STATS_INC(x) STATS_INC(x)
00202 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
00203 #else
00204 #define ETHARP_STATS_INC(x)
00205 #define ETHARP_STATS_DISPLAY()
00206 #endif
00207 
00208 #if LINK_STATS
00209 #define LINK_STATS_INC(x) STATS_INC(x)
00210 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
00211 #else
00212 #define LINK_STATS_INC(x)
00213 #define LINK_STATS_DISPLAY()
00214 #endif
00215 
00216 #if MEM_STATS
00217 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
00218 #define MEM_STATS_INC(x) STATS_INC(mem.x)
00219 #define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
00220                                     if (lwip_stats.mem.max < lwip_stats.mem.used) { \
00221                                         lwip_stats.mem.max = lwip_stats.mem.used; \
00222                                     } \
00223                                  } while(0)
00224 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
00225 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
00226 #else
00227 #define MEM_STATS_AVAIL(x, y)
00228 #define MEM_STATS_INC(x)
00229 #define MEM_STATS_INC_USED(x, y)
00230 #define MEM_STATS_DEC_USED(x, y)
00231 #define MEM_STATS_DISPLAY()
00232 #endif
00233 
00234 #if MEMP_STATS
00235 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
00236 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
00237 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
00238 #define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
00239                                     if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \
00240                                         lwip_stats.memp[i].max = lwip_stats.memp[i].used; \
00241                                     } \
00242                                  } while(0)
00243 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
00244 #else
00245 #define MEMP_STATS_AVAIL(x, i, y)
00246 #define MEMP_STATS_INC(x, i)
00247 #define MEMP_STATS_DEC(x, i)
00248 #define MEMP_STATS_INC_USED(x, i)
00249 #define MEMP_STATS_DISPLAY(i)
00250 #endif
00251 
00252 #if SYS_STATS
00253 #define SYS_STATS_INC(x) STATS_INC(sys.x)
00254 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
00255 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
00256 #else
00257 #define SYS_STATS_INC(x)
00258 #define SYS_STATS_DEC(x)
00259 #define SYS_STATS_DISPLAY()
00260 #endif
00261 
00262 /* Display of statistics */
00263 #if LWIP_STATS_DISPLAY
00264 void stats_display(void);
00265 void stats_display_proto(struct stats_proto *proto, char *name);
00266 void stats_display_igmp(struct stats_igmp *igmp);
00267 void stats_display_mem(struct stats_mem *mem, char *name);
00268 void stats_display_memp(struct stats_mem *mem, int index);
00269 void stats_display_sys(struct stats_sys *sys);
00270 #else
00271 #define stats_display()
00272 #define stats_display_proto(proto, name)
00273 #define stats_display_igmp(igmp)
00274 #define stats_display_mem(mem, name)
00275 #define stats_display_memp(mem, index)
00276 #define stats_display_sys(sys)
00277 #endif /* LWIP_STATS_DISPLAY */
00278 
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282 
00283 #endif /* __LWIP_STATS_H__ */