profiling_helpers.c 4.8 KB

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