macros.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Copyright 2020, Massachusetts Institute of Technology,
  3. * Cambridge, MA 02139
  4. * All Rights Reserved
  5. * Authors: Jingnan Shi, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. */
  8. #pragma once
  9. #include <iostream>
  10. #define TEASER_DEBUG_ERROR_VAR(x) \
  11. do { \
  12. std::cerr << #x << " = " << x << std::endl; \
  13. } while (0)
  14. #define TEASER_INFO_MSG(x) \
  15. do { \
  16. std::cout << x; \
  17. } while (0)
  18. #define TEASER_INFO_MSG_THROTTLE(x, i, N) \
  19. do { \
  20. if (i % N == 0) { \
  21. std::cout << x; \
  22. } \
  23. } while (0)
  24. #if defined(NDEBUG) && !defined(TEASER_DIAG_PRINT)
  25. // Use NOOP to turn off the defined debug macros
  26. #define TEASER_DEBUG_ERROR_MSG(x) \
  27. do { \
  28. } while (0)
  29. #define TEASER_DEBUG_INFO_MSG(x) \
  30. do { \
  31. } while (0)
  32. // Timing macros
  33. #define TEASER_DEBUG_DECLARE_TIMING(s) \
  34. do { \
  35. } while (0)
  36. #define TEASER_DEBUG_START_TIMING(s) \
  37. do { \
  38. } while (0)
  39. #define TEASER_DEBUG_STOP_TIMING(s) \
  40. do { \
  41. } while (0)
  42. #define TEASER_DEBUG_GET_TIMING(s) \
  43. do { \
  44. } while (0)
  45. #else
  46. // Debug messages
  47. #define TEASER_DEBUG_ERROR_MSG(x) \
  48. do { \
  49. std::cerr << x << std::endl; \
  50. } while (0)
  51. #define TEASER_DEBUG_INFO_MSG(x) \
  52. do { \
  53. std::cout << x << std::endl; \
  54. } while (0)
  55. // Timing macros
  56. #define TEASER_DEBUG_DECLARE_TIMING(s) std::chrono::steady_clock clock_##s;
  57. #define TEASER_DEBUG_START_TIMING(s) auto t_start_##s = clock_##s.now();
  58. #define TEASER_DEBUG_STOP_TIMING(s) \
  59. auto t_end_##s = clock_##s.now(); \
  60. std::chrono::duration<double, std::milli> diff_dur_##s = t_end_##s - t_start_##s; \
  61. double diff_##s = diff_dur_##s.count();
  62. #define TEASER_DEBUG_GET_TIMING(s)(double)(diff_##s / 1000.0)
  63. #endif