starpu_profiling.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_PROFILING_H__
  18. #define __STARPU_PROFILING_H__
  19. #include <starpu.h>
  20. #include <errno.h>
  21. #include <sys/time.h>
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #define STARPU_PROFILING_DISABLE 0
  27. #define STARPU_PROFILING_ENABLE 1
  28. struct starpu_task_profiling_info
  29. {
  30. /* Task submission */
  31. struct timespec submit_time;
  32. /* Scheduling overhead */
  33. struct timespec push_start_time;
  34. struct timespec push_end_time;
  35. struct timespec pop_start_time;
  36. struct timespec pop_end_time;
  37. /* Take input data */
  38. struct timespec acquire_data_start_time;
  39. struct timespec acquire_data_end_time;
  40. /* Execution */
  41. struct timespec start_time;
  42. struct timespec end_time;
  43. /* Release data */
  44. struct timespec release_data_start_time;
  45. struct timespec release_data_end_time;
  46. /* Callback */
  47. struct timespec callback_start_time;
  48. struct timespec callback_end_time;
  49. /* TODO add expected length, expected start/end ? */
  50. int workerid;
  51. uint64_t used_cycles;
  52. uint64_t stall_cycles;
  53. double power_consumed;
  54. };
  55. /* The timing is provided since the previous call to starpu_worker_get_profiling_info */
  56. struct starpu_worker_profiling_info
  57. {
  58. struct timespec start_time;
  59. struct timespec total_time;
  60. struct timespec executing_time;
  61. struct timespec sleeping_time;
  62. int executed_tasks;
  63. uint64_t used_cycles;
  64. uint64_t stall_cycles;
  65. double power_consumed;
  66. };
  67. struct starpu_bus_profiling_info
  68. {
  69. struct timespec start_time;
  70. struct timespec total_time;
  71. int long long transferred_bytes;
  72. int transfer_count;
  73. };
  74. /* This function sets the ID used for profiling trace filename */
  75. void starpu_set_profiling_id(int new_id);
  76. /* This function sets the profiling status:
  77. * - enable with STARPU_PROFILING_ENABLE
  78. * - disable with STARPU_PROFILING_DISABLE
  79. * Negative return values indicate an error, otherwise the previous status is
  80. * returned. Calling this function resets the profiling measurements. */
  81. int starpu_profiling_status_set(int status);
  82. /* Return the current profiling status or a negative value in case there was an
  83. * error. */
  84. int starpu_profiling_status_get(void);
  85. /* Get the profiling info associated to a worker, and reset the profiling
  86. * measurements. If worker_info is NULL, we only reset the counters. */
  87. int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);
  88. int starpu_bus_get_count(void);
  89. int starpu_bus_get_id(int src, int dst);
  90. int starpu_bus_get_src(int busid);
  91. int starpu_bus_get_dst(int busid);
  92. int starpu_bus_get_profiling_info(int busid, struct starpu_bus_profiling_info *bus_info);
  93. /* Some helper functions to manipulate profiling API output */
  94. /* Reset timespec */
  95. static inline void starpu_timespec_clear(struct timespec *tsp)
  96. {
  97. tsp->tv_sec = 0;
  98. tsp->tv_nsec = 0;
  99. }
  100. /* Computes result = a + b */
  101. static inline void starpu_timespec_add(struct timespec *a,
  102. struct timespec *b,
  103. struct timespec *result)
  104. {
  105. result->tv_sec = a->tv_sec + b->tv_sec;
  106. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  107. if (result->tv_nsec >= 1000000000)
  108. {
  109. ++(result)->tv_sec;
  110. result->tv_nsec -= 1000000000;
  111. }
  112. }
  113. /* Computes res += b */
  114. static inline void starpu_timespec_accumulate(struct timespec *result,
  115. struct timespec *a)
  116. {
  117. result->tv_sec += a->tv_sec;
  118. result->tv_nsec += a->tv_nsec;
  119. if (result->tv_nsec >= 1000000000)
  120. {
  121. ++(result)->tv_sec;
  122. result->tv_nsec -= 1000000000;
  123. }
  124. }
  125. /* Computes result = a - b */
  126. static inline void starpu_timespec_sub(struct timespec *a,
  127. struct timespec *b,
  128. struct timespec *result)
  129. {
  130. result->tv_sec = a->tv_sec - b->tv_sec;
  131. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  132. if ((result)->tv_nsec < 0)
  133. {
  134. --(result)->tv_sec;
  135. result->tv_nsec += 1000000000;
  136. }
  137. }
  138. #define starpu_timespec_cmp(a, b, CMP) \
  139. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  140. /* Returns the time elapsed between start and end in microseconds */
  141. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  142. double starpu_timing_timespec_to_us(struct timespec *ts);
  143. void starpu_bus_profiling_helper_display_summary(void);
  144. void starpu_worker_profiling_helper_display_summary(void);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* __STARPU_PROFILING_H__ */