From 663b1bb9a7013b7975227095169960c28fdf1a7a Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Tue, 9 Nov 2021 01:07:33 +0800 Subject: [PATCH] [log] check log level before dumping packet to string (#7138) `otDump` will currently always dump to string and use the log level to decide whether to print it. Since this function is in the key path of packet handling, this behavior reduces network throughput. This commit adds a log level check to fix the issue. --- src/core/common/logging.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/common/logging.cpp b/src/core/common/logging.cpp index 24df5066a..525a41510 100644 --- a/src/core/common/logging.cpp +++ b/src/core/common/logging.cpp @@ -297,6 +297,8 @@ void otDump(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aId, const size_t idLen = strlen(aId) + kFixedStringPart; ot::String string; + VerifyOrExit(otLoggingGetLevel() >= aLogLevel); + for (size_t i = 0; i < (kWidth - idLen) / 2; i++) { string.Append("="); @@ -325,6 +327,9 @@ void otDump(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aId, const } otLogDump(aLogLevel, aLogRegion, "%s", string.AsCString()); + +exit: + return; } #else // OPENTHREAD_CONFIG_LOG_PKT_DUMP void otDump(otLogLevel, otLogRegion, const char *, const void *, const size_t)