Skip to content

Commit

Permalink
SILKit-1607: Fix performance
Browse files Browse the repository at this point in the history
  • Loading branch information
VLukasBecker committed Nov 7, 2024
1 parent 1ef8b75 commit a38a80a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
28 changes: 24 additions & 4 deletions SilKit/source/services/logging/ILoggerInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,38 @@ class LoggerMessage
template <typename... Args>
void FormatMessage(fmt::format_string<Args...> fmt, Args&&... args)
{
_msg = fmt::format(fmt, args...);
if (_logger->GetLogLevel() <= _level)
{
_msg = fmt::format(fmt, std::forward<Args>(args)...);
}
}

void SetMessage(std::string newMsg)
{
_msg = std::move(newMsg);
if (_logger->GetLogLevel() <= _level)
{
_msg = std::move(newMsg);
}
}


template <typename Key, typename... Args>
void FormatKeyValue(Key&& key, fmt::format_string<Args...> fmt, Args&&... args)
{
if (_logger->GetLogLevel() <= _level)
{
auto&& formattedValue = fmt::format(fmt, std::forward<Args>(args)...);
_keyValues.emplace_back(std::forward<Key>(key), formattedValue);
}
}

template<typename Key, typename Value>
template <typename Key, typename Value>
void SetKeyValue(Key&& key, Value&& value)
{
_keyValues.push_back({std::forward<Key>(key), std::forward<Value>(value)});
if (_logger->GetLogLevel() <= _level)
{
_keyValues.emplace_back(std::forward<Key>(key), std::forward<Value>(value));
}
}

auto GetLevel() const -> Level
Expand Down
14 changes: 7 additions & 7 deletions SilKit/source/services/logging/MessageTracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ void TraceRx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add

for (const auto& pair : addr->GetServiceDescriptor().to_keyValues())
{
lm.SetKeyValue(pair.first, pair.second);
lm.FormatKeyValue(pair.first, pair.second);
}
lm.SetKeyValue(Logging::Keys::from, from.GetParticipantName());
lm.SetKeyValue(Logging::Keys::msg, (fmt::format("{}", msg)));
lm.FormatKeyValue(Logging::Keys::from, from.GetParticipantName());
lm.FormatKeyValue(Logging::Keys::msg, "{}", msg);

auto virtualTimeStamp = GetTimestamp(msg);
if (virtualTimeStamp != std::chrono::nanoseconds::duration::min())
{
lm.SetKeyValue(Logging::Keys::virtualTimeNS, (fmt::format("{}", virtualTimeStamp.count())));
lm.FormatKeyValue(Logging::Keys::virtualTimeNS, "{}", virtualTimeStamp.count());
}

lm.Dispatch();
Expand All @@ -80,15 +80,15 @@ void TraceTx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add

for (const auto& pair : addr->GetServiceDescriptor().to_keyValues())
{
lm.SetKeyValue(pair.first, pair.second);
lm.FormatKeyValue(pair.first, pair.second);
}

lm.SetKeyValue(Logging::Keys::msg, (fmt::format("{}", msg)));
lm.FormatKeyValue(Logging::Keys::msg, "{}", msg);

auto virtualTimeStamp = GetTimestamp(msg);
if (virtualTimeStamp != std::chrono::nanoseconds::duration::min())
{
lm.SetKeyValue(Logging::Keys::virtualTimeNS, (fmt::format("{}", virtualTimeStamp.count())));
lm.FormatKeyValue(Logging::Keys::virtualTimeNS, "{}", virtualTimeStamp.count());
}
lm.Dispatch();
}
Expand Down

0 comments on commit a38a80a

Please sign in to comment.