starpu_profiling.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 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. #include <starpu.h>
  21. #define STARPU_PROFILING_DISABLE 0
  22. #define STARPU_PROFILING_ENABLE 1
  23. /* -ENOSYS is returned in case the info is not available. Timing are shown in
  24. * microseconds. */
  25. struct starpu_task_profiling_info {
  26. struct timespec submit_time;
  27. struct timespec start_time;
  28. struct timespec end_time;
  29. /* TODO add expected length, expected start/end ? */
  30. int workerid;
  31. };
  32. /* The timing is provided since the previous call to starpu_worker_get_profiling_info */
  33. struct starpu_worker_profiling_info {
  34. struct timespec start_time;
  35. struct timespec total_time;
  36. struct timespec executing_time;
  37. struct timespec sleeping_time;
  38. int executed_tasks;
  39. };
  40. /* This function sets the profiling status:
  41. * - enable with STARPU_PROFILING_ENABLE
  42. * - disable with STARPU_PROFILING_DISABLE
  43. * Negative return values indicate an error, otherwise the previous status is
  44. * returned. Calling this function resets the profiling measurements. */
  45. int starpu_profiling_status_set(int status);
  46. /* Return the current profiling status or a negative value in case there was an
  47. * error. */
  48. int starpu_profiling_status_get(void);
  49. /* Get the profiling info associated to a worker, and reset the profiling
  50. * measurements. If worker_info is NULL, we only reset the counters. */
  51. int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);
  52. /* Some helper functions to manipulate profiling API output */
  53. /* Reset timespec */
  54. static inline void starpu_timespec_clear(struct timespec *tsp)
  55. {
  56. tsp->tv_sec = 0;
  57. tsp->tv_nsec = 0;
  58. }
  59. /* Computes result = a + b */
  60. static inline void starpu_timespec_add(struct timespec *a,
  61. struct timespec *b,
  62. struct timespec *result)
  63. {
  64. result->tv_sec = a->tv_sec + b->tv_sec;
  65. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  66. if (result->tv_nsec >= 1000000000)
  67. {
  68. ++(result)->tv_sec;
  69. result->tv_nsec -= 1000000000;
  70. }
  71. }
  72. /* Computes res += b */
  73. static inline void starpu_timespec_accumulate(struct timespec *result,
  74. struct timespec *a)
  75. {
  76. result->tv_sec += a->tv_sec;
  77. result->tv_nsec += a->tv_nsec;
  78. if (result->tv_nsec >= 1000000000)
  79. {
  80. ++(result)->tv_sec;
  81. result->tv_nsec -= 1000000000;
  82. }
  83. }
  84. /* Computes result = a - b */
  85. static inline void starpu_timespec_sub(struct timespec *a,
  86. struct timespec *b,
  87. struct timespec *result)
  88. {
  89. result->tv_sec = a->tv_sec - b->tv_sec;
  90. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  91. if ((result)->tv_nsec < 0)
  92. {
  93. --(result)->tv_sec;
  94. result->tv_nsec += 1000000000;
  95. }
  96. }
  97. #define starpu_timespec_cmp(a, b, CMP) \
  98. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  99. /* Returns the time elapsed between start and end in microseconds */
  100. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  101. double starpu_timing_timespec_to_us(struct timespec *ts);
  102. #endif // __STARPU_PROFILING_H__