profiling_helpers.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2013, 2016 Université de Bordeaux
  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. _starpu_profiling_bus_helper_display_summary(stderr);
  61. }
  62. void _starpu_profiling_worker_helper_display_summary(FILE *stream)
  63. {
  64. double sum_consumed = 0.;
  65. int profiling = starpu_profiling_status_get();
  66. double overall_time = 0;
  67. int workerid;
  68. int worker_cnt = starpu_worker_get_count();
  69. fprintf(stream, "\n#---------------------\n");
  70. fprintf(stream, "Worker stats:\n");
  71. for (workerid = 0; workerid < worker_cnt; workerid++)
  72. {
  73. struct starpu_profiling_worker_info info;
  74. starpu_profiling_worker_get_info(workerid, &info);
  75. char name[64];
  76. starpu_worker_get_name(workerid, name, sizeof(name));
  77. fprintf(stream, "%-32s\n", name);
  78. fprintf(stream, "\t%d task(s)\n", info.executed_tasks);
  79. if (profiling)
  80. {
  81. double total_time = starpu_timing_timespec_to_us(&info.total_time) / 1000.;
  82. double executing_time = starpu_timing_timespec_to_us(&info.executing_time) / 1000.;
  83. double sleeping_time = starpu_timing_timespec_to_us(&info.sleeping_time) / 1000.;
  84. if (total_time > overall_time)
  85. overall_time = total_time;
  86. fprintf(stream, "\ttotal: %.2lf ms executing: %.2lf ms sleeping: %.2lf ms overhead %.2lf ms\n",
  87. total_time, executing_time, sleeping_time, total_time - executing_time - sleeping_time);
  88. if (info.used_cycles || info.stall_cycles)
  89. fprintf(stream, "\t%llu Mcy %llu Mcy stall\n", (unsigned long long)info.used_cycles/1000000, (unsigned long long)info.stall_cycles/1000000);
  90. if (info.energy_consumed)
  91. fprintf(stream, "\t%f J consumed\n", info.energy_consumed);
  92. if (info.flops)
  93. fprintf(stream, "\t%f GFlop/s\n\n", info.flops / total_time / 1000000);
  94. }
  95. sum_consumed += info.energy_consumed;
  96. }
  97. if (profiling)
  98. {
  99. const char *strval_idle_power = starpu_getenv("STARPU_IDLE_POWER");
  100. if (strval_idle_power)
  101. {
  102. double idle_power = atof(strval_idle_power); /* Watt */
  103. double idle_energy = idle_power * overall_time / 1000.; /* J */
  104. fprintf(stream, "Idle energy: %.2lf J\n", idle_energy);
  105. fprintf(stream, "Total energy: %.2lf J\n",
  106. sum_consumed + idle_energy);
  107. }
  108. }
  109. fprintf(stream, "#---------------------\n");
  110. }
  111. void starpu_profiling_worker_helper_display_summary(void)
  112. {
  113. const char *stats;
  114. if (!((stats = starpu_getenv("STARPU_WORKER_STATS")) && atoi(stats))) return;
  115. _starpu_profiling_worker_helper_display_summary(stderr);
  116. }