From 779938ea6861e4b3d000648c351549a06e1e19e1 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 27 Jun 2008 18:37:53 +0000 Subject: [PATCH] patch #6483: stats module improvement: Added defines to display each module's statistic individually, added stats defines for MEM, MEMP and SYS modules, removed (unused) rexmit counter. --- CHANGELOG | 5 +++ src/core/mem.c | 34 ++++------------- src/core/memp.c | 24 ++++-------- src/core/stats.c | 81 ++++++++++++++++++++++------------------ src/include/lwip/stats.h | 74 +++++++++++++++++++++++++++++++++++- 5 files changed, 136 insertions(+), 82 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c5c79f88..09339f6e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2008-06-27 Simon Goldschmidt + * stats.h/.c, some other files: patch #6483: stats module improvement: + Added defines to display each module's statistic individually, added stats + defines for MEM, MEMP and SYS modules, removed (unused) rexmit counter. + 2008-06-17 Simon Goldschmidt * err.h: patch #6459: Made err_t overridable to use a more efficient type (define LWIP_ERR_T in cc.h) diff --git a/src/core/mem.c b/src/core/mem.c index 7dc8a76e..5817e29e 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -277,9 +277,7 @@ mem_init(void) /* initialize the lowest-free pointer to the start of the heap */ lfree = (struct mem *)ram; -#if MEM_STATS - lwip_stats.mem.avail = MEM_SIZE_ALIGNED; -#endif /* MEM_STATS */ + MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED); } /** @@ -308,9 +306,7 @@ mem_free(void *rmem) if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n")); -#if MEM_STATS - ++lwip_stats.mem.err; -#endif /* MEM_STATS */ + MEM_STATS_INC(err); LWIP_MEM_UNPROTECT(); return; } @@ -326,9 +322,7 @@ mem_free(void *rmem) lfree = mem; } -#if MEM_STATS - lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram); -#endif /* MEM_STATS */ + MEM_STATS_DEC_USED(used, mem->next - ((u8_t *)mem - ram)); /* finally, see if prev or next are free also */ plug_holes(mem); @@ -392,9 +386,7 @@ mem_realloc(void *rmem, mem_size_t newsize) /* protect the heap from concurrent access */ LWIP_MEM_PROTECT(); -#if MEM_STATS - lwip_stats.mem.used -= (size - newsize); -#endif /* MEM_STATS */ + MEM_STATS_DEC_USED(used, (size - newsize)); mem2 = (struct mem *)&ram[mem->next]; if(mem2->used == 0) { @@ -526,12 +518,7 @@ mem_malloc(mem_size_t size) if (mem2->next != MEM_SIZE_ALIGNED) { ((struct mem *)&ram[mem2->next])->prev = ptr2; } -#if MEM_STATS - lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM); - if (lwip_stats.mem.max < lwip_stats.mem.used) { - lwip_stats.mem.max = lwip_stats.mem.used; - } -#endif /* MEM_STATS */ + MEM_STATS_INC_USED(used, (size + SIZEOF_STRUCT_MEM)); } else { /* (a mem2 struct does no fit into the user data space of mem and mem->next will always * be used at this point: if not we have 2 unused structs in a row, plug_holes should have @@ -541,12 +528,7 @@ mem_malloc(mem_size_t size) * will always be used at this point! */ mem->used = 1; -#if MEM_STATS - lwip_stats.mem.used += mem->next - ((u8_t *)mem - ram); - if (lwip_stats.mem.max < lwip_stats.mem.used) { - lwip_stats.mem.max = lwip_stats.mem.used; - } -#endif /* MEM_STATS */ + MEM_STATS_INC_USED(used, mem->next - ((u8_t *)mem - ram)); } if (mem == lfree) { @@ -568,9 +550,7 @@ mem_malloc(mem_size_t size) } } LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size)); -#if MEM_STATS - ++lwip_stats.mem.err; -#endif /* MEM_STATS */ + MEM_STATS_INC(err); LWIP_MEM_UNPROTECT(); return NULL; } diff --git a/src/core/memp.c b/src/core/memp.c index 0ef28399..16a91894 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -252,13 +252,12 @@ memp_init(void) struct memp *memp; u16_t i, j; -#if MEMP_STATS for (i = 0; i < MEMP_MAX; ++i) { - lwip_stats.memp[i].used = lwip_stats.memp[i].max = - lwip_stats.memp[i].err = 0; - lwip_stats.memp[i].avail = memp_num[i]; + MEMP_STATS_AVAIL(used, i, 0); + MEMP_STATS_AVAIL(max, i, 0); + MEMP_STATS_AVAIL(err, i, 0); + MEMP_STATS_AVAIL(avail, i, memp_num[i]); } -#endif /* MEMP_STATS */ memp = LWIP_MEM_ALIGN(memp_memory); /* for every pool: */ @@ -315,20 +314,13 @@ memp_malloc_fn(memp_t type, const char* file, const int line) memp->file = file; memp->line = line; #endif /* MEMP_OVERFLOW_CHECK */ -#if MEMP_STATS - ++lwip_stats.memp[type].used; - if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) { - lwip_stats.memp[type].max = lwip_stats.memp[type].used; - } -#endif /* MEMP_STATS */ + MEMP_STATS_INC_USED(used, type); LWIP_ASSERT("memp_malloc: memp properly aligned", ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0); memp = (struct memp*)((u8_t*)memp + MEMP_SIZE); } else { LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %s\n", memp_desc[type])); -#if MEMP_STATS - ++lwip_stats.memp[type].err; -#endif /* MEMP_STATS */ + MEMP_STATS_INC(err, type); } SYS_ARCH_UNPROTECT(old_level); @@ -365,9 +357,7 @@ memp_free(memp_t type, void *mem) #endif /* MEMP_OVERFLOW_CHECK >= 2 */ #endif /* MEMP_OVERFLOW_CHECK */ -#if MEMP_STATS - lwip_stats.memp[type].used--; -#endif /* MEMP_STATS */ + MEMP_STATS_DEC(used, type); memp->next = memp_tab[type]; memp_tab[type] = memp; diff --git a/src/core/stats.c b/src/core/stats.c index 0604468d..a036d83b 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -54,7 +54,6 @@ stats_display_proto(struct stats_proto *proto, char *name) { LWIP_PLATFORM_DIAG(("\n%s\n\t", name)); LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit)); - LWIP_PLATFORM_DIAG(("rexmit: %"STAT_COUNTER_F"\n\t", proto->rexmit)); LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv)); LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw)); LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop)); @@ -68,6 +67,7 @@ stats_display_proto(struct stats_proto *proto, char *name) LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit)); } +#if IGMP_STATS void stats_display_igmp(struct stats_igmp *igmp) { @@ -82,7 +82,9 @@ stats_display_igmp(struct stats_igmp *igmp) LWIP_PLATFORM_DIAG(("report_rxed: %"STAT_COUNTER_F"\n\t", igmp->report_rxed)); LWIP_PLATFORM_DIAG(("group_query_rxed: %"STAT_COUNTER_F"\n", igmp->group_query_rxed)); } +#endif /* IGMP_STATS */ +#if MEM_STATS || MEMP_STATS void stats_display_mem(struct stats_mem *mem, char *name) { @@ -93,48 +95,53 @@ stats_display_mem(struct stats_mem *mem, char *name) LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err)); } -void -stats_display(void) -{ #if MEMP_STATS - s16_t i; +void +stats_display_memp(struct stats_mem *mem, int index) +{ char * memp_names[] = { #define LWIP_MEMPOOL(name,num,size,desc) desc, #include "lwip/memp_std.h" }; -#endif -#if LINK_STATS - stats_display_proto(&lwip_stats.link, "LINK"); -#endif -#if ETHARP_STATS - stats_display_proto(&lwip_stats.etharp, "ETHARP"); -#endif -#if IPFRAG_STATS - stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG"); -#endif -#if IP_STATS - stats_display_proto(&lwip_stats.ip, "IP"); -#endif -#if ICMP_STATS - stats_display_proto(&lwip_stats.icmp, "ICMP"); -#endif -#if IGMP_STATS - stats_display_igmp(&lwip_stats.igmp); -#endif -#if UDP_STATS - stats_display_proto(&lwip_stats.udp, "UDP"); -#endif -#if TCP_STATS - stats_display_proto(&lwip_stats.tcp, "TCP"); -#endif -#if MEM_STATS - stats_display_mem(&lwip_stats.mem, "HEAP"); -#endif -#if MEMP_STATS - for (i = 0; i < MEMP_MAX; i++) { - stats_display_mem(&lwip_stats.memp[i], memp_names[i]); + if(index < MEMP_MAX) { + stats_display_mem(mem, memp_names[index]); } -#endif +} +#endif /* MEMP_STATS */ +#endif /* MEM_STATS || MEMP_STATS */ + +#if SYS_STATS +void +stats_display_sys(struct stats_sys *sys) +{ + LWIP_PLATFORM_DIAG(("\nSYS\n\t")); + LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used)); + LWIP_PLATFORM_DIAG(("sem.max: %"U32_F"\n\t", (u32_t)sys->sem.max)); + LWIP_PLATFORM_DIAG(("sem.err: %"U32_F"\n\t", (u32_t)sys->sem.err)); + LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used)); + LWIP_PLATFORM_DIAG(("mbox.max: %"U32_F"\n\t", (u32_t)sys->mbox.max)); + LWIP_PLATFORM_DIAG(("mbox.err: %"U32_F"\n\t", (u32_t)sys->mbox.err)); +} +#endif /* SYS_STATS */ + +void +stats_display(void) +{ + s16_t i; + + LINK_STATS_DISPLAY(); + ETHARP_STATS_DISPLAY(); + IPFRAG_STATS_DISPLAY(); + IP_STATS_DISPLAY(); + IGMP_STATS_DISPLAY(); + ICMP_STATS_DISPLAY(); + UDP_STATS_DISPLAY(); + TCP_STATS_DISPLAY(); + MEM_STATS_DISPLAY(); + for (i = 0; i < MEMP_MAX; i++) { + MEMP_STATS_DISPLAY(i); + } + SYS_STATS_DISPLAY(); } #endif /* LWIP_STATS_DISPLAY */ diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index 755092ec..1507b4f5 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -57,7 +57,6 @@ extern "C" { struct stats_proto { STAT_COUNTER xmit; /* Transmitted packets. */ - STAT_COUNTER rexmit; /* Retransmitted packets. */ STAT_COUNTER recv; /* Received packets. */ STAT_COUNTER fw; /* Forwarded packets. */ STAT_COUNTER drop; /* Dropped packets. */ @@ -142,64 +141,137 @@ extern struct stats_ lwip_stats; #define stats_init() /* Compatibility define, not init needed. */ #define STATS_INC(x) ++lwip_stats.x +#define STATS_DEC(x) --lwip_stats.x #else #define stats_init() #define STATS_INC(x) +#define STATS_DEC(x) #endif /* LWIP_STATS */ #if TCP_STATS #define TCP_STATS_INC(x) STATS_INC(x) +#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP") #else #define TCP_STATS_INC(x) #endif #if UDP_STATS #define UDP_STATS_INC(x) STATS_INC(x) +#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP") #else #define UDP_STATS_INC(x) +#define UDP_STATS_DISPLAY() #endif #if ICMP_STATS #define ICMP_STATS_INC(x) STATS_INC(x) +#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP") #else #define ICMP_STATS_INC(x) +#define ICMP_STATS_DISPLAY() #endif #if IGMP_STATS #define IGMP_STATS_INC(x) STATS_INC(x) +#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp) #else #define IGMP_STATS_INC(x) +#define IGMP_STATS_DISPLAY() #endif #if IP_STATS #define IP_STATS_INC(x) STATS_INC(x) +#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP") #else #define IP_STATS_INC(x) +#define IP_STATS_DISPLAY() #endif #if IPFRAG_STATS #define IPFRAG_STATS_INC(x) STATS_INC(x) +#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG") #else #define IPFRAG_STATS_INC(x) +#define IPFRAG_STATS_DISPLAY() #endif #if ETHARP_STATS #define ETHARP_STATS_INC(x) STATS_INC(x) +#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP") #else #define ETHARP_STATS_INC(x) +#define ETHARP_STATS_DISPLAY() #endif #if LINK_STATS #define LINK_STATS_INC(x) STATS_INC(x) +#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK") #else #define LINK_STATS_INC(x) +#define LINK_STATS_DISPLAY() +#endif + +#if MEM_STATS +#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y +#define MEM_STATS_INC(x) STATS_INC(mem.x) +#define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \ + if (lwip_stats.mem.max < lwip_stats.mem.used) { \ + lwip_stats.mem.max = lwip_stats.mem.used; \ + } \ + } while(0) +#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y +#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP") +#else +#define MEM_STATS_AVAIL(x) +#define MEM_STATS_INC(x) +#define MEM_STATS_INC_USED(x) +#define MEM_STATS_DEC_USED(x) +#define MEM_STATS_DISPLAY() +#endif + +#if MEMP_STATS +#define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y +#define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x) +#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x) +#define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \ + if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \ + lwip_stats.memp[i].max = lwip_stats.memp[i].used; \ + } \ + } while(0) +#define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i) +#else +#define MEMP_STATS_AVAIL(x) +#define MEMP_STATS_INC(x) +#define MEMP_STATS_DEC(x) +#define MEMP_STATS_INC_USED(x) +#define MEMP_STATS_DISPLAY() +#endif + +#if SYS_STATS +#define SYS_STATS_INC(x) STATS_INC(sys.x) +#define SYS_STATS_DEC(x) STATS_DEC(sys.x) +#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys) +#else +#define SYS_STATS_INC(x) +#define SYS_STATS_DEC(x) +#define SYS_STATS_DISPLAY() #endif /* Display of statistics */ #if LWIP_STATS_DISPLAY void stats_display(void); +void stats_display_proto(struct stats_proto *proto, char *name); +void stats_display_igmp(struct stats_igmp *igmp); +void stats_display_mem(struct stats_mem *mem, char *name); +void stats_display_memp(struct stats_mem *mem, int index); +void stats_display_sys(struct stats_sys *sys); #else #define stats_display() +#define stats_display_proto(proto, name) +#define stats_display_igmp(igmp) +#define stats_display_mem(mem, name) +#define stats_display_memp(mem, int index) +#define stats_display_sys(sys) #endif /* LWIP_STATS_DISPLAY */ #ifdef __cplusplus