50 void dbgPrint0_tail(FILE *out,
bool addErrno,
bool addBacktrace)
noexcept;
52 void dbgPrint1_prefix(FILE *out,
const char *msg,
const char *msgsep)
noexcept;
55 template <
typename... Args>
56 inline __attribute__((always_inline))
57 void dbgPrint0(FILE *out,
bool addErrno,
bool addBacktrace, std::string_view format,
const Args &...args)
noexcept {
59 jau::impl::dbgPrint0_tail(out, addErrno, addBacktrace);
63 template <
typename... Args>
64 inline __attribute__((always_inline))
65 void dbgPrint1(FILE *out,
bool printPrefix,
const char *msg, std::string_view format,
const Args &...args)
noexcept {
67 jau::impl::dbgPrint1_prefix(out, msg,
": ");
69 jau::impl::dbgPrint0(out,
false,
false, format, args...);
73 template <
typename... Args>
74 inline __attribute__((always_inline))
75 void dbgPrint2(FILE *out,
const char *msg,
bool addErrno,
bool addBacktrace,
const char *func,
const char *file,
const int line,
76 std::string_view format,
const Args &...args)
noexcept {
77 jau::impl::dbgPrint1_prefix(out, msg,
" ");
78 ::fprintf(stderr,
"@ %s:%d %s: ", file, line, func);
79 jau::impl::dbgPrint0(out, addErrno, addBacktrace, format, args...);
83#define jau_dbgPrint1(out, printPrefix, msg, fmt, ...) \
84 jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
85 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
87#define jau_dbgPrint1Line(out, printPrefix, msg, fmt, ...) \
88 jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
89 static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
91#define jau_dbgPrint2(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...) \
92 jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
93 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
95#define jau_dbgPrint2Line(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...) \
96 jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
97 static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
100#define jau_DBG_PRINT(fmt, ...) { if( jau::environment::get().debug ) { jau_dbgPrint1(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
101#define jau_DBG_PRINT_LINE(fmt, ...) { if( jau::environment::get().debug ) { jau_dbgPrint1Line(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
104#define jau_DBG_JNI_PRINT(...) { if( jau::environment::get().debug_jni ) { jau_dbgPrint1(stderr, true, "Debug", __VA_ARGS__); } }
107#define jau_DBG_WARN_PRINT(...) { if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Warning", false , false , __func__, __FILE__, __LINE__, __VA_ARGS__); } }
110#define jau_DBG_ERR_PRINT(...) { if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Debug", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); } }
118#define jau_WORDY_PRINT(...) { if( jau::environment::get().verbose ) { jau_dbgPrint1(stderr, true, "Wordy", __VA_ARGS__); } }
120#define jau_PERF_TS_T0_BASE() const uint64_t _t0 = jau::getCurrentMilliseconds()
122#define jau_PERF_TS_TD_BASE(m) { const uint64_t _td = jau::getCurrentMilliseconds() - _t0; \
123 fprintf(stderr, "[%s] PERF %s done in %d ms,\n", jau::to_decstring(jau::environment::getElapsedMillisecond(), ',', 9).c_str(), (m), (int)_td); }
125 #define jau_PERF_TS_T0() jau_PERF_TS_T0_BASE()
126 #define jau_PERF_TS_TD(m) jau_PERF_TS_TD_BASE(m)
128 #define jau_PERF_TS_T0()
129 #define jau_PERF_TS_TD(m)
132 #define jau_PERF2_TS_T0() jau_PERF_TS_T0_BASE()
133 #define jau_PERF2_TS_TD(m) jau_PERF_TS_TD_BASE(m)
135 #define jau_PERF2_TS_T0()
136 #define jau_PERF2_TS_TD(m)
139 #define jau_PERF3_TS_T0() jau_PERF_TS_T0_BASE()
140 #define jau_PERF3_TS_TD(m) jau_PERF_TS_TD_BASE(m)
142 #define jau_PERF3_TS_T0()
143 #define jau_PERF3_TS_TD(m)
147#define jau_ABORT(...) { jau_dbgPrint2(stderr, "ABORT", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); abort(); }
150#define jau_ERR_PRINT(...) { jau_dbgPrint2(stderr, "Error", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); }
153#define jau_ERR_PRINT2(...) { jau_dbgPrint2(stderr, "Error", true , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
156#define jau_ERR_PRINT3(...) { jau_dbgPrint2(stderr, "Error", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); }
159#define jau_IRQ_PRINT(...) { jau_dbgPrint2(stderr, "Interrupted", true , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
162#define jau_WARN_PRINT(...) { jau_dbgPrint2(stderr, "Warning", false , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
165#define jau_INFO_PRINT(fmt, ...) { jau_dbgPrint1(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }
166#define jau_INFO_PRINT_LINE(fmt, ...) { jau_dbgPrint1Line(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }
169#define jau_PLAIN_PRINT(printPrefix, fmt, ...) { jau_dbgPrint1(stderr, (printPrefix), nullptr, fmt __VA_OPT__(,) __VA_ARGS__); }
172#define jau_COND_PRINT(C, ...) { if( C ) { jau::impl::dbgPrint0(stderr, false, false, __VA_ARGS__); } }
182 template <
typename... Args>
183 inline __attribute__((always_inline))
184 int
fprintf_td(const uint64_t elapsed_ms, FILE* stream,
std::string_view format, const Args &...args) noexcept {
185 int res = ::fprintf(stream,
"[%s] ",
jau::to_decstring(elapsed_ms,
',', 9).c_str());
199 template <
typename... Args>
200 inline __attribute__((always_inline))
201 int
fprintf_td(FILE* stream,
std::string_view format, const Args &...args) noexcept {
207 ::fprintf(stderr,
"%s: Start: %zu elements\n",
prefix.c_str(), (
size_t)list.size());
209 for (
auto it = list.begin(); it != list.end(); idx++) {
210 typename List::value_type & e = *it;
211 if (
nullptr != e ) {
212 ::fprintf(stderr,
"%s[%d]: useCount %zu, mem %p\n",
prefix.c_str(), idx, (
size_t)e.use_count(), e.get());
214 ::fprintf(stderr,
"%s[%d]: NULL\n",
prefix.c_str(), idx);
221#define jau_fprintf_td2(elapsed_ms, stream, fmt, ...) \
222 jau::fprintf_td((elapsed_ms), (stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
223 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
225#define jau_fprintf_td(stream, fmt, ...) \
226 jau::fprintf_td((stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
227 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...
std::string to_decstring(const value_type &v, const char separator='\'', const nsize_t min_width=0) noexcept
Produces a decimal integer string representation of an integral integer value with given radix.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
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...
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, std::string_view format, const Args &...args) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
void printSharedPtrList(const std::string &prefix, List &list) noexcept