stats.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. void
  46. stats_init(void)
  47. {
  48. #ifdef LWIP_DEBUG
  49. #if MEM_STATS
  50. lwip_stats.mem.name = "MEM";
  51. #endif /* MEM_STATS */
  52. #endif /* LWIP_DEBUG */
  53. }
  54. #if LWIP_STATS_DISPLAY
  55. void
  56. stats_display_proto(struct stats_proto *proto, const char *name)
  57. {
  58. LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
  59. LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit));
  60. LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv));
  61. LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw));
  62. LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop));
  63. LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", proto->chkerr));
  64. LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", proto->lenerr));
  65. LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", proto->memerr));
  66. LWIP_PLATFORM_DIAG(("rterr: %"STAT_COUNTER_F"\n\t", proto->rterr));
  67. LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", proto->proterr));
  68. LWIP_PLATFORM_DIAG(("opterr: %"STAT_COUNTER_F"\n\t", proto->opterr));
  69. LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", proto->err));
  70. LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit));
  71. }
  72. #if IGMP_STATS || MLD6_STATS
  73. void
  74. stats_display_igmp(struct stats_igmp *igmp, const char *name)
  75. {
  76. LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
  77. LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", igmp->xmit));
  78. LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", igmp->recv));
  79. LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", igmp->drop));
  80. LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr));
  81. LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr));
  82. LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", igmp->memerr));
  83. LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", igmp->proterr));
  84. LWIP_PLATFORM_DIAG(("rx_v1: %"STAT_COUNTER_F"\n\t", igmp->rx_v1));
  85. LWIP_PLATFORM_DIAG(("rx_group: %"STAT_COUNTER_F"\n\t", igmp->rx_group));
  86. LWIP_PLATFORM_DIAG(("rx_general: %"STAT_COUNTER_F"\n\t", igmp->rx_general));
  87. LWIP_PLATFORM_DIAG(("rx_report: %"STAT_COUNTER_F"\n\t", igmp->rx_report));
  88. LWIP_PLATFORM_DIAG(("tx_join: %"STAT_COUNTER_F"\n\t", igmp->tx_join));
  89. LWIP_PLATFORM_DIAG(("tx_leave: %"STAT_COUNTER_F"\n\t", igmp->tx_leave));
  90. LWIP_PLATFORM_DIAG(("tx_report: %"STAT_COUNTER_F"\n", igmp->tx_report));
  91. }
  92. #endif /* IGMP_STATS || MLD6_STATS */
  93. #if MEM_STATS || MEMP_STATS
  94. void
  95. stats_display_mem(struct stats_mem *mem, const char *name)
  96. {
  97. LWIP_PLATFORM_DIAG(("\nMEM %s\n\t", name));
  98. LWIP_PLATFORM_DIAG(("avail: %"MEM_SIZE_F"\n\t", mem->avail));
  99. LWIP_PLATFORM_DIAG(("used: %"MEM_SIZE_F"\n\t", mem->used));
  100. LWIP_PLATFORM_DIAG(("max: %"MEM_SIZE_F"\n\t", mem->max));
  101. LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n", mem->err));
  102. }
  103. #if MEMP_STATS
  104. void
  105. stats_display_memp(struct stats_mem *mem, int idx)
  106. {
  107. if (idx < MEMP_MAX) {
  108. stats_display_mem(mem, mem->name);
  109. }
  110. }
  111. #endif /* MEMP_STATS */
  112. #endif /* MEM_STATS || MEMP_STATS */
  113. #if SYS_STATS
  114. void
  115. stats_display_sys(struct stats_sys *sys)
  116. {
  117. LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
  118. LWIP_PLATFORM_DIAG(("sem.used: %"STAT_COUNTER_F"\n\t", sys->sem.used));
  119. LWIP_PLATFORM_DIAG(("sem.max: %"STAT_COUNTER_F"\n\t", sys->sem.max));
  120. LWIP_PLATFORM_DIAG(("sem.err: %"STAT_COUNTER_F"\n\t", sys->sem.err));
  121. LWIP_PLATFORM_DIAG(("mutex.used: %"STAT_COUNTER_F"\n\t", sys->mutex.used));
  122. LWIP_PLATFORM_DIAG(("mutex.max: %"STAT_COUNTER_F"\n\t", sys->mutex.max));
  123. LWIP_PLATFORM_DIAG(("mutex.err: %"STAT_COUNTER_F"\n\t", sys->mutex.err));
  124. LWIP_PLATFORM_DIAG(("mbox.used: %"STAT_COUNTER_F"\n\t", sys->mbox.used));
  125. LWIP_PLATFORM_DIAG(("mbox.max: %"STAT_COUNTER_F"\n\t", sys->mbox.max));
  126. LWIP_PLATFORM_DIAG(("mbox.err: %"STAT_COUNTER_F"\n", sys->mbox.err));
  127. }
  128. #endif /* SYS_STATS */
  129. void
  130. stats_display(void)
  131. {
  132. s16_t i;
  133. LINK_STATS_DISPLAY();
  134. ETHARP_STATS_DISPLAY();
  135. IPFRAG_STATS_DISPLAY();
  136. IP6_FRAG_STATS_DISPLAY();
  137. IP_STATS_DISPLAY();
  138. ND6_STATS_DISPLAY();
  139. IP6_STATS_DISPLAY();
  140. IGMP_STATS_DISPLAY();
  141. MLD6_STATS_DISPLAY();
  142. ICMP_STATS_DISPLAY();
  143. ICMP6_STATS_DISPLAY();
  144. UDP_STATS_DISPLAY();
  145. TCP_STATS_DISPLAY();
  146. MEM_STATS_DISPLAY();
  147. for (i = 0; i < MEMP_MAX; i++) {
  148. MEMP_STATS_DISPLAY(i);
  149. }
  150. SYS_STATS_DISPLAY();
  151. }
  152. #endif /* LWIP_STATS_DISPLAY */
  153. #endif /* LWIP_STATS */