datastats.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2013, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2015 CNRS
  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. static int _enable_stats = 0;
  22. void _starpu_datastats_init()
  23. {
  24. _enable_stats = !!starpu_getenv("STARPU_ENABLE_STATS");
  25. }
  26. static inline int starpu_enable_stats(void)
  27. {
  28. return _enable_stats;
  29. }
  30. /* measure the cache hit ratio for each node */
  31. static unsigned hit_cnt[STARPU_MAXNODES];
  32. static unsigned miss_cnt[STARPU_MAXNODES];
  33. void _starpu_msi_cache_hit(unsigned node STARPU_ATTRIBUTE_UNUSED)
  34. {
  35. if (!starpu_enable_stats())
  36. return;
  37. STARPU_HG_DISABLE_CHECKING(hit_cnt[node]);
  38. hit_cnt[node]++;
  39. }
  40. void _starpu_msi_cache_miss(unsigned node STARPU_ATTRIBUTE_UNUSED)
  41. {
  42. if (!starpu_enable_stats())
  43. return;
  44. STARPU_HG_DISABLE_CHECKING(miss_cnt[node]);
  45. miss_cnt[node]++;
  46. }
  47. void _starpu_display_msi_stats(void)
  48. {
  49. if (!starpu_enable_stats())
  50. return;
  51. unsigned node;
  52. unsigned total_hit_cnt = 0;
  53. unsigned total_miss_cnt = 0;
  54. fprintf(stderr, "\n#---------------------\n");
  55. fprintf(stderr, "MSI cache stats :\n");
  56. for (node = 0; node < STARPU_MAXNODES; node++)
  57. {
  58. total_hit_cnt += hit_cnt[node];
  59. total_miss_cnt += miss_cnt[node];
  60. }
  61. 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));
  62. for (node = 0; node < STARPU_MAXNODES; node++)
  63. {
  64. if (hit_cnt[node]+miss_cnt[node])
  65. {
  66. fprintf(stderr, "memory node %d\n", node);
  67. fprintf(stderr, "\thit : %u (%2.2f %%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  68. fprintf(stderr, "\tmiss : %u (%2.2f %%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  69. }
  70. }
  71. fprintf(stderr, "#---------------------\n");
  72. }
  73. /* measure the efficiency of our allocation cache */
  74. static unsigned alloc_cnt[STARPU_MAXNODES];
  75. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  76. void _starpu_allocation_cache_hit(unsigned node STARPU_ATTRIBUTE_UNUSED)
  77. {
  78. if (!starpu_enable_stats())
  79. return;
  80. STARPU_HG_DISABLE_CHECKING(alloc_cache_hit_cnt[node]);
  81. alloc_cache_hit_cnt[node]++;
  82. }
  83. void _starpu_data_allocation_inc_stats(unsigned node STARPU_ATTRIBUTE_UNUSED)
  84. {
  85. if (!starpu_enable_stats())
  86. return;
  87. STARPU_HG_DISABLE_CHECKING(alloc_cnt[node]);
  88. alloc_cnt[node]++;
  89. }
  90. void _starpu_display_alloc_cache_stats(void)
  91. {
  92. if (!starpu_enable_stats())
  93. return;
  94. fprintf(stderr, "\n#---------------------\n");
  95. fprintf(stderr, "Allocation cache stats:\n");
  96. unsigned node;
  97. for (node = 0; node < STARPU_MAXNODES; node++)
  98. {
  99. if (alloc_cnt[node])
  100. {
  101. fprintf(stderr, "memory node %d\n", node);
  102. fprintf(stderr, "\ttotal alloc : %u\n", alloc_cnt[node]);
  103. fprintf(stderr, "\tcached alloc: %u (%2.2f %%)\n",
  104. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  105. }
  106. else
  107. fprintf(stderr, "No allocation on node %d\n", node);
  108. }
  109. fprintf(stderr, "#---------------------\n");
  110. }