datastats.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <datawizard/datastats.h>
  19. #include <datawizard/coherency.h>
  20. #include <common/config.h>
  21. #ifdef STARPU_ENABLE_STATS
  22. /* measure the cache hit ratio for each node */
  23. static unsigned hit_cnt[STARPU_MAXNODES];
  24. static unsigned miss_cnt[STARPU_MAXNODES];
  25. #endif
  26. void _starpu_msi_cache_hit(unsigned node STARPU_ATTRIBUTE_UNUSED)
  27. {
  28. #ifdef STARPU_ENABLE_STATS
  29. hit_cnt[node]++;
  30. #endif
  31. }
  32. void _starpu_msi_cache_miss(unsigned node STARPU_ATTRIBUTE_UNUSED)
  33. {
  34. #ifdef STARPU_ENABLE_STATS
  35. miss_cnt[node]++;
  36. #endif
  37. }
  38. void _starpu_display_msi_stats(void)
  39. {
  40. #ifdef STARPU_ENABLE_STATS
  41. unsigned node;
  42. unsigned total_hit_cnt = 0;
  43. unsigned total_miss_cnt = 0;
  44. fprintf(stderr, "\n#---------------------\n");
  45. fprintf(stderr, "MSI cache stats :\n");
  46. for (node = 0; node < STARPU_MAXNODES; node++)
  47. {
  48. total_hit_cnt += hit_cnt[node];
  49. total_miss_cnt += miss_cnt[node];
  50. }
  51. fprintf(stderr, "TOTAL MSI stats\thit %u (%2.2f \%%)\tmiss %u (%2.2f \%%)\n", total_hit_cnt, (100.0f*total_hit_cnt)/(total_hit_cnt+total_miss_cnt), total_miss_cnt, (100.0f*total_miss_cnt)/(total_hit_cnt+total_miss_cnt));
  52. for (node = 0; node < STARPU_MAXNODES; node++)
  53. {
  54. if (hit_cnt[node]+miss_cnt[node])
  55. {
  56. fprintf(stderr, "memory node %d\n", node);
  57. fprintf(stderr, "\thit : %u (%2.2f \%%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  58. fprintf(stderr, "\tmiss : %u (%2.2f \%%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  59. }
  60. }
  61. fprintf(stderr, "#---------------------\n");
  62. #endif
  63. }
  64. /* measure the efficiency of our allocation cache */
  65. #ifdef STARPU_ENABLE_STATS
  66. static unsigned alloc_cnt[STARPU_MAXNODES];
  67. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  68. #endif
  69. void _starpu_allocation_cache_hit(unsigned node STARPU_ATTRIBUTE_UNUSED)
  70. {
  71. #ifdef STARPU_ENABLE_STATS
  72. alloc_cache_hit_cnt[node]++;
  73. #endif
  74. }
  75. void _starpu_data_allocation_inc_stats(unsigned node STARPU_ATTRIBUTE_UNUSED)
  76. {
  77. #ifdef STARPU_ENABLE_STATS
  78. alloc_cnt[node]++;
  79. #endif
  80. }
  81. void _starpu_display_alloc_cache_stats(void)
  82. {
  83. #ifdef STARPU_ENABLE_STATS
  84. fprintf(stderr, "\n#---------------------\n");
  85. fprintf(stderr, "Allocation cache stats:\n");
  86. unsigned node;
  87. for (node = 0; node < STARPU_MAXNODES; node++)
  88. {
  89. if (alloc_cnt[node])
  90. {
  91. fprintf(stderr, "memory node %d\n", node);
  92. fprintf(stderr, "\ttotal alloc : %u\n", alloc_cnt[node]);
  93. fprintf(stderr, "\tcached alloc: %u (%2.2f \%%)\n",
  94. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  95. }
  96. else
  97. fprintf(stderr, "No allocation on node %d\n", node);
  98. }
  99. fprintf(stderr, "#---------------------\n");
  100. #endif
  101. }
  102. /* measure the amount of data transfers between each pair of nodes */
  103. #ifdef STARPU_ENABLE_STATS
  104. static size_t comm_amount[STARPU_MAXNODES][STARPU_MAXNODES];
  105. #endif /* STARPU_ENABLE_STATS */
  106. void _starpu_comm_amounts_inc(unsigned src STARPU_ATTRIBUTE_UNUSED, unsigned dst STARPU_ATTRIBUTE_UNUSED, size_t size STARPU_ATTRIBUTE_UNUSED)
  107. {
  108. #ifdef STARPU_ENABLE_STATS
  109. comm_amount[src][dst] += size;
  110. #endif /* STARPU_ENABLE_STATS */
  111. }
  112. void _starpu_display_comm_amounts(void)
  113. {
  114. #ifdef STARPU_DEVEL
  115. # warning TODO. The information displayed here seems to be similar to the one displayed by starpu_profiling_bus_helper_display_summary()
  116. #endif
  117. #ifdef STARPU_ENABLE_STATS
  118. unsigned src, dst;
  119. size_t sum = 0;
  120. fprintf(stderr, "\n#---------------------\n");
  121. fprintf(stderr, "Data transfer stats:\n");
  122. for (dst = 0; dst < STARPU_MAXNODES; dst++)
  123. for (src = 0; src < STARPU_MAXNODES; src++)
  124. {
  125. sum += comm_amount[src][dst];
  126. sum += comm_amount[dst][src];
  127. }
  128. fprintf(stderr, "TOTAL transfers %f MB\n", (float)sum/1024/1024);
  129. for (dst = 0; dst < STARPU_MAXNODES; dst++)
  130. for (src = dst + 1; src < STARPU_MAXNODES; src++)
  131. {
  132. if (comm_amount[src][dst])
  133. fprintf(stderr, "\t%d <-> %d\t%f MB\n\t\t%d -> %d\t%f MB\n\t\t%d -> %d\t%f MB\n",
  134. src, dst, ((float)comm_amount[src][dst] + (float)comm_amount[dst][src])/(1024*1024),
  135. src, dst, ((float)comm_amount[src][dst])/(1024*1024),
  136. dst, src, ((float)comm_amount[dst][src])/(1024*1024));
  137. }
  138. fprintf(stderr, "#---------------------\n");
  139. #endif
  140. }