debug.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2013 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. {
  66. char *name;
  67. struct starpu_codelet *cl;
  68. } *codelets;
  69. static unsigned ncodelets, ncodelets_alloc;
  70. static starpu_pthread_mutex_t ayudame_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  71. int64_t _starpu_ayudame_get_func_id(struct starpu_codelet *cl)
  72. {
  73. unsigned i;
  74. const char *name;
  75. if (!cl)
  76. return 0;
  77. name = _starpu_codelet_get_model_name(cl);
  78. STARPU_PTHREAD_MUTEX_LOCK(&ayudame_mutex);
  79. for (i=0; i < ncodelets; i++)
  80. {
  81. if (codelets[i].cl == cl &&
  82. ((!name && !codelets[i].name) ||
  83. ((name && codelets[i].name) && !strcmp(codelets[i].name, name))))
  84. {
  85. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  86. return i + 1;
  87. }
  88. }
  89. if (ncodelets == ncodelets_alloc)
  90. {
  91. if (!ncodelets_alloc)
  92. ncodelets_alloc = 16;
  93. else
  94. ncodelets_alloc *= 2;
  95. codelets = realloc(codelets, ncodelets_alloc * sizeof(*codelets));
  96. }
  97. codelets[ncodelets].cl = cl;
  98. if (name)
  99. /* codelet might be freed by user */
  100. codelets[ncodelets].name = strdup(name);
  101. else
  102. codelets[ncodelets].name = NULL;
  103. i = ncodelets++;
  104. if (name)
  105. AYU_event(AYU_REGISTERFUNCTION, i+1, (void*) name);
  106. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  107. return i + 1;
  108. }
  109. #endif