From 716134186e1c07a41ea1ffe40847956fb9b5cf2a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 17 Feb 2023 19:10:06 -0800 Subject: [PATCH] Replace additional #ifdef debug related w/ if constexpr for regression visibility. --- include/ircd/m/media.h | 2 ++ include/ircd/net/acceptor.h | 2 ++ ircd/magick.cc | 25 +++++++++++++------------ ircd/net_listener.cc | 23 +++++++++++------------ matrix/media.cc | 28 ++++++++++++++-------------- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/include/ircd/m/media.h b/include/ircd/m/media.h index 9ca7db1b2..f7601c5e4 100644 --- a/include/ircd/m/media.h +++ b/include/ircd/m/media.h @@ -27,6 +27,8 @@ namespace ircd::m::media::file { using closure = std::function; + constexpr bool debug_read {false}; + room::id room_id(room::id::buf &out, const mxc &); room::id::buf room_id(const mxc &); diff --git a/include/ircd/net/acceptor.h b/include/ircd/net/acceptor.h index 35f3c890a..f98ff5167 100644 --- a/include/ircd/net/acceptor.h +++ b/include/ircd/net/acceptor.h @@ -37,6 +37,8 @@ ircd::net::acceptor IRCD_EXCEPTION(listener::error, error) IRCD_EXCEPTION(error, sni_warning) + static constexpr bool debug_alpn {false}; + static log::log log; static ios::descriptor accept_desc; static ios::descriptor handshake_desc; diff --git a/ircd/magick.cc b/ircd/magick.cc index 48a18c48d..877bcf13e 100644 --- a/ircd/magick.cc +++ b/ircd/magick.cc @@ -16,6 +16,8 @@ namespace ircd::magick struct display; struct transform; + constexpr bool debug_progress {false}; + [[noreturn]] static void handle_exception(const ExceptionType, const char *, const char *); static void handle_fatal(const ExceptionType, const char *, const char *) __attribute__((noreturn)); static void handle_error(const ExceptionType, const char *, const char *) noexcept; @@ -664,18 +666,17 @@ noexcept try // This debug message is very noisy, even for debug mode. Developer can // enable it at their discretion. - #ifdef IRCD_MAGICK_DEBUG_PROGRESS - log::debug - { - log, "job:%lu progress %2.2lf%% (%ld/%ld) cycles:%lu :%s", - job::cur.id, - (job::cur.tick / double(job::cur.ticks) * 100.0), - job::cur.tick, - job::cur.ticks, - job::cur.cycles, - job::cur.text, - }; - #endif + if constexpr(debug_progress) + log::debug + { + log, "job:%lu progress %2.2lf%% (%ld/%ld) cycles:%lu :%s", + job::cur.id, + (job::cur.tick / double(job::cur.ticks) * 100.0), + job::cur.tick, + job::cur.ticks, + job::cur.cycles, + job::cur.text, + }; check_cycles(job::cur); check_yield(job::cur); diff --git a/ircd/net_listener.cc b/ircd/net_listener.cc index cb4355d25..7623d5136 100644 --- a/ircd/net_listener.cc +++ b/ircd/net_listener.cc @@ -852,19 +852,18 @@ ircd::net::acceptor::handle_alpn(socket &socket, size(in), }; - #ifdef IRCD_NET_ACCEPTOR_DEBUG_ALPN - for(size_t i(0); i < size(in); ++i) - { - log::debug + if constexpr(debug_alpn) + for(size_t i(0); i < size(in); ++i) { - log, "%s ALPN protocol %zu of %zu: '%s'", - loghead(socket), - i, - size(in), - in[i], - }; - } - #endif IRCD_NET_ACCEPTOR_DEBUG_ALPN + log::debug + { + log, "%s ALPN protocol %zu of %zu: '%s'", + loghead(socket), + i, + size(in), + in[i], + }; + } //NOTE: proto == "h2" condition goes here for(const auto &proto : in) diff --git a/matrix/media.cc b/matrix/media.cc index 65cb006b5..0e9221f6a 100644 --- a/matrix/media.cc +++ b/matrix/media.cc @@ -396,20 +396,20 @@ ircd::m::media::file::read(const m::room &room, b64::decode(blk_decode_buf, blk_encoded) }; - #ifdef IRCD_M_MEDIA_FILE_DEBUG - log::debug - { - log, "File %s read event_idx:%lu events[fetched:%zu prefetched:%zu] encoded:%zu decoded:%zu total_encoded:%zu total_decoded:%zu", - string_view{room.room_id}, - it.event_idx(), - events_fetched, - events_prefetched, - size(blk_encoded), - size(blk), - encoding_bytes, - decoded_bytes, - }; - #endif + if constexpr(debug_read) + log::debug + { + log, "File %s read event_idx:%lu events[fetched:%zu prefetched:%zu] encoded:%zu decoded:%zu total_encoded:%zu total_decoded:%zu", + string_view{room.room_id}, + it.event_idx(), + events_fetched, + events_prefetched, + size(blk_encoded), + size(blk), + encoding_bytes, + decoded_bytes, + }; + assert(size(blk) == b64::decode_size(blk_encoded)); closure(blk);