50 void dbgPrint0_tail(FILE *out,
bool addErrno,
bool addBacktrace)
noexcept;
52 ssize_t dbgPrint_td_prefix(
const uint64_t elapsed_ms, FILE *out)
noexcept;
54 void dbgPrint1_prefix(FILE *out,
const char *msg,
const char *msgsep)
noexcept;
57 template <
typename... Args>
58 inline __attribute__((always_inline))
59 void dbgPrint0(FILE *out,
bool addErrno,
bool addBacktrace, std::string_view format,
const Args &...args)
noexcept {
61 jau::impl::dbgPrint0_tail(out, addErrno, addBacktrace);
65 template <
typename... Args>
66 inline __attribute__((always_inline))
67 void dbgPrint1(FILE *out,
bool printPrefix,
const char *msg, std::string_view format,
const Args &...args)
noexcept {
69 jau::impl::dbgPrint1_prefix(out, msg,
": ");
71 jau::impl::dbgPrint0(out,
false,
false, format, args...);
75 template <
typename... Args>
76 inline __attribute__((always_inline))
77 void dbgPrint2(FILE *out,
const char *msg,
bool addErrno,
bool addBacktrace,
const char *func,
const char *file,
const int line,
78 std::string_view format,
const Args &...args)
noexcept {
79 jau::impl::dbgPrint1_prefix(out, msg,
" ");
80 ::fprintf(stderr,
"@ %s:%d %s: ", file, line, func);
81 jau::impl::dbgPrint0(out, addErrno, addBacktrace, format, args...);
85#define jau_dbgPrint1(out, printPrefix, msg, fmt, ...) \
86 jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
87 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
89#define jau_dbgPrint1Line(out, printPrefix, msg, fmt, ...) \
90 jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
91 static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
93#define jau_dbgPrint2(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...) \
94 jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
95 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
97#define jau_dbgPrint2Line(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...) \
98 jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
99 static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
102#define jau_DBG_PRINT(fmt, ...) { if( jau::environment::get().debug ) { jau_dbgPrint1(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
103#define jau_DBG_PRINT_LINE(fmt, ...) { if( jau::environment::get().debug ) { jau_dbgPrint1Line(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
106#define jau_DBG_JNI_PRINT(...) { if( jau::environment::get().debug_jni ) { jau_dbgPrint1(stderr, true, "Debug", __VA_ARGS__); } }
109#define jau_DBG_WARN_PRINT(...) { if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Warning", false , false , __func__, __FILE__, __LINE__, __VA_ARGS__); } }
112#define jau_DBG_ERR_PRINT(...) { if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Debug", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); } }
120#define jau_WORDY_PRINT(...) { if( jau::environment::get().verbose ) { jau_dbgPrint1(stderr, true, "Wordy", __VA_ARGS__); } }
122#define jau_PERF_TS_T0_BASE() const uint64_t _t0 = jau::getCurrentMilliseconds()
124#define jau_PERF_TS_TD_BASE(m) { const uint64_t _td = jau::getCurrentMilliseconds() - _t0; \
125 fprintf(stderr, "[%s] PERF %s done in %d ms,\n", jau::to_decstring(jau::environment::getElapsedMillisecond(), ',', 9).c_str(), (m), (int)_td); }
127 #define jau_PERF_TS_T0() jau_PERF_TS_T0_BASE()
128 #define jau_PERF_TS_TD(m) jau_PERF_TS_TD_BASE(m)
130 #define jau_PERF_TS_T0()
131 #define jau_PERF_TS_TD(m)
134 #define jau_PERF2_TS_T0() jau_PERF_TS_T0_BASE()
135 #define jau_PERF2_TS_TD(m) jau_PERF_TS_TD_BASE(m)
137 #define jau_PERF2_TS_T0()
138 #define jau_PERF2_TS_TD(m)
141 #define jau_PERF3_TS_T0() jau_PERF_TS_T0_BASE()
142 #define jau_PERF3_TS_TD(m) jau_PERF_TS_TD_BASE(m)
144 #define jau_PERF3_TS_T0()
145 #define jau_PERF3_TS_TD(m)
149#define jau_ABORT(...) { jau_dbgPrint2(stderr, "ABORT", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); abort(); }
152#define jau_ERR_PRINT(...) { jau_dbgPrint2(stderr, "Error", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); }
155#define jau_ERR_PRINT2(...) { jau_dbgPrint2(stderr, "Error", true , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
158#define jau_ERR_PRINT3(...) { jau_dbgPrint2(stderr, "Error", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); }
161#define jau_IRQ_PRINT(...) { jau_dbgPrint2(stderr, "Interrupted", true , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
164#define jau_WARN_PRINT(...) { jau_dbgPrint2(stderr, "Warning", false , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
167#define jau_INFO_PRINT(fmt, ...) { jau_dbgPrint1(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }
168#define jau_INFO_PRINT_LINE(fmt, ...) { jau_dbgPrint1Line(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }
171#define jau_PLAIN_PRINT(printPrefix, fmt, ...) { jau_dbgPrint1(stderr, (printPrefix), nullptr, fmt __VA_OPT__(,) __VA_ARGS__); }
174#define jau_COND_PRINT(C, ...) { if( C ) { jau::impl::dbgPrint0(stderr, false, false, __VA_ARGS__); } }
186 template <
typename... Args>
187 inline __attribute__((always_inline))
188 ssize_t
fprintf_td(const uint64_t elapsed_ms, FILE* stream,
std::string_view format, const Args &...args) noexcept {
189 ssize_t res = jau::impl::dbgPrint_td_prefix(elapsed_ms, stream);
194 const int r = ::fputs(s.c_str(), stream);
196 return 0>r ? -1*res : res;
207 template <
typename... Args>
208 inline __attribute__((always_inline))
209 ssize_t
fprintf_td(FILE* stream,
std::string_view format, const Args &...args) noexcept {
220 template <
typename... Args>
221 inline __attribute__((always_inline))
222 ssize_t
fprintf_sc(FILE* stream,
std::string_view format, const Args &...args) noexcept {
224 const int r = ::fputs(s.c_str(), stream);
226 return 0>r ? -1*res : res;
231 ::fprintf(stderr,
"%s: Start: %zu elements\n",
prefix.c_str(), (
size_t)list.size());
233 for (
auto it = list.begin(); it != list.end(); idx++) {
234 typename List::value_type & e = *it;
235 if (
nullptr != e ) {
236 ::fprintf(stderr,
"%s[%d]: useCount %zu, mem %p\n",
prefix.c_str(), idx, (
size_t)e.use_count(), e.get());
238 ::fprintf(stderr,
"%s[%d]: NULL\n",
prefix.c_str(), idx);
245#define jau_fprintf_td2(elapsed_ms, stream, fmt, ...) \
246 jau::fprintf_td((elapsed_ms), (stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
247 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
249#define jau_fprintf_td(stream, fmt, ...) \
250 jau::fprintf_td((stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
251 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
253#define jau_printf(fmt, ...) \
254 jau::fprintf_sc((stdout), (fmt) __VA_OPT__(,) __VA_ARGS__); \
255 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
257#define jau_fprintf(stream, fmt, ...) \
258 jau::fprintf_sc((stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
259 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
static uint64_t getElapsedMillisecond() noexcept
Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMilliseco...
constexpr R clampCast(const T x, const T min_val, const T max_val) noexcept
Returns constrained integral value to lie between given min- and maximum value (w/ branching) in O(1)...
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
ssize_t fprintf_sc(FILE *stream, std::string_view format, const Args &...args) noexcept
Convenient secure fprintf() invocation using jau:format_string.
std::string format_string(std::string_view fmt, const Args &...args) noexcept
Safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved str...
ssize_t fprintf_td(const uint64_t elapsed_ms, FILE *stream, std::string_view format, const Args &...args) noexcept
Convenient secure fprintf() invocation, prepending the given elapsed_ms timestamp and using jau:forma...
void printSharedPtrList(const std::string &prefix, List &list) noexcept