starpu_profiling.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. #ifndef __STARPU_PROFILING_H__
  17. #define __STARPU_PROFILING_H__
  18. #include <errno.h>
  19. #include <sys/time.h>
  20. #ifdef __MINGW32__
  21. #ifndef STARPU_TIMESPEC_DEFINED
  22. #define STARPU_TIMESPEC_DEFINED 1
  23. struct timespec {
  24. time_t tv_sec; /* Seconds */
  25. long tv_nsec; /* Nanoseconds */
  26. };
  27. #endif /* STARPU_TIMESPEC_DEFINED */
  28. #endif
  29. #include <starpu.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #define STARPU_PROFILING_DISABLE 0
  34. #define STARPU_PROFILING_ENABLE 1
  35. struct starpu_task_profiling_info {
  36. struct timespec submit_time;
  37. struct timespec start_time;
  38. struct timespec end_time;
  39. /* TODO add expected length, expected start/end ? */
  40. int workerid;
  41. };
  42. /* The timing is provided since the previous call to starpu_worker_get_profiling_info */
  43. struct starpu_worker_profiling_info {
  44. struct timespec start_time;
  45. struct timespec total_time;
  46. struct timespec executing_time;
  47. struct timespec sleeping_time;
  48. int executed_tasks;
  49. };
  50. struct starpu_bus_profiling_info {
  51. struct timespec start_time;
  52. struct timespec total_time;
  53. int long long transferred_bytes;
  54. int transfer_count;
  55. };
  56. /* This function sets the profiling status:
  57. * - enable with STARPU_PROFILING_ENABLE
  58. * - disable with STARPU_PROFILING_DISABLE
  59. * Negative return values indicate an error, otherwise the previous status is
  60. * returned. Calling this function resets the profiling measurements. */
  61. int starpu_profiling_status_set(int status);
  62. /* Return the current profiling status or a negative value in case there was an
  63. * error. */
  64. int starpu_profiling_status_get(void);
  65. /* Get the profiling info associated to a worker, and reset the profiling
  66. * measurements. If worker_info is NULL, we only reset the counters. */
  67. int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);
  68. int starpu_bus_get_count(void);
  69. int starpu_bus_get_id(int src, int dst);
  70. int starpu_bus_get_src(int busid);
  71. int starpu_bus_get_dst(int busid);
  72. int starpu_bus_get_profiling_info(int busid, struct starpu_bus_profiling_info *bus_info);
  73. /* Some helper functions to manipulate profiling API output */
  74. /* Reset timespec */
  75. static inline void starpu_timespec_clear(struct timespec *tsp)
  76. {
  77. tsp->tv_sec = 0;
  78. tsp->tv_nsec = 0;
  79. }
  80. /* Computes result = a + b */
  81. static inline void starpu_timespec_add(struct timespec *a,
  82. struct timespec *b,
  83. struct timespec *result)
  84. {
  85. result->tv_sec = a->tv_sec + b->tv_sec;
  86. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  87. if (result->tv_nsec >= 1000000000)
  88. {
  89. ++(result)->tv_sec;
  90. result->tv_nsec -= 1000000000;
  91. }
  92. }
  93. /* Computes res += b */
  94. static inline void starpu_timespec_accumulate(struct timespec *result,
  95. struct timespec *a)
  96. {
  97. result->tv_sec += a->tv_sec;
  98. result->tv_nsec += a->tv_nsec;
  99. if (result->tv_nsec >= 1000000000)
  100. {
  101. ++(result)->tv_sec;
  102. result->tv_nsec -= 1000000000;
  103. }
  104. }
  105. /* Computes result = a - b */
  106. static inline void starpu_timespec_sub(struct timespec *a,
  107. struct timespec *b,
  108. struct timespec *result)
  109. {
  110. result->tv_sec = a->tv_sec - b->tv_sec;
  111. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  112. if ((result)->tv_nsec < 0)
  113. {
  114. --(result)->tv_sec;
  115. result->tv_nsec += 1000000000;
  116. }
  117. }
  118. #define starpu_timespec_cmp(a, b, CMP) \
  119. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  120. /* Returns the time elapsed between start and end in microseconds */
  121. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  122. double starpu_timing_timespec_to_us(struct timespec *ts);
  123. void starpu_bus_profiling_helper_display_summary(void);
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif // __STARPU_PROFILING_H__