Skip to content

Commit 0626b90

Browse files
committed
multiprocess: align our logging with libmultiprocess's
Without this change, logging (even if unused) may account for a substantial portion of bitcoin-node's and/or client's runtime cpu usage, due to libmultiprocess's expensive message serialization. This (along with some recent upstream changes) avoids the overhead by opting out of log handling for messages that we're not interested in. Info, Warning, and Error are logged unconditionally to match our behavior elsewhere. See BCLog::Logger::GetCategoryLogLevel .
1 parent 9d06822 commit 0626b90

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/ipc/capnp/protocol.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,35 @@
3030
namespace ipc {
3131
namespace capnp {
3232
namespace {
33+
34+
BCLog::Level ConvertIPCLogLevel(mp::Log level)
35+
{
36+
switch (level) {
37+
case mp::Log::Trace: return BCLog::Level::Trace;
38+
case mp::Log::Debug: return BCLog::Level::Debug;
39+
case mp::Log::Info: return BCLog::Level::Info;
40+
case mp::Log::Warning: return BCLog::Level::Warning;
41+
case mp::Log::Error: return BCLog::Level::Error;
42+
case mp::Log::Raise: return BCLog::Level::Error;
43+
} // no default case, so the compiler can warn about missing cases
44+
45+
// Be conservative and assume that if MP ever adds a new log level, it
46+
// should only be shown at our most verbose level.
47+
return BCLog::Level::Trace;
48+
}
49+
50+
mp::Log GetRequestedIPCLogLevel()
51+
{
52+
if (LogAcceptCategory(BCLog::IPC, BCLog::Level::Trace)) return mp::Log::Trace;
53+
if (LogAcceptCategory(BCLog::IPC, BCLog::Level::Debug)) return mp::Log::Debug;
54+
55+
// Info, Warning, and Error are logged unconditionally
56+
return mp::Log::Info;
57+
}
58+
3359
void IpcLogFn(mp::LogMessage message)
3460
{
35-
LogDebug(BCLog::IPC, "%s\n", message.message);
61+
LogPrintLevel(BCLog::IPC, ConvertIPCLogLevel(message.level), "%s\n", message.message);
3662
if (message.level == mp::Log::Raise) throw Exception(message.message);
3763
}
3864

@@ -64,6 +90,7 @@ class CapnpProtocol : public Protocol
6490
mp::g_thread_context.thread_name = mp::ThreadName(exe_name);
6591
mp::LogOptions opts = {
6692
.log_fn = IpcLogFn,
93+
.log_level = GetRequestedIPCLogLevel()
6794
};
6895
m_loop.emplace(exe_name, std::move(opts), &m_context);
6996
if (ready_fn) ready_fn();
@@ -95,6 +122,7 @@ class CapnpProtocol : public Protocol
95122
util::ThreadRename("capnp-loop");
96123
mp::LogOptions opts = {
97124
.log_fn = IpcLogFn,
125+
.log_level = GetRequestedIPCLogLevel()
98126
};
99127
m_loop.emplace(exe_name, std::move(opts), &m_context);
100128
m_loop_ref.emplace(*m_loop);

0 commit comments

Comments
 (0)