debug.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 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 pthread_mutex_t logfile_mutex = 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. }