Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/stats.h need to be fixed.

0001 /*
0002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
0003  * All rights reserved. 
0004  * 
0005  * Redistribution and use in source and binary forms, with or without modification, 
0006  * are permitted provided that the following conditions are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright notice,
0009  *    this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright notice,
0011  *    this list of conditions and the following disclaimer in the documentation
0012  *    and/or other materials provided with the distribution.
0013  * 3. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission. 
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
0017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
0018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
0019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
0020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
0021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
0024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
0025  * OF SUCH DAMAGE.
0026  *
0027  * This file is part of the lwIP TCP/IP stack.
0028  * 
0029  * Author: Adam Dunkels <adam@sics.se>
0030  *
0031  */
0032 #ifndef __LWIP_STATS_H__
0033 #define __LWIP_STATS_H__
0034 
0035 #include "lwip/opt.h"
0036 
0037 #include "lwip/mem.h"
0038 #include "lwip/memp.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043 
0044 #if LWIP_STATS
0045 
0046 #ifndef LWIP_STATS_LARGE
0047 #define LWIP_STATS_LARGE 0
0048 #endif
0049 
0050 #if LWIP_STATS_LARGE
0051 #define STAT_COUNTER     u32_t
0052 #define STAT_COUNTER_F   U32_F
0053 #else
0054 #define STAT_COUNTER     u16_t
0055 #define STAT_COUNTER_F   U16_F
0056 #endif 
0057 
0058 struct stats_proto {
0059   STAT_COUNTER xmit;             /* Transmitted packets. */
0060   STAT_COUNTER recv;             /* Received packets. */
0061   STAT_COUNTER fw;               /* Forwarded packets. */
0062   STAT_COUNTER drop;             /* Dropped packets. */
0063   STAT_COUNTER chkerr;           /* Checksum error. */
0064   STAT_COUNTER lenerr;           /* Invalid length error. */
0065   STAT_COUNTER memerr;           /* Out of memory error. */
0066   STAT_COUNTER rterr;            /* Routing error. */
0067   STAT_COUNTER proterr;          /* Protocol error. */
0068   STAT_COUNTER opterr;           /* Error in options. */
0069   STAT_COUNTER err;              /* Misc error. */
0070   STAT_COUNTER cachehit;
0071 };
0072 
0073 struct stats_igmp {
0074   STAT_COUNTER lenerr;           /* Invalid length error. */
0075   STAT_COUNTER chkerr;           /* Checksum error. */
0076   STAT_COUNTER v1_rxed;          /* */
0077   STAT_COUNTER join_sent;        /* */
0078   STAT_COUNTER leave_sent;       /* */
0079   STAT_COUNTER unicast_query;    /* */
0080   STAT_COUNTER report_sent;      /* */
0081   STAT_COUNTER report_rxed;      /* */
0082   STAT_COUNTER group_query_rxed; /* */
0083 };
0084 
0085 struct stats_mem {
0086   mem_size_t avail;
0087   mem_size_t used;
0088   mem_size_t max;
0089   STAT_COUNTER err;
0090   STAT_COUNTER illegal;
0091 };
0092 
0093 struct stats_syselem {
0094   STAT_COUNTER used;
0095   STAT_COUNTER max;
0096   STAT_COUNTER err;
0097 };
0098 
0099 struct stats_sys {
0100   struct stats_syselem sem;
0101   struct stats_syselem mbox;
0102 };
0103 
0104 struct stats_ {
0105 #if LINK_STATS
0106   struct stats_proto link;
0107 #endif
0108 #if ETHARP_STATS
0109   struct stats_proto etharp;
0110 #endif
0111 #if IPFRAG_STATS
0112   struct stats_proto ip_frag;
0113 #endif
0114 #if IP_STATS
0115   struct stats_proto ip;
0116 #endif
0117 #if ICMP_STATS
0118   struct stats_proto icmp;
0119 #endif
0120 #if IGMP_STATS
0121   struct stats_igmp igmp;
0122 #endif
0123 #if UDP_STATS
0124   struct stats_proto udp;
0125 #endif
0126 #if TCP_STATS
0127   struct stats_proto tcp;
0128 #endif
0129 #if MEM_STATS
0130   struct stats_mem mem;
0131 #endif
0132 #if MEMP_STATS
0133   struct stats_mem memp[MEMP_MAX];
0134 #endif
0135 #if SYS_STATS
0136   struct stats_sys sys;
0137 #endif
0138 };
0139 
0140 extern struct stats_ lwip_stats;
0141 
0142 #define stats_init() /* Compatibility define, not init needed. */
0143 
0144 #define STATS_INC(x) ++lwip_stats.x
0145 #define STATS_DEC(x) --lwip_stats.x
0146 #else
0147 #define stats_init()
0148 #define STATS_INC(x)
0149 #define STATS_DEC(x)
0150 #endif /* LWIP_STATS */
0151 
0152 #if TCP_STATS
0153 #define TCP_STATS_INC(x) STATS_INC(x)
0154 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
0155 #else
0156 #define TCP_STATS_INC(x)
0157 #define TCP_STATS_DISPLAY()
0158 #endif
0159 
0160 #if UDP_STATS
0161 #define UDP_STATS_INC(x) STATS_INC(x)
0162 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
0163 #else
0164 #define UDP_STATS_INC(x)
0165 #define UDP_STATS_DISPLAY()
0166 #endif
0167 
0168 #if ICMP_STATS
0169 #define ICMP_STATS_INC(x) STATS_INC(x)
0170 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
0171 #else
0172 #define ICMP_STATS_INC(x)
0173 #define ICMP_STATS_DISPLAY()
0174 #endif
0175 
0176 #if IGMP_STATS
0177 #define IGMP_STATS_INC(x) STATS_INC(x)
0178 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
0179 #else
0180 #define IGMP_STATS_INC(x)
0181 #define IGMP_STATS_DISPLAY()
0182 #endif
0183 
0184 #if IP_STATS
0185 #define IP_STATS_INC(x) STATS_INC(x)
0186 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
0187 #else
0188 #define IP_STATS_INC(x)
0189 #define IP_STATS_DISPLAY()
0190 #endif
0191 
0192 #if IPFRAG_STATS
0193 #define IPFRAG_STATS_INC(x) STATS_INC(x)
0194 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
0195 #else
0196 #define IPFRAG_STATS_INC(x)
0197 #define IPFRAG_STATS_DISPLAY()
0198 #endif
0199 
0200 #if ETHARP_STATS
0201 #define ETHARP_STATS_INC(x) STATS_INC(x)
0202 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
0203 #else
0204 #define ETHARP_STATS_INC(x)
0205 #define ETHARP_STATS_DISPLAY()
0206 #endif
0207 
0208 #if LINK_STATS
0209 #define LINK_STATS_INC(x) STATS_INC(x)
0210 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
0211 #else
0212 #define LINK_STATS_INC(x)
0213 #define LINK_STATS_DISPLAY()
0214 #endif
0215 
0216 #if MEM_STATS
0217 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
0218 #define MEM_STATS_INC(x) STATS_INC(mem.x)
0219 #define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
0220                                     if (lwip_stats.mem.max < lwip_stats.mem.used) { \
0221                                         lwip_stats.mem.max = lwip_stats.mem.used; \
0222                                     } \
0223                                  } while(0)
0224 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
0225 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
0226 #else
0227 #define MEM_STATS_AVAIL(x, y)
0228 #define MEM_STATS_INC(x)
0229 #define MEM_STATS_INC_USED(x, y)
0230 #define MEM_STATS_DEC_USED(x, y)
0231 #define MEM_STATS_DISPLAY()
0232 #endif
0233 
0234 #if MEMP_STATS
0235 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
0236 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
0237 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
0238 #define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
0239                                     if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \
0240                                         lwip_stats.memp[i].max = lwip_stats.memp[i].used; \
0241                                     } \
0242                                  } while(0)
0243 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
0244 #else
0245 #define MEMP_STATS_AVAIL(x, i, y)
0246 #define MEMP_STATS_INC(x, i)
0247 #define MEMP_STATS_DEC(x, i)
0248 #define MEMP_STATS_INC_USED(x, i)
0249 #define MEMP_STATS_DISPLAY(i)
0250 #endif
0251 
0252 #if SYS_STATS
0253 #define SYS_STATS_INC(x) STATS_INC(sys.x)
0254 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
0255 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
0256 #else
0257 #define SYS_STATS_INC(x)
0258 #define SYS_STATS_DEC(x)
0259 #define SYS_STATS_DISPLAY()
0260 #endif
0261 
0262 /* Display of statistics */
0263 #if LWIP_STATS_DISPLAY
0264 void stats_display(void);
0265 void stats_display_proto(struct stats_proto *proto, char *name);
0266 void stats_display_igmp(struct stats_igmp *igmp);
0267 void stats_display_mem(struct stats_mem *mem, char *name);
0268 void stats_display_memp(struct stats_mem *mem, int index);
0269 void stats_display_sys(struct stats_sys *sys);
0270 #else
0271 #define stats_display()
0272 #define stats_display_proto(proto, name)
0273 #define stats_display_igmp(igmp)
0274 #define stats_display_mem(mem, name)
0275 #define stats_display_memp(mem, index)
0276 #define stats_display_sys(sys)
0277 #endif /* LWIP_STATS_DISPLAY */
0278 
0279 #ifdef __cplusplus
0280 }
0281 #endif
0282 
0283 #endif /* __LWIP_STATS_H__ */