stats.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. * @file
  3. * Statistics module
  4. *
  5. */
  6. /*
  7. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  24. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  26. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  29. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. * OF SUCH DAMAGE.
  31. *
  32. * This file is part of the lwIP TCP/IP stack.
  33. *
  34. * Author: Adam Dunkels <adam@sics.se>
  35. *
  36. */
  37. #include "lwip/opt.h"
  38. #if LWIP_STATS /* don't build if not configured for use in lwipopts.h */
  39. #include "lwip/def.h"
  40. #include "lwip/stats.h"
  41. #include "lwip/mem.h"
  42. #include "lwip/debug.h"
  43. #include <string.h>
  44. struct stats_ lwip_stats;
  45. #if defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY
  46. #if MEMP_STATS
  47. static const char * memp_names[] = {
  48. #define LWIP_MEMPOOL(name,num,size,desc) desc,
  49. #include "lwip/priv/memp_std.h"
  50. };
  51. #endif /* MEMP_STATS */
  52. #endif /* LWIP_DEBUG || LWIP_STATS_DISPLAY */
  53. void
  54. stats_init(void)
  55. {
  56. #ifdef LWIP_DEBUG
  57. #if MEMP_STATS
  58. int i;
  59. for (i = 0; i < MEMP_MAX; i++) {
  60. lwip_stats.memp[i].name = memp_names[i];
  61. }
  62. #endif /* MEMP_STATS */
  63. #if MEM_STATS
  64. lwip_stats.mem.name = "MEM";
  65. #endif /* MEM_STATS */
  66. #endif /* LWIP_DEBUG */
  67. }
  68. #if LWIP_STATS_DISPLAY
  69. void
  70. stats_display_proto(struct stats_proto *proto, const char *name)
  71. {
  72. LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
  73. LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit));
  74. LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv));
  75. LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw));
  76. LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop));
  77. LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", proto->chkerr));
  78. LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", proto->lenerr));
  79. LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", proto->memerr));
  80. LWIP_PLATFORM_DIAG(("rterr: %"STAT_COUNTER_F"\n\t", proto->rterr));
  81. LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", proto->proterr));
  82. LWIP_PLATFORM_DIAG(("opterr: %"STAT_COUNTER_F"\n\t", proto->opterr));
  83. LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", proto->err));
  84. LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit));
  85. }
  86. #if IGMP_STATS || MLD6_STATS
  87. void
  88. stats_display_igmp(struct stats_igmp *igmp, const char *name)
  89. {
  90. LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
  91. LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", igmp->xmit));
  92. LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", igmp->recv));
  93. LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", igmp->drop));
  94. LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr));
  95. LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr));
  96. LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", igmp->memerr));
  97. LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", igmp->proterr));
  98. LWIP_PLATFORM_DIAG(("rx_v1: %"STAT_COUNTER_F"\n\t", igmp->rx_v1));
  99. LWIP_PLATFORM_DIAG(("rx_group: %"STAT_COUNTER_F"\n\t", igmp->rx_group));
  100. LWIP_PLATFORM_DIAG(("rx_general: %"STAT_COUNTER_F"\n\t", igmp->rx_general));
  101. LWIP_PLATFORM_DIAG(("rx_report: %"STAT_COUNTER_F"\n\t", igmp->rx_report));
  102. LWIP_PLATFORM_DIAG(("tx_join: %"STAT_COUNTER_F"\n\t", igmp->tx_join));
  103. LWIP_PLATFORM_DIAG(("tx_leave: %"STAT_COUNTER_F"\n\t", igmp->tx_leave));
  104. LWIP_PLATFORM_DIAG(("tx_report: %"STAT_COUNTER_F"\n\t", igmp->tx_report));
  105. }
  106. #endif /* IGMP_STATS || MLD6_STATS */
  107. #if MEM_STATS || MEMP_STATS
  108. void
  109. stats_display_mem(struct stats_mem *mem, const char *name)
  110. {
  111. LWIP_PLATFORM_DIAG(("\nMEM %s\n\t", name));
  112. LWIP_PLATFORM_DIAG(("avail: %"U32_F"\n\t", (u32_t)mem->avail));
  113. LWIP_PLATFORM_DIAG(("used: %"U32_F"\n\t", (u32_t)mem->used));
  114. LWIP_PLATFORM_DIAG(("max: %"U32_F"\n\t", (u32_t)mem->max));
  115. LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
  116. }
  117. #if MEMP_STATS
  118. void
  119. stats_display_memp(struct stats_mem *mem, int index)
  120. {
  121. if (index < MEMP_MAX) {
  122. stats_display_mem(mem, memp_names[index]);
  123. }
  124. }
  125. #endif /* MEMP_STATS */
  126. #endif /* MEM_STATS || MEMP_STATS */
  127. #if SYS_STATS
  128. void
  129. stats_display_sys(struct stats_sys *sys)
  130. {
  131. LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
  132. LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used));
  133. LWIP_PLATFORM_DIAG(("sem.max: %"U32_F"\n\t", (u32_t)sys->sem.max));
  134. LWIP_PLATFORM_DIAG(("sem.err: %"U32_F"\n\t", (u32_t)sys->sem.err));
  135. LWIP_PLATFORM_DIAG(("mutex.used: %"U32_F"\n\t", (u32_t)sys->mutex.used));
  136. LWIP_PLATFORM_DIAG(("mutex.max: %"U32_F"\n\t", (u32_t)sys->mutex.max));
  137. LWIP_PLATFORM_DIAG(("mutex.err: %"U32_F"\n\t", (u32_t)sys->mutex.err));
  138. LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used));
  139. LWIP_PLATFORM_DIAG(("mbox.max: %"U32_F"\n\t", (u32_t)sys->mbox.max));
  140. LWIP_PLATFORM_DIAG(("mbox.err: %"U32_F"\n\t", (u32_t)sys->mbox.err));
  141. }
  142. #endif /* SYS_STATS */
  143. void
  144. stats_display(void)
  145. {
  146. s16_t i;
  147. LINK_STATS_DISPLAY();
  148. ETHARP_STATS_DISPLAY();
  149. IPFRAG_STATS_DISPLAY();
  150. IP6_FRAG_STATS_DISPLAY();
  151. IP_STATS_DISPLAY();
  152. ND6_STATS_DISPLAY();
  153. IP6_STATS_DISPLAY();
  154. IGMP_STATS_DISPLAY();
  155. MLD6_STATS_DISPLAY();
  156. ICMP_STATS_DISPLAY();
  157. ICMP6_STATS_DISPLAY();
  158. UDP_STATS_DISPLAY();
  159. TCP_STATS_DISPLAY();
  160. MEM_STATS_DISPLAY();
  161. for (i = 0; i < MEMP_MAX; i++) {
  162. MEMP_STATS_DISPLAY(i);
  163. }
  164. SYS_STATS_DISPLAY();
  165. }
  166. #endif /* LWIP_STATS_DISPLAY */
  167. #if ESP_STATS_DROP
  168. void stats_display_esp(struct stats_esp *esp)
  169. {
  170. LWIP_PLATFORM_DIAG(("\nESP\n\t"));
  171. LWIP_PLATFORM_DIAG(("esp.rx_rawmbox_post_fail: %"U32_F"\n\t", (u32_t)esp->rx_rawmbox_post_fail));
  172. LWIP_PLATFORM_DIAG(("esp.rx_udpmbox_post_fail: %"U32_F"\n\t", (u32_t)esp->rx_udpmbox_post_fail));
  173. LWIP_PLATFORM_DIAG(("esp.rx_tcpmbox_post_fail: %"U32_F"\n\t", (u32_t)esp->rx_tcpmbox_post_fail));
  174. LWIP_PLATFORM_DIAG(("esp.err_tcp_rxmbox_post_fail: %"U32_F"\n\t", (u32_t)esp->err_tcp_rxmbox_post_fail));
  175. LWIP_PLATFORM_DIAG(("esp.err_tcp_acceptmbox_post_fail: %"U32_F"\n\t", (u32_t)esp->err_tcp_acceptmbox_post_fail));
  176. LWIP_PLATFORM_DIAG(("esp.acceptmbox_post_fail: %"U32_F"\n\t", (u32_t)esp->acceptmbox_post_fail));
  177. LWIP_PLATFORM_DIAG(("esp.free_mbox_post_fail: %"U32_F"\n\t", (u32_t)esp->free_mbox_post_fail));
  178. LWIP_PLATFORM_DIAG(("esp.tcpip_inpkt_post_fail: %"U32_F"\n\t", (u32_t)esp->tcpip_inpkt_post_fail));
  179. LWIP_PLATFORM_DIAG(("esp.tcpip_cb_post_fail: %"U32_F"\n\t", (u32_t)esp->tcpip_cb_post_fail));
  180. LWIP_PLATFORM_DIAG(("esp.wlanif_input_pbuf_fail: %"U32_F"\n\t", (u32_t)esp->wlanif_input_pbuf_fail));
  181. LWIP_PLATFORM_DIAG(("esp.wlanif_outut_pbuf_fail: %"U32_F"\n\t", (u32_t)esp->wlanif_outut_pbuf_fail));
  182. }
  183. #endif
  184. #endif /* LWIP_STATS */