debug.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012 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. #include <common/config.h>
  18. #include <core/debug.h>
  19. #include <common/utils.h>
  20. #ifdef STARPU_VERBOSE
  21. /* we want a single writer at the same time to have a log that is readable */
  22. static _starpu_pthread_mutex_t logfile_mutex = _STARPU_PTHREAD_MUTEX_INITIALIZER;
  23. static FILE *logfile;
  24. #endif
  25. /* Tell gdb whether FXT is compiled in or not */
  26. int _starpu_use_fxt
  27. #ifdef STARPU_USE_FXT
  28. = 1
  29. #endif
  30. ;
  31. void _starpu_open_debug_logfile(void)
  32. {
  33. #ifdef STARPU_VERBOSE
  34. /* what is the name of the file ? default = "starpu.log" */
  35. char *logfile_name;
  36. logfile_name = getenv("STARPU_LOGFILENAME");
  37. if (!logfile_name)
  38. {
  39. logfile_name = "starpu.log";
  40. }
  41. logfile = fopen(logfile_name, "w+");
  42. STARPU_ASSERT(logfile);
  43. #endif
  44. }
  45. void _starpu_close_debug_logfile(void)
  46. {
  47. #ifdef STARPU_VERBOSE
  48. fclose(logfile);
  49. #endif
  50. }
  51. void _starpu_print_to_logfile(const char *format STARPU_ATTRIBUTE_UNUSED, ...)
  52. {
  53. #ifdef STARPU_VERBOSE
  54. va_list args;
  55. va_start(args, format);
  56. _STARPU_PTHREAD_MUTEX_LOCK(&logfile_mutex);
  57. vfprintf(logfile, format, args);
  58. _STARPU_PTHREAD_MUTEX_UNLOCK(&logfile_mutex);
  59. va_end( args );
  60. #endif
  61. }
  62. /* Record codelet to give ayudame nice function ids starting from 0. */
  63. #ifdef HAVE_AYUDAME_H
  64. struct ayudame_codelet {
  65. char *name;
  66. struct starpu_codelet *cl;
  67. } *codelets;
  68. static unsigned ncodelets, ncodelets_alloc;
  69. static _starpu_pthread_mutex_t ayudame_mutex = _STARPU_PTHREAD_MUTEX_INITIALIZER;
  70. int64_t _starpu_ayudame_get_func_id(struct starpu_codelet *cl)
  71. {
  72. unsigned i;
  73. const char *name;
  74. if (!cl)
  75. return -1;
  76. name = _starpu_codelet_get_model_name(cl);
  77. _STARPU_PTHREAD_MUTEX_LOCK(&ayudame_mutex);
  78. for (i=0; i < ncodelets; i++) {
  79. if (codelets[i].cl == cl &&
  80. ((!name && !codelets[i].name) ||
  81. ((name && codelets[i].name) && !strcmp(codelets[i].name, name)))) {
  82. _STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  83. return i;
  84. }
  85. }
  86. if (ncodelets == ncodelets_alloc) {
  87. if (!ncodelets_alloc)
  88. ncodelets_alloc = 16;
  89. else
  90. ncodelets_alloc *= 2;
  91. codelets = realloc(codelets, ncodelets_alloc * sizeof(*codelets));
  92. }
  93. codelets[ncodelets].cl = cl;
  94. if (name)
  95. /* codelet might be freed by user */
  96. codelets[ncodelets].name = strdup(name);
  97. else
  98. codelets[ncodelets].name = NULL;
  99. i = ncodelets++;
  100. if (name)
  101. AYU_event(AYU_REGISTERFUNCTION, i, (void*) name);
  102. _STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  103. return i;
  104. }
  105. #endif