TaskDebugMacros.h
Go to the documentation of this file.
1 #ifndef art_Utilities_TaskDebugMacros_h
2 #define art_Utilities_TaskDebugMacros_h
3 // vim: set sw=2 expandtab :
4 
6 #include "hep_concurrency/tsan.h"
7 
8 #include <atomic>
9 #include <iostream>
10 #include <sstream>
11 #include <string>
12 
13 namespace art {
14 
15  struct DebugTasksValue {
17 
18  int
19  operator()() const noexcept
20  {
21  return value_.load();
22  }
23 
24  std::atomic<char const*> cvalue_;
25  std::atomic<int> value_;
26  };
27 
29 
30  namespace detail {
32  public:
33  MessageAccumulator(char const banner_prefix,
34  std::string const& fcn_name,
35  std::string const& pretty_fcn_name,
36  ScheduleID schedule_id = ScheduleID{},
37  std::string const& step = std::string(6, ' '));
39 
40  template <typename T>
41  decltype(auto)
42  operator<<(T const& t)
43  {
44  usr_msg_ << t;
45  return std::forward<decltype(*this)>(*this);
46  }
47 
48  private:
49  std::ostringstream buffer_;
50  std::ostringstream usr_msg_;
51  };
52  }
53 }
54 
55 #define TDEBUG(LEVEL) \
56  if ((LEVEL) <= art::debugTasks()) \
57  std::cerr
58 
59 #define TDEBUG_BEGIN_FUNC_SI(LEVEL, SI) \
60  if ((LEVEL) <= art::debugTasks()) \
61  art::detail::MessageAccumulator( \
62  '-', __func__, __PRETTY_FUNCTION__, SI, "Begin")
63 
64 #define TDEBUG_END_FUNC_SI(LEVEL, SI) \
65  if ((LEVEL) <= art::debugTasks()) \
66  art::detail::MessageAccumulator('-', __func__, __PRETTY_FUNCTION__, SI, "End")
67 
68 #define TDEBUG_FUNC_SI(LEVEL, SI) \
69  if ((LEVEL) <= art::debugTasks()) \
70  art::detail::MessageAccumulator('-', __func__, __PRETTY_FUNCTION__, SI)
71 
72 #define TDEBUG_FUNC(LEVEL) \
73  if ((LEVEL) <= art::debugTasks()) \
74  art::detail::MessageAccumulator('-', __func__, __PRETTY_FUNCTION__)
75 
76 #define TDEBUG_TASK_SI(LEVEL, SI) \
77  if ((LEVEL) <= art::debugTasks()) \
78  art::detail::MessageAccumulator('=', __func__, __PRETTY_FUNCTION__, SI)
79 
80 #define TDEBUG_TASK(LEVEL) \
81  if ((LEVEL) <= art::debugTasks()) \
82  art::detail::MessageAccumulator('=', __func__, __PRETTY_FUNCTION__)
83 
84 #define TDEBUG_BEGIN_TASK_SI(LEVEL, SI) \
85  if ((LEVEL) <= art::debugTasks()) \
86  art::detail::MessageAccumulator( \
87  '=', __func__, __PRETTY_FUNCTION__, SI, "Begin")
88 
89 #define TDEBUG_END_TASK_SI(LEVEL, SI) \
90  if ((LEVEL) <= art::debugTasks()) \
91  art::detail::MessageAccumulator('=', __func__, __PRETTY_FUNCTION__, SI, "End")
92 
93 #endif /* art_Utilities_TaskDebugMacros_h */
94 
95 // Local Variables:
96 // mode: c++
97 // End:
std::string string
Definition: nybbler.cc:12
DebugTasksValue debugTasks
std::atomic< int > value_
std::atomic< char const * > cvalue_
int operator()() const noexcept