| 1 |
606 |
jeremybenn |
/*
|
| 2 |
|
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
| 3 |
|
|
* All rights reserved.
|
| 4 |
|
|
*
|
| 5 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
| 6 |
|
|
* are permitted provided that the following conditions are met:
|
| 7 |
|
|
*
|
| 8 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
| 9 |
|
|
* this list of conditions and the following disclaimer.
|
| 10 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
| 12 |
|
|
* and/or other materials provided with the distribution.
|
| 13 |
|
|
* 3. The name of the author may not be used to endorse or promote products
|
| 14 |
|
|
* derived from this software without specific prior written permission.
|
| 15 |
|
|
*
|
| 16 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
| 17 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| 18 |
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
| 19 |
|
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 20 |
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
| 21 |
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 22 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 23 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
| 24 |
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
| 25 |
|
|
* OF SUCH DAMAGE.
|
| 26 |
|
|
*
|
| 27 |
|
|
* This file is part of the lwIP TCP/IP stack.
|
| 28 |
|
|
*
|
| 29 |
|
|
* Author: Adam Dunkels <adam@sics.se>
|
| 30 |
|
|
*
|
| 31 |
|
|
*/
|
| 32 |
|
|
#ifndef __LWIP_STATS_H__
|
| 33 |
|
|
#define __LWIP_STATS_H__
|
| 34 |
|
|
|
| 35 |
|
|
#include "lwip/opt.h"
|
| 36 |
|
|
|
| 37 |
|
|
#include "lwip/mem.h"
|
| 38 |
|
|
#include "lwip/memp.h"
|
| 39 |
|
|
|
| 40 |
|
|
#ifdef __cplusplus
|
| 41 |
|
|
extern "C" {
|
| 42 |
|
|
#endif
|
| 43 |
|
|
|
| 44 |
|
|
#if LWIP_STATS
|
| 45 |
|
|
|
| 46 |
|
|
#ifndef LWIP_STATS_LARGE
|
| 47 |
|
|
#define LWIP_STATS_LARGE 0
|
| 48 |
|
|
#endif
|
| 49 |
|
|
|
| 50 |
|
|
#if LWIP_STATS_LARGE
|
| 51 |
|
|
#define STAT_COUNTER u32_t
|
| 52 |
|
|
#define STAT_COUNTER_F U32_F
|
| 53 |
|
|
#else
|
| 54 |
|
|
#define STAT_COUNTER u16_t
|
| 55 |
|
|
#define STAT_COUNTER_F U16_F
|
| 56 |
|
|
#endif
|
| 57 |
|
|
|
| 58 |
|
|
struct stats_proto {
|
| 59 |
|
|
STAT_COUNTER xmit; /* Transmitted packets. */
|
| 60 |
|
|
STAT_COUNTER recv; /* Received packets. */
|
| 61 |
|
|
STAT_COUNTER fw; /* Forwarded packets. */
|
| 62 |
|
|
STAT_COUNTER drop; /* Dropped packets. */
|
| 63 |
|
|
STAT_COUNTER chkerr; /* Checksum error. */
|
| 64 |
|
|
STAT_COUNTER lenerr; /* Invalid length error. */
|
| 65 |
|
|
STAT_COUNTER memerr; /* Out of memory error. */
|
| 66 |
|
|
STAT_COUNTER rterr; /* Routing error. */
|
| 67 |
|
|
STAT_COUNTER proterr; /* Protocol error. */
|
| 68 |
|
|
STAT_COUNTER opterr; /* Error in options. */
|
| 69 |
|
|
STAT_COUNTER err; /* Misc error. */
|
| 70 |
|
|
STAT_COUNTER cachehit;
|
| 71 |
|
|
};
|
| 72 |
|
|
|
| 73 |
|
|
struct stats_igmp {
|
| 74 |
|
|
STAT_COUNTER lenerr; /* Invalid length error. */
|
| 75 |
|
|
STAT_COUNTER chkerr; /* Checksum error. */
|
| 76 |
|
|
STAT_COUNTER v1_rxed; /* */
|
| 77 |
|
|
STAT_COUNTER join_sent; /* */
|
| 78 |
|
|
STAT_COUNTER leave_sent; /* */
|
| 79 |
|
|
STAT_COUNTER unicast_query; /* */
|
| 80 |
|
|
STAT_COUNTER report_sent; /* */
|
| 81 |
|
|
STAT_COUNTER report_rxed; /* */
|
| 82 |
|
|
STAT_COUNTER group_query_rxed; /* */
|
| 83 |
|
|
};
|
| 84 |
|
|
|
| 85 |
|
|
struct stats_mem {
|
| 86 |
|
|
mem_size_t avail;
|
| 87 |
|
|
mem_size_t used;
|
| 88 |
|
|
mem_size_t max;
|
| 89 |
|
|
STAT_COUNTER err;
|
| 90 |
|
|
STAT_COUNTER illegal;
|
| 91 |
|
|
};
|
| 92 |
|
|
|
| 93 |
|
|
struct stats_syselem {
|
| 94 |
|
|
STAT_COUNTER used;
|
| 95 |
|
|
STAT_COUNTER max;
|
| 96 |
|
|
STAT_COUNTER err;
|
| 97 |
|
|
};
|
| 98 |
|
|
|
| 99 |
|
|
struct stats_sys {
|
| 100 |
|
|
struct stats_syselem sem;
|
| 101 |
|
|
struct stats_syselem mbox;
|
| 102 |
|
|
};
|
| 103 |
|
|
|
| 104 |
|
|
struct stats_ {
|
| 105 |
|
|
#if LINK_STATS
|
| 106 |
|
|
struct stats_proto link;
|
| 107 |
|
|
#endif
|
| 108 |
|
|
#if ETHARP_STATS
|
| 109 |
|
|
struct stats_proto etharp;
|
| 110 |
|
|
#endif
|
| 111 |
|
|
#if IPFRAG_STATS
|
| 112 |
|
|
struct stats_proto ip_frag;
|
| 113 |
|
|
#endif
|
| 114 |
|
|
#if IP_STATS
|
| 115 |
|
|
struct stats_proto ip;
|
| 116 |
|
|
#endif
|
| 117 |
|
|
#if ICMP_STATS
|
| 118 |
|
|
struct stats_proto icmp;
|
| 119 |
|
|
#endif
|
| 120 |
|
|
#if IGMP_STATS
|
| 121 |
|
|
struct stats_igmp igmp;
|
| 122 |
|
|
#endif
|
| 123 |
|
|
#if UDP_STATS
|
| 124 |
|
|
struct stats_proto udp;
|
| 125 |
|
|
#endif
|
| 126 |
|
|
#if TCP_STATS
|
| 127 |
|
|
struct stats_proto tcp;
|
| 128 |
|
|
#endif
|
| 129 |
|
|
#if MEM_STATS
|
| 130 |
|
|
struct stats_mem mem;
|
| 131 |
|
|
#endif
|
| 132 |
|
|
#if MEMP_STATS
|
| 133 |
|
|
struct stats_mem memp[MEMP_MAX];
|
| 134 |
|
|
#endif
|
| 135 |
|
|
#if SYS_STATS
|
| 136 |
|
|
struct stats_sys sys;
|
| 137 |
|
|
#endif
|
| 138 |
|
|
};
|
| 139 |
|
|
|
| 140 |
|
|
extern struct stats_ lwip_stats;
|
| 141 |
|
|
|
| 142 |
|
|
#define stats_init() /* Compatibility define, not init needed. */
|
| 143 |
|
|
|
| 144 |
|
|
#define STATS_INC(x) ++lwip_stats.x
|
| 145 |
|
|
#define STATS_DEC(x) --lwip_stats.x
|
| 146 |
|
|
#else
|
| 147 |
|
|
#define stats_init()
|
| 148 |
|
|
#define STATS_INC(x)
|
| 149 |
|
|
#define STATS_DEC(x)
|
| 150 |
|
|
#endif /* LWIP_STATS */
|
| 151 |
|
|
|
| 152 |
|
|
#if TCP_STATS
|
| 153 |
|
|
#define TCP_STATS_INC(x) STATS_INC(x)
|
| 154 |
|
|
#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
|
| 155 |
|
|
#else
|
| 156 |
|
|
#define TCP_STATS_INC(x)
|
| 157 |
|
|
#define TCP_STATS_DISPLAY()
|
| 158 |
|
|
#endif
|
| 159 |
|
|
|
| 160 |
|
|
#if UDP_STATS
|
| 161 |
|
|
#define UDP_STATS_INC(x) STATS_INC(x)
|
| 162 |
|
|
#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
|
| 163 |
|
|
#else
|
| 164 |
|
|
#define UDP_STATS_INC(x)
|
| 165 |
|
|
#define UDP_STATS_DISPLAY()
|
| 166 |
|
|
#endif
|
| 167 |
|
|
|
| 168 |
|
|
#if ICMP_STATS
|
| 169 |
|
|
#define ICMP_STATS_INC(x) STATS_INC(x)
|
| 170 |
|
|
#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
|
| 171 |
|
|
#else
|
| 172 |
|
|
#define ICMP_STATS_INC(x)
|
| 173 |
|
|
#define ICMP_STATS_DISPLAY()
|
| 174 |
|
|
#endif
|
| 175 |
|
|
|
| 176 |
|
|
#if IGMP_STATS
|
| 177 |
|
|
#define IGMP_STATS_INC(x) STATS_INC(x)
|
| 178 |
|
|
#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
|
| 179 |
|
|
#else
|
| 180 |
|
|
#define IGMP_STATS_INC(x)
|
| 181 |
|
|
#define IGMP_STATS_DISPLAY()
|
| 182 |
|
|
#endif
|
| 183 |
|
|
|
| 184 |
|
|
#if IP_STATS
|
| 185 |
|
|
#define IP_STATS_INC(x) STATS_INC(x)
|
| 186 |
|
|
#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
|
| 187 |
|
|
#else
|
| 188 |
|
|
#define IP_STATS_INC(x)
|
| 189 |
|
|
#define IP_STATS_DISPLAY()
|
| 190 |
|
|
#endif
|
| 191 |
|
|
|
| 192 |
|
|
#if IPFRAG_STATS
|
| 193 |
|
|
#define IPFRAG_STATS_INC(x) STATS_INC(x)
|
| 194 |
|
|
#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
|
| 195 |
|
|
#else
|
| 196 |
|
|
#define IPFRAG_STATS_INC(x)
|
| 197 |
|
|
#define IPFRAG_STATS_DISPLAY()
|
| 198 |
|
|
#endif
|
| 199 |
|
|
|
| 200 |
|
|
#if ETHARP_STATS
|
| 201 |
|
|
#define ETHARP_STATS_INC(x) STATS_INC(x)
|
| 202 |
|
|
#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
|
| 203 |
|
|
#else
|
| 204 |
|
|
#define ETHARP_STATS_INC(x)
|
| 205 |
|
|
#define ETHARP_STATS_DISPLAY()
|
| 206 |
|
|
#endif
|
| 207 |
|
|
|
| 208 |
|
|
#if LINK_STATS
|
| 209 |
|
|
#define LINK_STATS_INC(x) STATS_INC(x)
|
| 210 |
|
|
#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
|
| 211 |
|
|
#else
|
| 212 |
|
|
#define LINK_STATS_INC(x)
|
| 213 |
|
|
#define LINK_STATS_DISPLAY()
|
| 214 |
|
|
#endif
|
| 215 |
|
|
|
| 216 |
|
|
#if MEM_STATS
|
| 217 |
|
|
#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
|
| 218 |
|
|
#define MEM_STATS_INC(x) STATS_INC(mem.x)
|
| 219 |
|
|
#define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
|
| 220 |
|
|
if (lwip_stats.mem.max < lwip_stats.mem.used) { \
|
| 221 |
|
|
lwip_stats.mem.max = lwip_stats.mem.used; \
|
| 222 |
|
|
} \
|
| 223 |
|
|
} while(0)
|
| 224 |
|
|
#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
|
| 225 |
|
|
#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
|
| 226 |
|
|
#else
|
| 227 |
|
|
#define MEM_STATS_AVAIL(x, y)
|
| 228 |
|
|
#define MEM_STATS_INC(x)
|
| 229 |
|
|
#define MEM_STATS_INC_USED(x, y)
|
| 230 |
|
|
#define MEM_STATS_DEC_USED(x, y)
|
| 231 |
|
|
#define MEM_STATS_DISPLAY()
|
| 232 |
|
|
#endif
|
| 233 |
|
|
|
| 234 |
|
|
#if MEMP_STATS
|
| 235 |
|
|
#define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
|
| 236 |
|
|
#define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
|
| 237 |
|
|
#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
|
| 238 |
|
|
#define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
|
| 239 |
|
|
if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \
|
| 240 |
|
|
lwip_stats.memp[i].max = lwip_stats.memp[i].used; \
|
| 241 |
|
|
} \
|
| 242 |
|
|
} while(0)
|
| 243 |
|
|
#define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
|
| 244 |
|
|
#else
|
| 245 |
|
|
#define MEMP_STATS_AVAIL(x, i, y)
|
| 246 |
|
|
#define MEMP_STATS_INC(x, i)
|
| 247 |
|
|
#define MEMP_STATS_DEC(x, i)
|
| 248 |
|
|
#define MEMP_STATS_INC_USED(x, i)
|
| 249 |
|
|
#define MEMP_STATS_DISPLAY(i)
|
| 250 |
|
|
#endif
|
| 251 |
|
|
|
| 252 |
|
|
#if SYS_STATS
|
| 253 |
|
|
#define SYS_STATS_INC(x) STATS_INC(sys.x)
|
| 254 |
|
|
#define SYS_STATS_DEC(x) STATS_DEC(sys.x)
|
| 255 |
|
|
#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
|
| 256 |
|
|
#else
|
| 257 |
|
|
#define SYS_STATS_INC(x)
|
| 258 |
|
|
#define SYS_STATS_DEC(x)
|
| 259 |
|
|
#define SYS_STATS_DISPLAY()
|
| 260 |
|
|
#endif
|
| 261 |
|
|
|
| 262 |
|
|
/* Display of statistics */
|
| 263 |
|
|
#if LWIP_STATS_DISPLAY
|
| 264 |
|
|
void stats_display(void);
|
| 265 |
|
|
void stats_display_proto(struct stats_proto *proto, char *name);
|
| 266 |
|
|
void stats_display_igmp(struct stats_igmp *igmp);
|
| 267 |
|
|
void stats_display_mem(struct stats_mem *mem, char *name);
|
| 268 |
|
|
void stats_display_memp(struct stats_mem *mem, int index);
|
| 269 |
|
|
void stats_display_sys(struct stats_sys *sys);
|
| 270 |
|
|
#else
|
| 271 |
|
|
#define stats_display()
|
| 272 |
|
|
#define stats_display_proto(proto, name)
|
| 273 |
|
|
#define stats_display_igmp(igmp)
|
| 274 |
|
|
#define stats_display_mem(mem, name)
|
| 275 |
|
|
#define stats_display_memp(mem, index)
|
| 276 |
|
|
#define stats_display_sys(sys)
|
| 277 |
|
|
#endif /* LWIP_STATS_DISPLAY */
|
| 278 |
|
|
|
| 279 |
|
|
#ifdef __cplusplus
|
| 280 |
|
|
}
|
| 281 |
|
|
#endif
|
| 282 |
|
|
|
| 283 |
|
|
#endif /* __LWIP_STATS_H__ */
|