49 template <
typename... Args>
50 void dbgPrint0(FILE *out,
bool addErrno,
bool addBacktrace, std::string_view format,
const Args &...args)
noexcept {
51 std::exception_ptr eptr;
55 ::fprintf(stderr,
"; last errno %d %s", errno, strerror(errno));
61 if (addErrno || addBacktrace) {
65 eptr = std::current_exception();
70 template <
typename... Args>
71 void dbgPrint1(FILE *out,
bool printPrefix,
const char *msg, std::string_view format,
const Args &...args)
noexcept {
73 std::exception_ptr eptr;
83 eptr = std::current_exception();
90 template <
typename... Args>
91 void dbgPrint2(FILE *out,
const char *msg,
bool addErrno,
bool addBacktrace,
const char *
func,
const char *file,
const int line,
92 std::string_view format,
const Args &...args)
noexcept {
93 std::exception_ptr eptr;
102 ::fprintf(stderr,
"@ %s:%d %s: ", file, line,
func);
104 eptr = std::current_exception();
111 #define jau_dbgPrint1(out, printPrefix, msg, fmt, ...) \
112 jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
113 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
115 #define jau_dbgPrint1Line(out, printPrefix, msg, fmt, ...) \
116 jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
117 static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
119 #define jau_dbgPrint2(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...) \
120 jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
121 static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
123 #define jau_dbgPrint2Line(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...) \
124 jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
125 static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
128 #define DBG_PRINT(fmt, ...) { if( jau::environment::get().debug ) { jau_dbgPrint1(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
129 #define DBG_PRINT_LINE(fmt, ...) { if( jau::environment::get().debug ) { jau_dbgPrint1Line(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
132 #define DBG_JNI_PRINT(...) { if( jau::environment::get().debug_jni ) { jau_dbgPrint1(stderr, true, "Debug", __VA_ARGS__); } }
135 #define DBG_WARN_PRINT(...) { if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Warning", false , false , __func__, __FILE__, __LINE__, __VA_ARGS__); } }
138 #define DBG_ERR_PRINT(...) { if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Debug", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); } }
146 #define WORDY_PRINT(...) { if( jau::environment::get().verbose ) { jau_dbgPrint1(stderr, true, "Wordy", __VA_ARGS__); } }
148 #define PERF_TS_T0_BASE() const uint64_t _t0 = jau::getCurrentMilliseconds()
150 #define PERF_TS_TD_BASE(m) { const uint64_t _td = jau::getCurrentMilliseconds() - _t0; \
151 fprintf(stderr, "[%s] PERF %s done in %d ms,\n", jau::to_decstring(jau::environment::getElapsedMillisecond(), ',', 9).c_str(), (m), (int)_td); }
153 #define PERF_TS_T0() PERF_TS_T0_BASE()
154 #define PERF_TS_TD(m) PERF_TS_TD_BASE(m)
157 #define PERF_TS_TD(m)
159 #ifdef PERF2_PRINT_ON
160 #define PERF2_TS_T0() PERF_TS_T0_BASE()
161 #define PERF2_TS_TD(m) PERF_TS_TD_BASE(m)
163 #define PERF2_TS_T0()
164 #define PERF2_TS_TD(m)
166 #ifdef PERF3_PRINT_ON
167 #define PERF3_TS_T0() PERF_TS_T0_BASE()
168 #define PERF3_TS_TD(m) PERF_TS_TD_BASE(m)
170 #define PERF3_TS_T0()
171 #define PERF3_TS_TD(m)
175 #define ABORT(...) { jau_dbgPrint2(stderr, "ABORT", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); abort(); }
178 #define ERR_PRINT(...) { jau_dbgPrint2(stderr, "Error", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); }
181 #define ERR_PRINT2(...) { jau_dbgPrint2(stderr, "Error", true , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
184 #define ERR_PRINT3(...) { jau_dbgPrint2(stderr, "Error", true , true , __func__, __FILE__, __LINE__, __VA_ARGS__); }
187 #define IRQ_PRINT(...) { jau_dbgPrint2(stderr, "Interrupted", true , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
190 #define WARN_PRINT(...) { jau_dbgPrint2(stderr, "Warning", false , false , __func__, __FILE__, __LINE__, __VA_ARGS__); }
193 #define INFO_PRINT(fmt, ...) { jau_dbgPrint1(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }
194 #define INFO_PRINT_LINE(fmt, ...) { jau_dbgPrint1Line(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }
197 #define PLAIN_PRINT(printPrefix, fmt, ...) { jau_dbgPrint1(stderr, (printPrefix), nullptr, fmt __VA_OPT__(,) __VA_ARGS__); }
206 template <
typename... Args>
207 int fprintf_td(
const uint64_t elapsed_ms, FILE* stream, std::string_view format,
const Args &...args)
noexcept {
209 std::exception_ptr eptr;
217 eptr = std::current_exception();
228 template <
typename... Args>
229 inline int fprintf_td(FILE* stream, std::string_view format,
const Args &...args)
noexcept {
234 #define COND_PRINT(C, ...) { if( C ) { jau::impl::dbgPrint0(stderr, false, false, __VA_ARGS__); } }
238 ::fprintf(stderr,
"%s: Start: %zu elements\n",
prefix.c_str(), (
size_t)list.size());
240 for (
auto it = list.begin(); it != list.end(); idx++) {
241 typename List::value_type & e = *it;
242 if (
nullptr != e ) {
243 ::fprintf(stderr,
"%s[%d]: useCount %zu, mem %p\n",
prefix.c_str(), idx, (
size_t)e.use_count(), e.get());
245 ::fprintf(stderr,
"%s[%d]: NULL\n",
prefix.c_str(), idx);
static uint64_t getElapsedMillisecond() noexcept
Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMilliseco...
bool handle_exception(std::exception_ptr eptr)
Handle given optional exception (nullable std::exception_ptr) and send std::exception::what() message...
std::string to_decstring(const value_type &v, const char separator=',', const nsize_t width=0) noexcept
Produce a decimal string representation of an integral integer value.
void dbgPrint0(FILE *out, bool addErrno, bool addBacktrace, std::string_view format, const Args &...args) noexcept
void dbgPrint2(FILE *out, const char *msg, bool addErrno, bool addBacktrace, const char *func, const char *file, const int line, std::string_view format, const Args &...args) noexcept
void dbgPrint1(FILE *out, bool printPrefix, const char *msg, std::string_view format, const Args &...args) noexcept
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
std::string get_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=1) noexcept
Returns a de-mangled backtrace string separated by newline excluding this function.
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.
std::string format_string(std::string_view format, const Args &...args) noexcept
Safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved str...
void printSharedPtrList(const std::string &prefix, List &list) noexcept