debug.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <common/config.h>
  17. #include <core/debug.h>
  18. #ifdef VERBOSE
  19. /* we want a single writer at the same time to have a log that is readable */
  20. static pthread_mutex_t logfile_mutex = PTHREAD_MUTEX_INITIALIZER;
  21. static FILE *logfile;
  22. #endif
  23. void _starpu_open_debug_logfile(void)
  24. {
  25. #ifdef VERBOSE
  26. /* what is the name of the file ? default = "starpu.log" */
  27. char *logfile_name;
  28. logfile_name = getenv("STARPU_LOGFILENAME");
  29. if (!logfile_name)
  30. {
  31. logfile_name = "starpu.log";
  32. }
  33. logfile = fopen(logfile_name, "w+");
  34. STARPU_ASSERT(logfile);
  35. #endif
  36. }
  37. void _starpu_close_debug_logfile(void)
  38. {
  39. #ifdef VERBOSE
  40. fclose(logfile);
  41. #endif
  42. }
  43. void _starpu_print_to_logfile(const char *format __attribute__((unused)), ...)
  44. {
  45. #ifdef VERBOSE
  46. va_list args;
  47. va_start(args, format);
  48. pthread_mutex_lock(&logfile_mutex);
  49. vfprintf(logfile, format, args);
  50. pthread_mutex_unlock(&logfile_mutex);
  51. va_end( args );
  52. #endif
  53. }