datastats.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011,2013,2014,2016,2019 Université de Bordeaux
  4. * Copyright (C) 2010-2013,2015-2017 CNRS
  5. * Copyright (C) 2015,2016 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include <datawizard/datastats.h>
  20. #include <datawizard/coherency.h>
  21. #include <datawizard/memory_nodes.h>
  22. #include <common/config.h>
  23. int _starpu_enable_stats = 0;
  24. void _starpu_datastats_init()
  25. {
  26. _starpu_enable_stats = !!starpu_getenv("STARPU_ENABLE_STATS");
  27. }
  28. /* measure the cache hit ratio for each node */
  29. static unsigned hit_cnt[STARPU_MAXNODES];
  30. static unsigned miss_cnt[STARPU_MAXNODES];
  31. void __starpu_msi_cache_hit(unsigned node)
  32. {
  33. STARPU_HG_DISABLE_CHECKING(hit_cnt[node]);
  34. hit_cnt[node]++;
  35. }
  36. void __starpu_msi_cache_miss(unsigned node)
  37. {
  38. STARPU_HG_DISABLE_CHECKING(miss_cnt[node]);
  39. miss_cnt[node]++;
  40. }
  41. void _starpu_display_msi_stats(FILE *stream)
  42. {
  43. if (!starpu_enable_stats())
  44. return;
  45. unsigned node;
  46. unsigned total_hit_cnt = 0;
  47. unsigned total_miss_cnt = 0;
  48. fprintf(stream, "\n#---------------------\n");
  49. fprintf(stream, "MSI cache stats :\n");
  50. for (node = 0; node < STARPU_MAXNODES; node++)
  51. {
  52. total_hit_cnt += hit_cnt[node];
  53. total_miss_cnt += miss_cnt[node];
  54. }
  55. 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));
  56. for (node = 0; node < STARPU_MAXNODES; node++)
  57. {
  58. if (hit_cnt[node]+miss_cnt[node])
  59. {
  60. char name[128];
  61. starpu_memory_node_get_name(node, name, sizeof(name));
  62. fprintf(stream, "memory node %s\n", name);
  63. fprintf(stream, "\thit : %u (%2.2f %%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  64. fprintf(stream, "\tmiss : %u (%2.2f %%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  65. }
  66. }
  67. fprintf(stream, "#---------------------\n");
  68. }
  69. /* measure the efficiency of our allocation cache */
  70. static unsigned alloc_cnt[STARPU_MAXNODES];
  71. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  72. void __starpu_allocation_cache_hit(unsigned node)
  73. {
  74. STARPU_HG_DISABLE_CHECKING(alloc_cache_hit_cnt[node]);
  75. alloc_cache_hit_cnt[node]++;
  76. }
  77. void __starpu_data_allocation_inc_stats(unsigned node)
  78. {
  79. STARPU_HG_DISABLE_CHECKING(alloc_cnt[node]);
  80. alloc_cnt[node]++;
  81. }
  82. void _starpu_display_alloc_cache_stats(FILE *stream)
  83. {
  84. if (!starpu_enable_stats())
  85. return;
  86. fprintf(stream, "\n#---------------------\n");
  87. fprintf(stream, "Allocation cache stats:\n");
  88. unsigned node;
  89. for (node = 0; node < STARPU_MAXNODES; node++)
  90. {
  91. if (alloc_cnt[node])
  92. {
  93. char name[128];
  94. starpu_memory_node_get_name(node, name, sizeof(name));
  95. fprintf(stream, "memory node %s\n", name);
  96. fprintf(stream, "\ttotal alloc : %u\n", alloc_cnt[node]);
  97. fprintf(stream, "\tcached alloc: %u (%2.2f %%)\n",
  98. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  99. }
  100. }
  101. fprintf(stream, "#---------------------\n");
  102. }