profiling_helpers.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 <starpu_profiling.h>
  18. #include <profiling/profiling.h>
  19. #include <datawizard/memory_nodes.h>
  20. static double convert_to_GB(float d)
  21. {
  22. const double divisor = 1024;
  23. return d = (((d / divisor) / divisor) / divisor);
  24. }
  25. void _starpu_profiling_bus_helper_display_summary(FILE *stream)
  26. {
  27. int long long sum_transferred = 0;
  28. fprintf(stream, "\n#---------------------\n");
  29. fprintf(stream, "Data transfer stats:\n");
  30. int busid;
  31. int bus_cnt = starpu_bus_get_count();
  32. for (busid = 0; busid < bus_cnt; busid++)
  33. {
  34. char src_name[128], dst_name[128];
  35. int src, dst;
  36. src = starpu_bus_get_src(busid);
  37. dst = starpu_bus_get_dst(busid);
  38. struct starpu_profiling_bus_info bus_info;
  39. starpu_bus_get_profiling_info(busid, &bus_info);
  40. int long long transferred = bus_info.transferred_bytes;
  41. int long long transfer_cnt = bus_info.transfer_count;
  42. double elapsed_time = starpu_timing_timespec_to_us(&bus_info.total_time) / 1e6;
  43. double d = convert_to_GB(transferred);
  44. starpu_memory_node_get_name(src, src_name, sizeof(src_name));
  45. starpu_memory_node_get_name(dst, dst_name, sizeof(dst_name));
  46. fprintf(stream, "\t%s -> %s", src_name, dst_name);
  47. fprintf(stream, "\t%.4lf %s", d, "GB");
  48. fprintf(stream, "\t%.4lf %s/s", (d * 1024) / elapsed_time, "MB");
  49. fprintf(stream, "\t(transfers : %lld - avg %.4lf %s)\n", transfer_cnt, (d * 1024) / transfer_cnt, "MB");
  50. sum_transferred += transferred;
  51. }
  52. double d = convert_to_GB(sum_transferred);
  53. fprintf(stream, "Total transfers: %.4lf %s\n", d, "GB");
  54. fprintf(stream, "#---------------------\n");
  55. }
  56. void starpu_profiling_bus_helper_display_summary(void)
  57. {
  58. const char *stats;
  59. if (!((stats = starpu_getenv("STARPU_BUS_STATS")) && atoi(stats))) return;
  60. const char *filename = starpu_getenv("STARPU_BUS_STATS_FILE");
  61. if (filename==NULL)
  62. _starpu_profiling_bus_helper_display_summary(stderr);
  63. else
  64. {
  65. FILE *sfile = fopen(filename, "w+");
  66. STARPU_ASSERT_MSG(sfile, "Could not open file %s for displaying bus stats (%s). You can specify another file destination with the STARPU_BUS_STATS_FILE environment variable", filename, strerror(errno));
  67. _starpu_profiling_bus_helper_display_summary(sfile);
  68. fclose(sfile);
  69. }
  70. }
  71. void _starpu_profiling_worker_helper_display_summary(FILE *stream)
  72. {
  73. double sum_consumed = 0.;
  74. int profiling = starpu_profiling_status_get();
  75. double overall_time = 0;
  76. int workerid;
  77. int worker_cnt = starpu_worker_get_count();
  78. fprintf(stream, "\n#---------------------\n");
  79. fprintf(stream, "Worker stats:\n");
  80. for (workerid = 0; workerid < worker_cnt; workerid++)
  81. {
  82. struct starpu_profiling_worker_info info;
  83. int ret = starpu_profiling_worker_get_info(workerid, &info);
  84. char name[64];
  85. STARPU_ASSERT(!ret);
  86. starpu_worker_get_name(workerid, name, sizeof(name));
  87. fprintf(stream, "%-32s\n", name);
  88. fprintf(stream, "\t%d task(s)\n", info.executed_tasks);
  89. if (profiling)
  90. {
  91. double total_time = starpu_timing_timespec_to_us(&info.total_time) / 1000.;
  92. double executing_time = starpu_timing_timespec_to_us(&info.executing_time) / 1000.;
  93. double sleeping_time = starpu_timing_timespec_to_us(&info.sleeping_time) / 1000.;
  94. if (total_time > overall_time)
  95. overall_time = total_time;
  96. fprintf(stream, "\ttotal: %.2lf ms executing: %.2lf ms sleeping: %.2lf ms overhead %.2lf ms\n",
  97. total_time, executing_time, sleeping_time, total_time - executing_time - sleeping_time);
  98. if (info.used_cycles || info.stall_cycles)
  99. fprintf(stream, "\t%llu Mcy %llu Mcy stall\n", (unsigned long long)info.used_cycles/1000000, (unsigned long long)info.stall_cycles/1000000);
  100. if (info.energy_consumed)
  101. fprintf(stream, "\t%f J consumed\n", info.energy_consumed);
  102. if (info.flops)
  103. fprintf(stream, "\t%f GFlop/s\n\n", info.flops / total_time / 1000000);
  104. }
  105. sum_consumed += info.energy_consumed;
  106. }
  107. if (profiling)
  108. {
  109. const char *strval_idle_power = starpu_getenv("STARPU_IDLE_POWER");
  110. if (strval_idle_power)
  111. {
  112. double idle_power = atof(strval_idle_power); /* Watt */
  113. double idle_energy = idle_power * overall_time / 1000.; /* J */
  114. fprintf(stream, "Idle energy: %.2lf J\n", idle_energy);
  115. fprintf(stream, "Total energy: %.2lf J\n",
  116. sum_consumed + idle_energy);
  117. }
  118. }
  119. fprintf(stream, "#---------------------\n");
  120. }
  121. void starpu_profiling_worker_helper_display_summary(void)
  122. {
  123. const char *stats;
  124. if (!((stats = starpu_getenv("STARPU_WORKER_STATS")) && atoi(stats))) return;
  125. const char *filename = starpu_getenv("STARPU_WORKER_STATS_FILE");
  126. if (filename==NULL)
  127. _starpu_profiling_worker_helper_display_summary(stderr);
  128. else
  129. {
  130. FILE *sfile = fopen(filename, "w+");
  131. STARPU_ASSERT_MSG(sfile, "Could not open file %s for displaying worker stats (%s). You can specify another file destination with the STARPU_WORKER_STATS_FILE environment variable", filename, strerror(errno));
  132. _starpu_profiling_worker_helper_display_summary(sfile);
  133. fclose(sfile);
  134. }
  135. }