Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stats.h
00001 /** 00002 * @file 00003 * Statistics API (to be used from TCPIP thread) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 #ifndef LWIP_HDR_STATS_H 00038 #define LWIP_HDR_STATS_H 00039 00040 #include "lwip/opt.h" 00041 00042 #include "lwip/mem.h" 00043 #include "lwip/memp.h" 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 #if LWIP_STATS 00050 00051 #ifndef LWIP_STATS_LARGE 00052 #define LWIP_STATS_LARGE 0 00053 #endif 00054 00055 #if LWIP_STATS_LARGE 00056 #define STAT_COUNTER u32_t 00057 #define STAT_COUNTER_F U32_F 00058 #else 00059 #define STAT_COUNTER u16_t 00060 #define STAT_COUNTER_F U16_F 00061 #endif 00062 00063 /** Protocol related stats */ 00064 struct stats_proto { 00065 STAT_COUNTER xmit; /* Transmitted packets. */ 00066 STAT_COUNTER recv; /* Received packets. */ 00067 STAT_COUNTER fw; /* Forwarded packets. */ 00068 STAT_COUNTER drop; /* Dropped packets. */ 00069 STAT_COUNTER chkerr; /* Checksum error. */ 00070 STAT_COUNTER lenerr; /* Invalid length error. */ 00071 STAT_COUNTER memerr; /* Out of memory error. */ 00072 STAT_COUNTER rterr; /* Routing error. */ 00073 STAT_COUNTER proterr; /* Protocol error. */ 00074 STAT_COUNTER opterr; /* Error in options. */ 00075 STAT_COUNTER err; /* Misc error. */ 00076 STAT_COUNTER cachehit; 00077 }; 00078 00079 /** IGMP stats */ 00080 struct stats_igmp { 00081 STAT_COUNTER xmit; /* Transmitted packets. */ 00082 STAT_COUNTER recv; /* Received packets. */ 00083 STAT_COUNTER drop; /* Dropped packets. */ 00084 STAT_COUNTER chkerr; /* Checksum error. */ 00085 STAT_COUNTER lenerr; /* Invalid length error. */ 00086 STAT_COUNTER memerr; /* Out of memory error. */ 00087 STAT_COUNTER proterr; /* Protocol error. */ 00088 STAT_COUNTER rx_v1; /* Received v1 frames. */ 00089 STAT_COUNTER rx_group; /* Received group-specific queries. */ 00090 STAT_COUNTER rx_general; /* Received general queries. */ 00091 STAT_COUNTER rx_report; /* Received reports. */ 00092 STAT_COUNTER tx_join; /* Sent joins. */ 00093 STAT_COUNTER tx_leave; /* Sent leaves. */ 00094 STAT_COUNTER tx_report; /* Sent reports. */ 00095 }; 00096 00097 /** Memory stats */ 00098 struct stats_mem { 00099 #if defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY 00100 const char *name; 00101 #endif /* defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY */ 00102 STAT_COUNTER err; 00103 mem_size_t avail; 00104 mem_size_t used; 00105 mem_size_t max; 00106 STAT_COUNTER illegal; 00107 }; 00108 00109 /** System element stats */ 00110 struct stats_syselem { 00111 STAT_COUNTER used; 00112 STAT_COUNTER max; 00113 STAT_COUNTER err; 00114 }; 00115 00116 /** System stats */ 00117 struct stats_sys { 00118 struct stats_syselem sem; 00119 struct stats_syselem mutex; 00120 struct stats_syselem mbox; 00121 }; 00122 00123 /** SNMP MIB2 stats */ 00124 struct stats_mib2 { 00125 /* IP */ 00126 u32_t ipinhdrerrors; 00127 u32_t ipinaddrerrors; 00128 u32_t ipinunknownprotos; 00129 u32_t ipindiscards; 00130 u32_t ipindelivers; 00131 u32_t ipoutrequests; 00132 u32_t ipoutdiscards; 00133 u32_t ipoutnoroutes; 00134 u32_t ipreasmoks; 00135 u32_t ipreasmfails; 00136 u32_t ipfragoks; 00137 u32_t ipfragfails; 00138 u32_t ipfragcreates; 00139 u32_t ipreasmreqds; 00140 u32_t ipforwdatagrams; 00141 u32_t ipinreceives; 00142 00143 /* TCP */ 00144 u32_t tcpactiveopens; 00145 u32_t tcppassiveopens; 00146 u32_t tcpattemptfails; 00147 u32_t tcpestabresets; 00148 u32_t tcpoutsegs; 00149 u32_t tcpretranssegs; 00150 u32_t tcpinsegs; 00151 u32_t tcpinerrs; 00152 u32_t tcpoutrsts; 00153 00154 /* UDP */ 00155 u32_t udpindatagrams; 00156 u32_t udpnoports; 00157 u32_t udpinerrors; 00158 u32_t udpoutdatagrams; 00159 00160 /* ICMP */ 00161 u32_t icmpinmsgs; 00162 u32_t icmpinerrors; 00163 u32_t icmpindestunreachs; 00164 u32_t icmpintimeexcds; 00165 u32_t icmpinparmprobs; 00166 u32_t icmpinsrcquenchs; 00167 u32_t icmpinredirects; 00168 u32_t icmpinechos; 00169 u32_t icmpinechoreps; 00170 u32_t icmpintimestamps; 00171 u32_t icmpintimestampreps; 00172 u32_t icmpinaddrmasks; 00173 u32_t icmpinaddrmaskreps; 00174 u32_t icmpoutmsgs; 00175 u32_t icmpouterrors; 00176 u32_t icmpoutdestunreachs; 00177 u32_t icmpouttimeexcds; 00178 u32_t icmpoutechos; /* can be incremented by user application ('ping') */ 00179 u32_t icmpoutechoreps; 00180 }; 00181 00182 /** 00183 * @ingroup netif_mib2 00184 * SNMP MIB2 interface stats 00185 */ 00186 struct stats_mib2_netif_ctrs { 00187 /** The total number of octets received on the interface, including framing characters */ 00188 u32_t ifinoctets; 00189 /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were 00190 * not addressed to a multicast or broadcast address at this sub-layer */ 00191 u32_t ifinucastpkts; 00192 /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were 00193 * addressed to a multicast or broadcast address at this sub-layer */ 00194 u32_t ifinnucastpkts; 00195 /** The number of inbound packets which were chosen to be discarded even though no errors had 00196 * been detected to prevent their being deliverable to a higher-layer protocol. One possible 00197 * reason for discarding such a packet could be to free up buffer space */ 00198 u32_t ifindiscards; 00199 /** For packet-oriented interfaces, the number of inbound packets that contained errors 00200 * preventing them from being deliverable to a higher-layer protocol. For character- 00201 * oriented or fixed-length interfaces, the number of inbound transmission units that 00202 * contained errors preventing them from being deliverable to a higher-layer protocol. */ 00203 u32_t ifinerrors; 00204 /** For packet-oriented interfaces, the number of packets received via the interface which 00205 * were discarded because of an unknown or unsupported protocol. For character-oriented 00206 * or fixed-length interfaces that support protocol multiplexing the number of transmission 00207 * units received via the interface which were discarded because of an unknown or unsupported 00208 * protocol. For any interface that does not support protocol multiplexing, this counter will 00209 * always be 0 */ 00210 u32_t ifinunknownprotos; 00211 /** The total number of octets transmitted out of the interface, including framing characters. */ 00212 u32_t ifoutoctets; 00213 /** The total number of packets that higher-level protocols requested be transmitted, and 00214 * which were not addressed to a multicast or broadcast address at this sub-layer, including 00215 * those that were discarded or not sent. */ 00216 u32_t ifoutucastpkts; 00217 /** The total number of packets that higher-level protocols requested be transmitted, and which 00218 * were addressed to a multicast or broadcast address at this sub-layer, including 00219 * those that were discarded or not sent. */ 00220 u32_t ifoutnucastpkts; 00221 /** The number of outbound packets which were chosen to be discarded even though no errors had 00222 * been detected to prevent their being transmitted. One possible reason for discarding 00223 * such a packet could be to free up buffer space. */ 00224 u32_t ifoutdiscards; 00225 /** For packet-oriented interfaces, the number of outbound packets that could not be transmitted 00226 * because of errors. For character-oriented or fixed-length interfaces, the number of outbound 00227 * transmission units that could not be transmitted because of errors. */ 00228 u32_t ifouterrors; 00229 }; 00230 00231 /** lwIP stats container */ 00232 struct stats_ { 00233 #if LINK_STATS 00234 /** Link level */ 00235 struct stats_proto link; 00236 #endif 00237 #if ETHARP_STATS 00238 /** ARP */ 00239 struct stats_proto etharp; 00240 #endif 00241 #if IPFRAG_STATS 00242 /** Fragmentation */ 00243 struct stats_proto ip_frag; 00244 #endif 00245 #if IP_STATS 00246 /** IP */ 00247 struct stats_proto ip; 00248 #endif 00249 #if ICMP_STATS 00250 /** ICMP */ 00251 struct stats_proto icmp; 00252 #endif 00253 #if IGMP_STATS 00254 /** IGMP */ 00255 struct stats_igmp igmp; 00256 #endif 00257 #if UDP_STATS 00258 /** UDP */ 00259 struct stats_proto udp; 00260 #endif 00261 #if TCP_STATS 00262 /** TCP */ 00263 struct stats_proto tcp; 00264 #endif 00265 #if MEM_STATS 00266 /** Heap */ 00267 struct stats_mem mem; 00268 #endif 00269 #if MEMP_STATS 00270 /** Internal memory pools */ 00271 struct stats_mem *memp[MEMP_MAX]; 00272 #endif 00273 #if SYS_STATS 00274 /** System */ 00275 struct stats_sys sys; 00276 #endif 00277 #if IP6_STATS 00278 /** IPv6 */ 00279 struct stats_proto ip6; 00280 #endif 00281 #if ICMP6_STATS 00282 /** ICMP6 */ 00283 struct stats_proto icmp6; 00284 #endif 00285 #if IP6_FRAG_STATS 00286 /** IPv6 fragmentation */ 00287 struct stats_proto ip6_frag; 00288 #endif 00289 #if MLD6_STATS 00290 /** Multicast listener discovery */ 00291 struct stats_igmp mld6; 00292 #endif 00293 #if ND6_STATS 00294 /** Neighbor discovery */ 00295 struct stats_proto nd6; 00296 #endif 00297 #if MIB2_STATS 00298 /** SNMP MIB2 */ 00299 struct stats_mib2 mib2; 00300 #endif 00301 }; 00302 00303 /** Global variable containing lwIP internal statistics. Add this to your debugger's watchlist. */ 00304 extern struct stats_ lwip_stats; 00305 00306 /** Init statistics */ 00307 void stats_init(void); 00308 00309 #define STATS_INC(x) ++lwip_stats.x 00310 #define STATS_DEC(x) --lwip_stats.x 00311 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \ 00312 if (lwip_stats.x.max < lwip_stats.x.used) { \ 00313 lwip_stats.x.max = lwip_stats.x.used; \ 00314 } \ 00315 } while(0) 00316 #define STATS_GET(x) lwip_stats.x 00317 #else /* LWIP_STATS */ 00318 #define stats_init() 00319 #define STATS_INC(x) 00320 #define STATS_DEC(x) 00321 #define STATS_INC_USED(x) 00322 #endif /* LWIP_STATS */ 00323 00324 #if TCP_STATS 00325 #define TCP_STATS_INC(x) STATS_INC(x) 00326 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP") 00327 #else 00328 #define TCP_STATS_INC(x) 00329 #define TCP_STATS_DISPLAY() 00330 #endif 00331 00332 #if UDP_STATS 00333 #define UDP_STATS_INC(x) STATS_INC(x) 00334 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP") 00335 #else 00336 #define UDP_STATS_INC(x) 00337 #define UDP_STATS_DISPLAY() 00338 #endif 00339 00340 #if ICMP_STATS 00341 #define ICMP_STATS_INC(x) STATS_INC(x) 00342 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP") 00343 #else 00344 #define ICMP_STATS_INC(x) 00345 #define ICMP_STATS_DISPLAY() 00346 #endif 00347 00348 #if IGMP_STATS 00349 #define IGMP_STATS_INC(x) STATS_INC(x) 00350 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP") 00351 #else 00352 #define IGMP_STATS_INC(x) 00353 #define IGMP_STATS_DISPLAY() 00354 #endif 00355 00356 #if IP_STATS 00357 #define IP_STATS_INC(x) STATS_INC(x) 00358 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP") 00359 #else 00360 #define IP_STATS_INC(x) 00361 #define IP_STATS_DISPLAY() 00362 #endif 00363 00364 #if IPFRAG_STATS 00365 #define IPFRAG_STATS_INC(x) STATS_INC(x) 00366 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG") 00367 #else 00368 #define IPFRAG_STATS_INC(x) 00369 #define IPFRAG_STATS_DISPLAY() 00370 #endif 00371 00372 #if ETHARP_STATS 00373 #define ETHARP_STATS_INC(x) STATS_INC(x) 00374 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP") 00375 #else 00376 #define ETHARP_STATS_INC(x) 00377 #define ETHARP_STATS_DISPLAY() 00378 #endif 00379 00380 #if LINK_STATS 00381 #define LINK_STATS_INC(x) STATS_INC(x) 00382 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK") 00383 #else 00384 #define LINK_STATS_INC(x) 00385 #define LINK_STATS_DISPLAY() 00386 #endif 00387 00388 #if MEM_STATS 00389 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y 00390 #define MEM_STATS_INC(x) STATS_INC(mem.x) 00391 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y) 00392 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y 00393 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP") 00394 #else 00395 #define MEM_STATS_AVAIL(x, y) 00396 #define MEM_STATS_INC(x) 00397 #define MEM_STATS_INC_USED(x, y) 00398 #define MEM_STATS_DEC_USED(x, y) 00399 #define MEM_STATS_DISPLAY() 00400 #endif 00401 00402 #if MEMP_STATS 00403 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i]->x) 00404 #define MEMP_STATS_DISPLAY(i) stats_display_memp(lwip_stats.memp[i], i) 00405 #define MEMP_STATS_GET(x, i) STATS_GET(memp[i]->x) 00406 #else 00407 #define MEMP_STATS_DEC(x, i) 00408 #define MEMP_STATS_DISPLAY(i) 00409 #define MEMP_STATS_GET(x, i) 0 00410 #endif 00411 00412 #if SYS_STATS 00413 #define SYS_STATS_INC(x) STATS_INC(sys.x) 00414 #define SYS_STATS_DEC(x) STATS_DEC(sys.x) 00415 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1) 00416 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys) 00417 #else 00418 #define SYS_STATS_INC(x) 00419 #define SYS_STATS_DEC(x) 00420 #define SYS_STATS_INC_USED(x) 00421 #define SYS_STATS_DISPLAY() 00422 #endif 00423 00424 #if IP6_STATS 00425 #define IP6_STATS_INC(x) STATS_INC(x) 00426 #define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6") 00427 #else 00428 #define IP6_STATS_INC(x) 00429 #define IP6_STATS_DISPLAY() 00430 #endif 00431 00432 #if ICMP6_STATS 00433 #define ICMP6_STATS_INC(x) STATS_INC(x) 00434 #define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6") 00435 #else 00436 #define ICMP6_STATS_INC(x) 00437 #define ICMP6_STATS_DISPLAY() 00438 #endif 00439 00440 #if IP6_FRAG_STATS 00441 #define IP6_FRAG_STATS_INC(x) STATS_INC(x) 00442 #define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG") 00443 #else 00444 #define IP6_FRAG_STATS_INC(x) 00445 #define IP6_FRAG_STATS_DISPLAY() 00446 #endif 00447 00448 #if MLD6_STATS 00449 #define MLD6_STATS_INC(x) STATS_INC(x) 00450 #define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1") 00451 #else 00452 #define MLD6_STATS_INC(x) 00453 #define MLD6_STATS_DISPLAY() 00454 #endif 00455 00456 #if ND6_STATS 00457 #define ND6_STATS_INC(x) STATS_INC(x) 00458 #define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND") 00459 #else 00460 #define ND6_STATS_INC(x) 00461 #define ND6_STATS_DISPLAY() 00462 #endif 00463 00464 #if MIB2_STATS 00465 #define MIB2_STATS_INC(x) STATS_INC(x) 00466 #else 00467 #define MIB2_STATS_INC(x) 00468 #endif 00469 00470 /* Display of statistics */ 00471 #if LWIP_STATS_DISPLAY 00472 void stats_display(void); 00473 void stats_display_proto(struct stats_proto *proto, const char *name); 00474 void stats_display_igmp(struct stats_igmp *igmp, const char *name); 00475 void stats_display_mem(struct stats_mem *mem, const char *name); 00476 void stats_display_memp(struct stats_mem *mem, int index); 00477 void stats_display_sys(struct stats_sys *sys); 00478 #else /* LWIP_STATS_DISPLAY */ 00479 #define stats_display() 00480 #define stats_display_proto(proto, name) 00481 #define stats_display_igmp(igmp, name) 00482 #define stats_display_mem(mem, name) 00483 #define stats_display_memp(mem, index) 00484 #define stats_display_sys(sys) 00485 #endif /* LWIP_STATS_DISPLAY */ 00486 00487 #ifdef __cplusplus 00488 } 00489 #endif 00490 00491 #endif /* LWIP_HDR_STATS_H */
Generated on Tue Jul 12 2022 14:24:39 by
