debug.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2013, 2015 CNRS
  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 = NULL;
  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 = starpu_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. if (logfile)
  49. {
  50. fclose(logfile);
  51. logfile = NULL;
  52. }
  53. #endif
  54. }
  55. void _starpu_print_to_logfile(const char *format STARPU_ATTRIBUTE_UNUSED, ...)
  56. {
  57. #ifdef STARPU_VERBOSE
  58. va_list args;
  59. va_start(args, format);
  60. STARPU_PTHREAD_MUTEX_LOCK(&logfile_mutex);
  61. vfprintf(logfile, format, args);
  62. STARPU_PTHREAD_MUTEX_UNLOCK(&logfile_mutex);
  63. va_end( args );
  64. #endif
  65. }
  66. /* Record codelet to give ayudame nice function ids starting from 0. */
  67. #ifdef HAVE_AYUDAME_H
  68. struct ayudame_codelet
  69. {
  70. char *name;
  71. struct starpu_codelet *cl;
  72. } *codelets;
  73. static unsigned ncodelets, ncodelets_alloc;
  74. static starpu_pthread_mutex_t ayudame_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  75. int64_t _starpu_ayudame_get_func_id(struct starpu_codelet *cl)
  76. {
  77. unsigned i;
  78. const char *name;
  79. if (!cl)
  80. return 0;
  81. name = _starpu_codelet_get_model_name(cl);
  82. STARPU_PTHREAD_MUTEX_LOCK(&ayudame_mutex);
  83. for (i=0; i < ncodelets; i++)
  84. {
  85. if (codelets[i].cl == cl &&
  86. ((!name && !codelets[i].name) ||
  87. ((name && codelets[i].name) && !strcmp(codelets[i].name, name))))
  88. {
  89. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  90. return i + 1;
  91. }
  92. }
  93. if (ncodelets == ncodelets_alloc)
  94. {
  95. if (!ncodelets_alloc)
  96. ncodelets_alloc = 16;
  97. else
  98. ncodelets_alloc *= 2;
  99. codelets = realloc(codelets, ncodelets_alloc * sizeof(*codelets));
  100. }
  101. codelets[ncodelets].cl = cl;
  102. if (name)
  103. /* codelet might be freed by user */
  104. codelets[ncodelets].name = strdup(name);
  105. else
  106. codelets[ncodelets].name = NULL;
  107. i = ncodelets++;
  108. if (name)
  109. AYU_event(AYU_REGISTERFUNCTION, i+1, (void*) name);
  110. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  111. return i + 1;
  112. }
  113. #endif