diff --git a/include/ircd/json/util.h b/include/ircd/json/util.h index b8ff96542..7c6c30b73 100644 --- a/include/ircd/json/util.h +++ b/include/ircd/json/util.h @@ -92,9 +92,8 @@ __attribute__((always_inline, gnu_inline, artificial)) ircd::json::debug_valid_output(const string_view &in, const size_t &expected) { - #ifdef RB_DEBUG - valid_output(in, expected); - #endif + if constexpr(RB_DEBUG_LEVEL) + valid_output(in, expected); } constexpr ircd::json::name_hash_t diff --git a/ircd/client.cc b/ircd/client.cc index 32904dbdf..7665aa3d4 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -484,14 +484,17 @@ try dock.notify_all(); }}; - #ifdef RB_DEBUG - util::timer timer; - log::debug + util::timer timer { - log, "%s enter", - loghead(*client), + RB_DEBUG_LEVEL }; - #endif + + if constexpr(RB_DEBUG_LEVEL) + log::debug + { + log, "%s enter", + loghead(*client), + }; if(!client->main()) { @@ -499,15 +502,16 @@ try return; } - #ifdef RB_DEBUG - char buf[64]; - log::debug + if constexpr(RB_DEBUG_LEVEL) { - log, "%s leave %s", - loghead(*client), - pretty(buf, timer.at(), true) - }; - #endif + char buf[64]; + log::debug + { + log, "%s leave %s", + loghead(*client), + pretty(buf, timer.at(), true) + }; + } client->async(); } diff --git a/ircd/db.cc b/ircd/db.cc index 8c35310ee..799d38df4 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -4405,13 +4405,12 @@ ircd::db::throw_on_error::throw_on_error(const rocksdb::Status &status) case Status::kNotFound: throw not_found{}; - #ifdef RB_DEBUG //case Status::kCorruption: case Status::kNotSupported: case Status::kInvalidArgument: - debugtrap(); + if constexpr(RB_DEBUG_LEVEL) + debugtrap(); [[fallthrough]]; - #endif [[unlikely]] default: @@ -4556,9 +4555,10 @@ ircd::db::commit(database &d, rocksdb::WriteBatch &batch, const rocksdb::WriteOptions &opts) { - #ifdef RB_DEBUG - ircd::timer timer; - #endif + ircd::timer timer + { + RB_DEBUG_LEVEL + }; const std::lock_guard lock{d.write_mutex}; const ctx::uninterruptible ui; @@ -4568,17 +4568,18 @@ ircd::db::commit(database &d, d.d->Write(opts, &batch) }; - #ifdef RB_DEBUG - char dbuf[192]; - log::debug + if constexpr(RB_DEBUG_LEVEL) { - log, "[%s] %lu COMMIT %s in %ld$us", - d.name, - sequence(d), - debug(dbuf, batch), - timer.at().count() - }; - #endif + char dbuf[192]; + log::debug + { + log, "[%s] %lu COMMIT %s in %ld$us", + d.name, + sequence(d), + debug(dbuf, batch), + timer.at().count() + }; + } } ircd::string_view diff --git a/ircd/db_database.cc b/ircd/db_database.cc index 021bf82f8..a6cb3989f 100644 --- a/ircd/db_database.cc +++ b/ircd/db_database.cc @@ -1042,9 +1042,8 @@ try opts->stats_dump_period_sec = 0; // Disable noise opts->statistics = this->stats; - #ifdef RB_DEBUG - opts->dump_malloc_stats = true; - #endif + if constexpr(RB_DEBUG_LEVEL) + opts->dump_malloc_stats = true; // Disables the timer to delete unused files; this operation occurs // instead with our compaction operations so we don't need to complicate. diff --git a/ircd/fs.cc b/ircd/fs.cc index a6e8ba16a..f5c2b28d6 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -273,17 +273,19 @@ ircd::fs::support::dump_info() support }; - #ifdef RB_DEBUG - const unique_mutable_buffer buf + if constexpr(RB_DEBUG_LEVEL) { - PATH_MAX_LEN + 1 - }; + const unique_mutable_buffer buf + { + PATH_MAX_LEN + 1 + }; - log::debug - { - log, "Current working directory: `%s'", cwd(buf) - }; - #endif + log::debug + { + log, "Current working directory: `%s'", + cwd(buf) + }; + } } bool diff --git a/ircd/info.cc b/ircd/info.cc index c4f6b192c..06a7cb0d3 100644 --- a/ircd/info.cc +++ b/ircd/info.cc @@ -933,7 +933,6 @@ ircd::info::dump_sys_info() fs::support::dump_info(); // Additional detected system parameters - //#ifdef RB_DEBUG char buf[2][48]; log::logf { @@ -948,7 +947,6 @@ ircd::info::dump_sys_info() between(thp_enable, '[', ']'), thp_size, }; - //#endif } #ifdef HAVE_SYS_UTSNAME_H diff --git a/ircd/mods_ldso.cc b/ircd/mods_ldso.cc index 66f3b1f38..f75b6679c 100644 --- a/ircd/mods_ldso.cc +++ b/ircd/mods_ldso.cc @@ -416,6 +416,7 @@ ircd_dl_signal_exception(int errcode, // #ifdef HAVE_DLFCN_H #ifdef IRCD_MODS_HOOK_DLSYM +#define RB_DEBUG_MODS_HOOK_DLSYM 0 extern "C" void * __libc_dlsym(void *, const char *); @@ -424,14 +425,13 @@ extern "C" void * dlsym(void *const handle, const char *const symbol) { - #ifdef RB_DEBUG_MODS_HOOK_DLSYM - ircd::log::debug - { - ircd::mods::log, "handle:%p symbol lookup '%s'", - handle, - symbol - }; - #endif + if constexpr(RB_DEBUG_MODS_HOOK_DLSYM) + ircd::log::debug + { + ircd::mods::log, "handle:%p symbol lookup '%s'", + handle, + symbol + }; return __libc_dlsym(handle, symbol); } diff --git a/ircd/net.cc b/ircd/net.cc index 53e0b3ffa..04727f6c1 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -2420,25 +2420,26 @@ noexcept try if(timedout && ec == errc::operation_canceled) ec = make_error_code(errc::timed_out); - #ifdef RB_DEBUG - const auto *const current_cipher + if constexpr(RB_DEBUG_LEVEL) { - !ec? - openssl::current_cipher(*this): - nullptr - }; + const auto *const current_cipher + { + !ec? + openssl::current_cipher(*this): + nullptr + }; - char ecbuf[64]; - log::debug - { - log, "%s handshake cipher:%s %s", - loghead(*this), - current_cipher? - openssl::name(*current_cipher): - ""_sv, - string(ecbuf, ec) - }; - #endif + char ecbuf[64]; + log::debug + { + log, "%s handshake cipher:%s %s", + loghead(*this), + current_cipher? + openssl::name(*current_cipher): + ""_sv, + string(ecbuf, ec) + }; + } // Toggles the behavior of non-async functions; see func comment if(!ec) @@ -2608,16 +2609,17 @@ noexcept try } } - #ifdef RB_DEBUG - thread_local char buf[16_KiB]; - const critical_assertion ca; - log::debug + if constexpr(RB_DEBUG_LEVEL) { - log, "verify[%s] %s", - common_name(opts), - openssl::print_subject(buf, cert) - }; - #endif + thread_local char buf[16_KiB]; + const critical_assertion ca; + log::debug + { + log, "verify[%s] %s", + common_name(opts), + openssl::print_subject(buf, cert) + }; + } return true; } diff --git a/ircd/net_listener.cc b/ircd/net_listener.cc index 4755a8d7a..cb4355d25 100644 --- a/ircd/net_listener.cc +++ b/ircd/net_listener.cc @@ -726,28 +726,29 @@ noexcept try assert(it != end(handshaking)); assert(openssl::get_app_data(*sock) == sock.get()); - #ifdef RB_DEBUG - const auto *const current_cipher + if constexpr(RB_DEBUG_LEVEL) { - !ec? - openssl::current_cipher(*sock): - nullptr - }; + const auto *const current_cipher + { + !ec? + openssl::current_cipher(*sock): + nullptr + }; - char ecbuf[64]; - log::debug - { - log, "%s %s handshook(%zd:%zu) cipher:%s %s", - loghead(*sock), - loghead(*this), - std::distance(cbegin(handshaking), it), - handshaking.size(), - current_cipher? - openssl::name(*current_cipher): - ""_sv, - string(ecbuf, ec) - }; - #endif + char ecbuf[64]; + log::debug + { + log, "%s %s handshook(%zd:%zu) cipher:%s %s", + loghead(*sock), + loghead(*this), + std::distance(cbegin(handshaking), it), + handshaking.size(), + current_cipher? + openssl::name(*current_cipher): + ""_sv, + string(ecbuf, ec) + }; + } handshaking.erase(it); openssl::set_app_data(*sock, nullptr); diff --git a/ircd/resource.cc b/ircd/resource.cc index 9dd0e72f1..eec3e9caa 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -1361,32 +1361,33 @@ ircd::resource::response::response(client &client, eptr = std::current_exception(); } - #ifdef RB_DEBUG - const log::level level + if constexpr(RB_DEBUG_LEVEL) { - http::severity(http::category(code)) - }; + const log::level level + { + http::severity(http::category(code)) + }; - log::logf - { - log, level, - "%s HTTP %u `%s' %s in %s; %s content-length:%s head-length:%zu %s%s", - loghead(client), - uint(code), - client.request.head.path, - http::status(code), - rtime, - content_type, - ssize_t(content_length) >= 0? - lex_cast(content_length): - "chunked"_sv, - wrote_head, - eptr? - "error:"_sv: - string_view{}, - what(eptr) - }; - #endif + log::logf + { + log, level, + "%s HTTP %u `%s' %s in %s; %s content-length:%s head-length:%zu %s%s", + loghead(client), + uint(code), + client.request.head.path, + http::status(code), + rtime, + content_type, + ssize_t(content_length) >= 0? + lex_cast(content_length): + "chunked"_sv, + wrote_head, + eptr? + "error:"_sv: + string_view{}, + what(eptr) + }; + } if(unlikely(eptr)) std::rethrow_exception(eptr);