[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.
This commit is contained in:
Jiacheng Guo
2021-11-08 09:07:33 -08:00
committed by GitHub
parent 96a17b07ca
commit 663b1bb9a7
+5
View File
@@ -297,6 +297,8 @@ void otDump(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aId, const
size_t idLen = strlen(aId) + kFixedStringPart;
ot::String<kStringLineLength> 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)