debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013, 2017 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2013, 2015, 2016 CNRS
  5. * Copyright (C) 2016 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <common/config.h>
  19. #include <core/debug.h>
  20. #include <common/utils.h>
  21. #ifdef STARPU_VERBOSE
  22. /* we want a single writer at the same time to have a log that is readable */
  23. static starpu_pthread_mutex_t logfile_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  24. static FILE *logfile = NULL;
  25. #endif
  26. /* Tell gdb whether FXT is compiled in or not */
  27. int _starpu_use_fxt
  28. #ifdef STARPU_USE_FXT
  29. = 1
  30. #endif
  31. ;
  32. void _starpu_open_debug_logfile(void)
  33. {
  34. #ifdef STARPU_VERBOSE
  35. /* what is the name of the file ? default = "starpu.log" */
  36. char *logfile_name;
  37. logfile_name = starpu_getenv("STARPU_LOGFILENAME");
  38. if (!logfile_name)
  39. {
  40. logfile_name = "starpu.log";
  41. }
  42. logfile = fopen(logfile_name, "w+");
  43. 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));
  44. #endif
  45. }
  46. void _starpu_close_debug_logfile(void)
  47. {
  48. #ifdef STARPU_VERBOSE
  49. if (logfile)
  50. {
  51. fclose(logfile);
  52. logfile = NULL;
  53. }
  54. #endif
  55. }
  56. void _starpu_print_to_logfile(const char *format STARPU_ATTRIBUTE_UNUSED, ...)
  57. {
  58. #ifdef STARPU_VERBOSE
  59. va_list args;
  60. va_start(args, format);
  61. STARPU_PTHREAD_MUTEX_LOCK(&logfile_mutex);
  62. vfprintf(logfile, format, args);
  63. STARPU_PTHREAD_MUTEX_UNLOCK(&logfile_mutex);
  64. va_end( args );
  65. #endif
  66. }
  67. /* Record codelet to give ayudame nice function ids starting from 0. */
  68. #if defined(STARPU_USE_AYUDAME1)
  69. struct ayudame_codelet
  70. {
  71. char *name;
  72. struct starpu_codelet *cl;
  73. } *codelets;
  74. static unsigned ncodelets, ncodelets_alloc;
  75. static starpu_pthread_mutex_t ayudame_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  76. int64_t _starpu_ayudame_get_func_id(struct starpu_codelet *cl)
  77. {
  78. unsigned i;
  79. const char *name;
  80. if (!cl)
  81. return 0;
  82. name = _starpu_codelet_get_model_name(cl);
  83. STARPU_PTHREAD_MUTEX_LOCK(&ayudame_mutex);
  84. for (i=0; i < ncodelets; i++)
  85. {
  86. if (codelets[i].cl == cl &&
  87. ((!name && !codelets[i].name) ||
  88. ((name && codelets[i].name) && !strcmp(codelets[i].name, name))))
  89. {
  90. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  91. return i + 1;
  92. }
  93. }
  94. if (ncodelets == ncodelets_alloc)
  95. {
  96. if (!ncodelets_alloc)
  97. ncodelets_alloc = 16;
  98. else
  99. ncodelets_alloc *= 2;
  100. _STARPU_REALLOC(codelets, ncodelets_alloc * sizeof(*codelets));
  101. }
  102. codelets[ncodelets].cl = cl;
  103. if (name)
  104. /* codelet might be freed by user */
  105. codelets[ncodelets].name = strdup(name);
  106. else
  107. codelets[ncodelets].name = NULL;
  108. i = ncodelets++;
  109. if (name)
  110. AYU_event(AYU_REGISTERFUNCTION, i+1, (void*) name);
  111. STARPU_PTHREAD_MUTEX_UNLOCK(&ayudame_mutex);
  112. return i + 1;
  113. }
  114. #endif /* AYUDAME1 */