debug.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. int _starpu_use_fxt
  26. #ifdef STARPU_USE_FXT
  27. = 1
  28. #endif
  29. ;
  30. void _starpu_open_debug_logfile(void)
  31. {
  32. #ifdef STARPU_VERBOSE
  33. /* what is the name of the file ? default = "starpu.log" */
  34. char *logfile_name;
  35. logfile_name = getenv("STARPU_LOGFILENAME");
  36. if (!logfile_name)
  37. {
  38. logfile_name = "starpu.log";
  39. }
  40. logfile = fopen(logfile_name, "w+");
  41. STARPU_ASSERT(logfile);
  42. #endif
  43. }
  44. void _starpu_close_debug_logfile(void)
  45. {
  46. #ifdef STARPU_VERBOSE
  47. fclose(logfile);
  48. #endif
  49. }
  50. void _starpu_print_to_logfile(const char *format STARPU_ATTRIBUTE_UNUSED, ...)
  51. {
  52. #ifdef STARPU_VERBOSE
  53. va_list args;
  54. va_start(args, format);
  55. _STARPU_PTHREAD_MUTEX_LOCK(&logfile_mutex);
  56. vfprintf(logfile, format, args);
  57. _STARPU_PTHREAD_MUTEX_UNLOCK(&logfile_mutex);
  58. va_end( args );
  59. #endif
  60. }