26 #ifndef MLN_DEBUG_TRACE_HH
27 # define MLN_DEBUG_TRACE_HH
39 # include <mln/core/contract.hh>
41 # define mln_trace(S) \
42 mln::debug::trace mln_trace_(S); \
45 # define mln_trace_warning(S) \
46 mln::debug::trace::warning(S);
84 trace(
const std::string& scope);
89 static void warning(
const std::string& message);
99 static std::stack<std::clock_t> start_times_;
100 static std::stack<std::string> scopes_;
101 static unsigned max_tab_;
102 static bool is_quiet_;
106 # ifndef MLN_INCLUDE_ONLY
110 # ifndef MLN_WO_GLOBAL_VARS
116 std::stack<std::clock_t> trace::start_times_;
117 std::stack<std::string> trace::scopes_;
118 unsigned trace::max_tab_ = 0;
119 bool trace::is_quiet_ =
quiet;
121 # endif // ! MLN_WO_GLOBAL_VARS
133 start_times_.push(std::clock());
136 if ((
tab != 0) && (max_tab_ ==
tab))
137 std::cout << std::endl;
139 for (
unsigned i = 0; i <
tab; ++i)
141 std::cout << scope <<
" {";
153 std::string scope = scopes_.top();
156 bool has_inner_trace = (max_tab_ ==
tab);
159 if (!has_inner_trace)
160 for (
unsigned i = 0; i <
tab; ++i)
165 if (!has_inner_trace)
166 std::cout << scope <<
" ";
168 mln_assertion(! start_times_.empty());
169 std::clock_t now = std::clock();
171 if (start_times_.top() > now)
173 <<
"Warning: Clock skew detected (start time in the future)."
176 if (start_times_.top() < now)
180 << ((
float(now) -
float(start_times_.top())) / CLOCKS_PER_SEC)
186 if (has_inner_trace || (max_tab_ - tab > 1))
187 std::cout << std::endl;
210 std::cerr <<
"Warning: " << message << std::endl;
213 # endif // ! MLN_INCLUDE_ONLY
220 #endif // ! MLN_DEBUG_TRACE_HH