dmmlib_trace.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include "tls_allocator.h"
  27. #ifdef PARSE_ENV
  28. #include "dmmlib/dmmlib.h" /* to check if systemallocator is initialized */
  29. #endif /* PARSE_ENV */
  30. #ifdef WITH_MEM_TRACE
  31. #include <stdio.h>
  32. #ifndef PARSE_ENV
  33. /** Memory trace file descriptor */
  34. #define MEM_FD stderr
  35. /** Function for memory trace messages */
  36. #define MEM_TRACE(...) fprintf(MEM_FD, __VA_ARGS__)
  37. #else /* PARSE_ENV */
  38. /** Memory trace file descriptor macro */
  39. #define MEM_FD mem_fd
  40. /** Memory trace file descriptor */
  41. FILE* mem_fd;
  42. /** Function for memory trace messages */
  43. #define MEM_TRACE(...) \
  44. get_tls_allocator(); \
  45. if(__builtin_expect (tls_allocator->initialized, true)) { \
  46. fprintf(MEM_FD, __VA_ARGS__); \
  47. }
  48. #endif /* PARSE_ENV */
  49. #else /* WITH_MEM_TRACE */
  50. /** Function for memory trace messages */
  51. #define MEM_TRACE(...) /* do nothing */
  52. #endif /* WITH_MEM_TRACE */
  53. #ifdef WITH_STATS_TRACE
  54. #include <stdio.h>
  55. #ifndef PARSE_ENV
  56. /** Statistics file descriptor */
  57. #define STATS_FD stderr
  58. /** Function for statistics trace messages */
  59. #define STATS_TRACE(...) fprintf(STATS_FD, __VA_ARGS__)
  60. #else /* PARSE_ENV */
  61. /** Statistics file descriptor macro */
  62. #define STATS_FD stats_fd
  63. /** Statistics file descriptor */
  64. FILE* stats_fd;
  65. /** Function for statistics trace messages */
  66. #define STATS_TRACE(...) \
  67. get_tls_allocator(); \
  68. if(__builtin_expect (tls_allocator->initialized, true)) { \
  69. fprintf(STATS_FD, __VA_ARGS__); \
  70. }
  71. #endif /* PARSE_ENV */
  72. #else /* WITH_STATS_TRACE */
  73. /** Function for statistics trace messages */
  74. #define STATS_TRACE(...) /* do nothing */
  75. #endif /* WITH_STATS_TRACE */
  76. #ifdef WITH_DEBUG
  77. #include <stdio.h>
  78. #ifndef PARSE_ENV
  79. /** Debug file descriptor */
  80. #define DBG_FD stderr
  81. /** Function for debug trace messages */
  82. #define DBG_TRACE(...) fprintf(DBG_FD, __VA_ARGS__)
  83. #else /* PARSE_ENV */
  84. /** Debug file descriptor macro */
  85. #define DBG_FD dbg_fd
  86. /** Debug file descriptor */
  87. FILE* dbg_fd;
  88. /** Function for debug trace messages */
  89. #define DBG_TRACE(...) \
  90. get_tls_allocator(); \
  91. if(__builtin_expect (tls_allocator->initialized, true)) { \
  92. fprintf(DBG_FD, __VA_ARGS__); \
  93. }
  94. #endif /* PARSE_ENV */
  95. #else /* WITH_DEBUG */
  96. /** Function for debug trace messages */
  97. #define DBG_TRACE(...) /* do nothing */
  98. #endif /* WITH_DEBUG */
  99. #endif /* _DMMLIB_TRACE_H_ */