debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 <common/config.h>
  17. #include <core/debug.h>
  18. #include <common/utils.h>
  19. #ifdef STARPU_VERBOSE
  20. /* we want a single writer at the same time to have a log that is readable */
  21. static starpu_pthread_mutex_t logfile_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  22. static FILE *logfile = NULL;
  23. #endif
  24. int _starpu_debug
  25. #ifdef STARPU_DEBUG
  26. = 1
  27. #else
  28. = 0
  29. #endif
  30. ;
  31. /* Tell gdb whether FXT is compiled in or not */
  32. int _starpu_use_fxt
  33. #ifdef STARPU_USE_FXT
  34. = 1
  35. #endif
  36. ;
  37. void _starpu_open_debug_logfile(void)
  38. {
  39. #ifdef STARPU_VERBOSE
  40. /* what is the name of the file ? default = "starpu.log" */
  41. char *logfile_name;
  42. logfile_name = starpu_getenv("STARPU_LOGFILENAME");
  43. if (!logfile_name)
  44. {
  45. logfile_name = "starpu.log";
  46. }
  47. logfile = fopen(logfile_name, "w+");
  48. STARPU_ASSERT_MSG(logfile, "Could not open file %s for verbose logs (%s). You can specify another file destination with the STARPU_LOGFILENAME environment variable", logfile_name, strerror(errno));
  49. #endif
  50. }
  51. void _starpu_close_debug_logfile(void)
  52. {
  53. #ifdef STARPU_VERBOSE
  54. if (logfile)
  55. {
  56. fclose(logfile);
  57. logfile = NULL;
  58. }
  59. #endif
  60. }
  61. void _starpu_print_to_logfile(const char *format STARPU_ATTRIBUTE_UNUSED, ...)
  62. {
  63. #ifdef STARPU_VERBOSE
  64. va_list args;
  65. va_start(args, format);
  66. STARPU_PTHREAD_MUTEX_LOCK(&logfile_mutex);
  67. vfprintf(logfile, format, args);
  68. STARPU_PTHREAD_MUTEX_UNLOCK(&logfile_mutex);
  69. va_end( args );
  70. #endif
  71. }
  72. /* Record codelet to give ayudame nice function ids starting from 0. */
  73. #if defined(STARPU_USE_AYUDAME1)
  74. struct ayudame_codelet
  75. {
  76. char *name;
  77. struct starpu_codelet *cl;
  78. } *codelets;
  79. static unsigned ncodelets, ncodelets_alloc;
  80. static starpu_pthread_mutex_t ayudame_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  81. int64_t _starpu_ayudame_get_func_id(struct starpu_codelet *cl)
  82. {
  83. unsigned i;
  84. const char *name;
  85. if (!cl)
  86. return 0;
  87. name = _starpu_codelet_get_model_name(cl);
  88. STARPU_PTHREAD_MUTEX_LOCK(&ayudame_mutex);
  89. for (i=0; i < ncodelets; i++)
  90. {
  91. if (codelets[i].cl == cl &&
  92. ((!name && !codelets[i].name) ||
  93. ((name && codelets[i].name) && !strcmp(codelets[i].name, name))))
  94. {
  95. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  96. return i + 1;
  97. }
  98. }
  99. if (ncodelets == ncodelets_alloc)
  100. {
  101. if (!ncodelets_alloc)
  102. ncodelets_alloc = 16;
  103. else
  104. ncodelets_alloc *= 2;
  105. _STARPU_REALLOC(codelets, ncodelets_alloc * sizeof(*codelets));
  106. }
  107. codelets[ncodelets].cl = cl;
  108. if (name)
  109. /* codelet might be freed by user */
  110. codelets[ncodelets].name = strdup(name);
  111. else
  112. codelets[ncodelets].name = NULL;
  113. i = ncodelets++;
  114. if (name)
  115. AYU_event(AYU_REGISTERFUNCTION, i+1, (void*) name);
  116. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  117. return i + 1;
  118. }
  119. #endif /* AYUDAME1 */