datastats.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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, 2016, 2017 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. int _starpu_enable_stats = 0;
  22. void _starpu_datastats_init()
  23. {
  24. _starpu_enable_stats = !!starpu_getenv("STARPU_ENABLE_STATS");
  25. }
  26. /* measure the cache hit ratio for each node */
  27. static unsigned hit_cnt[STARPU_MAXNODES];
  28. static unsigned miss_cnt[STARPU_MAXNODES];
  29. void __starpu_msi_cache_hit(unsigned node)
  30. {
  31. STARPU_HG_DISABLE_CHECKING(hit_cnt[node]);
  32. hit_cnt[node]++;
  33. }
  34. void __starpu_msi_cache_miss(unsigned node)
  35. {
  36. STARPU_HG_DISABLE_CHECKING(miss_cnt[node]);
  37. miss_cnt[node]++;
  38. }
  39. void _starpu_display_msi_stats(FILE *stream)
  40. {
  41. if (!starpu_enable_stats())
  42. return;
  43. unsigned node;
  44. unsigned total_hit_cnt = 0;
  45. unsigned total_miss_cnt = 0;
  46. fprintf(stream, "\n#---------------------\n");
  47. fprintf(stream, "MSI cache stats :\n");
  48. for (node = 0; node < STARPU_MAXNODES; node++)
  49. {
  50. total_hit_cnt += hit_cnt[node];
  51. total_miss_cnt += miss_cnt[node];
  52. }
  53. fprintf(stream, "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));
  54. for (node = 0; node < STARPU_MAXNODES; node++)
  55. {
  56. if (hit_cnt[node]+miss_cnt[node])
  57. {
  58. fprintf(stream, "memory node %u\n", node);
  59. fprintf(stream, "\thit : %u (%2.2f %%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  60. fprintf(stream, "\tmiss : %u (%2.2f %%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  61. }
  62. }
  63. fprintf(stream, "#---------------------\n");
  64. }
  65. /* measure the efficiency of our allocation cache */
  66. static unsigned alloc_cnt[STARPU_MAXNODES];
  67. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  68. void __starpu_allocation_cache_hit(unsigned node)
  69. {
  70. STARPU_HG_DISABLE_CHECKING(alloc_cache_hit_cnt[node]);
  71. alloc_cache_hit_cnt[node]++;
  72. }
  73. void __starpu_data_allocation_inc_stats(unsigned node)
  74. {
  75. STARPU_HG_DISABLE_CHECKING(alloc_cnt[node]);
  76. alloc_cnt[node]++;
  77. }
  78. void _starpu_display_alloc_cache_stats(FILE *stream)
  79. {
  80. if (!starpu_enable_stats())
  81. return;
  82. fprintf(stream, "\n#---------------------\n");
  83. fprintf(stream, "Allocation cache stats:\n");
  84. unsigned node;
  85. for (node = 0; node < STARPU_MAXNODES; node++)
  86. {
  87. if (alloc_cnt[node])
  88. {
  89. fprintf(stream, "memory node %u\n", node);
  90. fprintf(stream, "\ttotal alloc : %u\n", alloc_cnt[node]);
  91. fprintf(stream, "\tcached alloc: %u (%2.2f %%)\n",
  92. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  93. }
  94. else
  95. fprintf(stream, "No allocation on node %u\n", node);
  96. }
  97. fprintf(stream, "#---------------------\n");
  98. }