datastats.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <datawizard/datastats.h>
  18. #include <datawizard/coherency.h>
  19. #include <datawizard/memory_nodes.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. char name[128];
  59. starpu_memory_node_get_name(node, name, sizeof(name));
  60. fprintf(stream, "memory node %s\n", name);
  61. fprintf(stream, "\thit : %u (%2.2f %%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  62. fprintf(stream, "\tmiss : %u (%2.2f %%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  63. }
  64. }
  65. fprintf(stream, "#---------------------\n");
  66. }
  67. /* measure the efficiency of our allocation cache */
  68. static unsigned alloc_cnt[STARPU_MAXNODES];
  69. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  70. void __starpu_allocation_cache_hit(unsigned node)
  71. {
  72. STARPU_HG_DISABLE_CHECKING(alloc_cache_hit_cnt[node]);
  73. alloc_cache_hit_cnt[node]++;
  74. }
  75. void __starpu_data_allocation_inc_stats(unsigned node)
  76. {
  77. STARPU_HG_DISABLE_CHECKING(alloc_cnt[node]);
  78. alloc_cnt[node]++;
  79. }
  80. void _starpu_display_alloc_cache_stats(FILE *stream)
  81. {
  82. if (!starpu_enable_stats())
  83. return;
  84. fprintf(stream, "\n#---------------------\n");
  85. fprintf(stream, "Allocation cache stats:\n");
  86. unsigned node;
  87. for (node = 0; node < STARPU_MAXNODES; node++)
  88. {
  89. if (alloc_cnt[node])
  90. {
  91. char name[128];
  92. starpu_memory_node_get_name(node, name, sizeof(name));
  93. fprintf(stream, "memory node %s\n", name);
  94. fprintf(stream, "\ttotal alloc : %u\n", alloc_cnt[node]);
  95. fprintf(stream, "\tcached alloc: %u (%2.2f %%)\n",
  96. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  97. }
  98. }
  99. fprintf(stream, "#---------------------\n");
  100. }