dmmlib_trace.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright Institute of Communication and Computer Systems (ICCS)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /**
  18. * @file dmmlib_trace.h
  19. * @author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * @date September 2012
  21. * @brief Tracing functions
  22. */
  23. #ifndef _DMMLIB_TRACE_H_
  24. #define _DMMLIB_TRACE_H_
  25. #include "dmmlib/config.h"
  26. #ifdef PARSE_ENV
  27. #include "dmmlib/dmmlib.h" /* to check if systemallocator is initialized */
  28. #endif /* PARSE_ENV */
  29. #ifdef WITH_MEM_TRACE
  30. #include <stdio.h>
  31. #ifndef PARSE_ENV
  32. /** Memory trace file descriptor */
  33. #define MEM_FD stderr
  34. /** Function for memory trace messages */
  35. #define MEM_TRACE(...) fprintf(MEM_FD, __VA_ARGS__)
  36. #else /* PARSE_ENV */
  37. /** Memory trace file descriptor macro */
  38. #define MEM_FD mem_fd
  39. /** Memory trace file descriptor */
  40. FILE* mem_fd;
  41. /** Function for memory trace messages */
  42. #define MEM_TRACE(...) \
  43. if(__builtin_expect (systemallocator.initialized, true)) { \
  44. fprintf(MEM_FD, __VA_ARGS__); \
  45. }
  46. #endif /* PARSE_ENV */
  47. #else /* WITH_MEM_TRACE */
  48. /** Function for memory trace messages */
  49. #define MEM_TRACE(...) /* do nothing */
  50. #endif /* WITH_MEM_TRACE */
  51. #ifdef WITH_STATS_TRACE
  52. #include <stdio.h>
  53. #ifndef PARSE_ENV
  54. /** Statistics file descriptor */
  55. #define STATS_FD stderr
  56. /** Function for statistics trace messages */
  57. #define STATS_TRACE(...) fprintf(STATS_FD, __VA_ARGS__)
  58. #else /* PARSE_ENV */
  59. /** Statistics file descriptor macro */
  60. #define STATS_FD stats_fd
  61. /** Statistics file descriptor */
  62. FILE* stats_fd;
  63. /** Function for statistics trace messages */
  64. #define STATS_TRACE(...) \
  65. if(__builtin_expect (systemallocator.initialized, true)) { \
  66. fprintf(STATS_FD, __VA_ARGS__); \
  67. }
  68. #endif /* PARSE_ENV */
  69. #else /* WITH_STATS_TRACE */
  70. /** Function for statistics trace messages */
  71. #define STATS_TRACE(...) /* do nothing */
  72. #endif /* WITH_STATS_TRACE */
  73. #ifdef WITH_DEBUG
  74. #include <stdio.h>
  75. #ifndef PARSE_ENV
  76. /** Debug file descriptor */
  77. #define DBG_FD stderr
  78. /** Function for debug trace messages */
  79. #define DBG_TRACE(...) fprintf(DBG_FD, __VA_ARGS__)
  80. #else /* PARSE_ENV */
  81. /** Debug file descriptor macro */
  82. #define DBG_FD dbg_fd
  83. /** Debug file descriptor */
  84. FILE* dbg_fd;
  85. /** Function for debug trace messages */
  86. #define DBG_TRACE(...) \
  87. if(__builtin_expect (systemallocator.initialized, true)) { \
  88. fprintf(DBG_FD, __VA_ARGS__); \
  89. }
  90. #endif /* PARSE_ENV */
  91. #else /* WITH_DEBUG */
  92. /** Function for debug trace messages */
  93. #define DBG_TRACE(...) /* do nothing */
  94. #endif /* WITH_DEBUG */
  95. #endif /* _DMMLIB_TRACE_H_ */