]> git.sur5r.net Git - freertos/blob - Demo/Common/ethernet/lwIP/core/stats.c
d5b37406bbef9fdb62c780e2033bdf95c7334b26
[freertos] / Demo / Common / ethernet / lwIP / core / stats.c
1 /*
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
33 #include <string.h>
34
35 #include "lwip/opt.h"
36
37 #include "lwip/def.h"
38
39 #include "lwip/stats.h"
40 #include "lwip/mem.h"
41
42
43 #if LWIP_STATS
44 struct stats_ lwip_stats;
45
46 void
47 stats_init(void)
48 {
49   memset(&lwip_stats, 0, sizeof(struct stats_));
50 }
51 #if LWIP_STATS_DISPLAY
52 void
53 stats_display_proto(struct stats_proto *proto, char *name)
54 {
55   LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
56   LWIP_PLATFORM_DIAG(("xmit: %"S16_F"\n\t", proto->xmit)); 
57   LWIP_PLATFORM_DIAG(("rexmit: %"S16_F"\n\t", proto->rexmit)); 
58   LWIP_PLATFORM_DIAG(("recv: %"S16_F"\n\t", proto->recv)); 
59   LWIP_PLATFORM_DIAG(("fw: %"S16_F"\n\t", proto->fw)); 
60   LWIP_PLATFORM_DIAG(("drop: %"S16_F"\n\t", proto->drop)); 
61   LWIP_PLATFORM_DIAG(("chkerr: %"S16_F"\n\t", proto->chkerr)); 
62   LWIP_PLATFORM_DIAG(("lenerr: %"S16_F"\n\t", proto->lenerr)); 
63   LWIP_PLATFORM_DIAG(("memerr: %"S16_F"\n\t", proto->memerr)); 
64   LWIP_PLATFORM_DIAG(("rterr: %"S16_F"\n\t", proto->rterr)); 
65   LWIP_PLATFORM_DIAG(("proterr: %"S16_F"\n\t", proto->proterr)); 
66   LWIP_PLATFORM_DIAG(("opterr: %"S16_F"\n\t", proto->opterr)); 
67   LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", proto->err)); 
68   LWIP_PLATFORM_DIAG(("cachehit: %"S16_F"\n", proto->cachehit)); 
69 }
70
71 void
72 stats_display_pbuf(struct stats_pbuf *pbuf)
73 {
74   LWIP_PLATFORM_DIAG(("\nPBUF\n\t"));
75   LWIP_PLATFORM_DIAG(("avail: %"S16_F"\n\t", pbuf->avail)); 
76   LWIP_PLATFORM_DIAG(("used: %"S16_F"\n\t", pbuf->used)); 
77   LWIP_PLATFORM_DIAG(("max: %"S16_F"\n\t", pbuf->max)); 
78   LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", pbuf->err)); 
79   LWIP_PLATFORM_DIAG(("alloc_locked: %"S16_F"\n\t", pbuf->alloc_locked)); 
80   LWIP_PLATFORM_DIAG(("refresh_locked: %"S16_F"\n", pbuf->refresh_locked)); 
81 }
82
83 void
84 stats_display_mem(struct stats_mem *mem, char *name)
85 {
86   LWIP_PLATFORM_DIAG(("\n MEM %s\n\t", name));
87   LWIP_PLATFORM_DIAG(("avail: %"MEM_SIZE_F"\n\t", mem->avail)); 
88   LWIP_PLATFORM_DIAG(("used: %"MEM_SIZE_F"\n\t", mem->used)); 
89   LWIP_PLATFORM_DIAG(("max: %"MEM_SIZE_F"\n\t", mem->max)); 
90   LWIP_PLATFORM_DIAG(("err: %"MEM_SIZE_F"\n", mem->err));
91   
92 }
93
94 void
95 stats_display(void)
96 {
97   s16_t i;
98   char * memp_names[] = {"PBUF", "RAW_PCB", "UDP_PCB", "TCP_PCB", "TCP_PCB_LISTEN",
99         "TCP_SEG", "NETBUF", "NETCONN", "API_MSG", "TCP_MSG", "TIMEOUT"};
100   stats_display_proto(&lwip_stats.link, "LINK");
101   stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG");
102   stats_display_proto(&lwip_stats.ip, "IP");
103   stats_display_proto(&lwip_stats.icmp, "ICMP");
104   stats_display_proto(&lwip_stats.udp, "UDP");
105   stats_display_proto(&lwip_stats.tcp, "TCP");
106   stats_display_pbuf(&lwip_stats.pbuf);
107   stats_display_mem(&lwip_stats.mem, "HEAP");
108   for (i = 0; i < MEMP_MAX; i++) {
109     stats_display_mem(&lwip_stats.memp[i], memp_names[i]);
110   }
111   
112 }
113 #endif /* LWIP_STATS_DISPLAY */
114 #endif /* LWIP_STATS */
115