Skip to content

Commit

Permalink
fixup! SILKit-1607: Fix performance
Browse files Browse the repository at this point in the history
  • Loading branch information
VLukasBecker committed Nov 8, 2024
1 parent a38a80a commit a25dad0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
15 changes: 0 additions & 15 deletions SilKit/source/services/logging/ILoggerInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ class LoggerMessage
{
}

template <typename... Args>
void SetMessage(fmt::format_string<Args...> fmt, Args&&... args)
{
_msg = fmt::format(fmt, std::forward<Args>(args)...);
}

template <typename... Args>
void FormatMessage(fmt::format_string<Args...> fmt, Args&&... args)
Expand Down Expand Up @@ -126,21 +121,11 @@ class LoggerMessage
return _keyValues;
}

bool HasKeyValues() const
{
return !_keyValues.empty();
}

auto GetMsgString() const -> const std::string&
{
return _msg;
}

auto GetLogger() const -> ILoggerInternal*
{
return _logger;
}

void Dispatch()
{
if (_logger->GetLogLevel() <= _level)
Expand Down
6 changes: 3 additions & 3 deletions SilKit/source/services/logging/MessageTracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void TraceRx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add

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

auto virtualTimeStamp = GetTimestamp(msg);
Expand All @@ -80,7 +80,7 @@ void TraceTx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add

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

lm.FormatKeyValue(Logging::Keys::msg, "{}", msg);
Expand Down
16 changes: 8 additions & 8 deletions SilKit/source/services/orchestration/SystemStateTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("Updating participant status");
lm.SetKeyValue(Log::Keys::participantName, participantName);
lm.SetKeyValue(Log::Keys::oldParticipantState, fmt::format("{}", oldParticipantState));
lm.SetKeyValue(Log::Keys::newParticipantState, fmt::format("{}", newParticipantState));
lm.FormatKeyValue(Log::Keys::oldParticipantState, "{}", oldParticipantState);
lm.FormatKeyValue(Log::Keys::newParticipantState, "{}", newParticipantState);
lm.Dispatch();
}
// Check if transition from the old to the new participant state is valid
Expand All @@ -155,8 +155,8 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
Log::LoggerMessage lm{_logger, logLevel};
lm.SetMessage("SystemMonitor detected invalid ParticipantState transition!");
lm.SetKeyValue(Log::Keys::participantName, participantName);
lm.SetKeyValue(Log::Keys::oldParticipantState, fmt::format("{}", oldParticipantState));
lm.SetKeyValue(Log::Keys::newParticipantState, fmt::format("{}", newParticipantState));
lm.FormatKeyValue(Log::Keys::oldParticipantState, "{}", oldParticipantState);
lm.FormatKeyValue(Log::Keys::newParticipantState, "{}", newParticipantState);
lm.SetKeyValue(Log::Keys::enterTime, FormatTimePoint(newParticipantStatus.enterTime));
lm.SetKeyValue(Log::Keys::enterReason, newParticipantStatus.enterReason);
lm.Dispatch();
Expand Down Expand Up @@ -195,8 +195,8 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("Computed new system state update!");
lm.SetKeyValue(Log::Keys::participantName, participantName);
lm.SetKeyValue(Log::Keys::oldParticipantState, fmt::format("{}", oldSystemState));
lm.SetKeyValue(Log::Keys::newParticipantState, fmt::format("{}", newSystemState));
lm.FormatKeyValue(Log::Keys::oldParticipantState, "{}", oldSystemState);
lm.FormatKeyValue(Log::Keys::newParticipantState, "{}", newSystemState);
lm.Dispatch();
}

Expand All @@ -205,8 +205,8 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("The system state has changed!");
lm.SetKeyValue(Log::Keys::participantName, participantName);
lm.SetKeyValue(Log::Keys::oldParticipantState, fmt::format("{}", oldSystemState));
lm.SetKeyValue(Log::Keys::newParticipantState, fmt::format("{}", newSystemState));
lm.FormatKeyValue(Log::Keys::oldParticipantState, "{}", oldSystemState);
lm.FormatKeyValue(Log::Keys::newParticipantState, "{}", newSystemState);
lm.Dispatch();

_systemState = newSystemState;
Expand Down
8 changes: 4 additions & 4 deletions SilKit/source/services/orchestration/TimeSyncService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ void TimeSyncService::ExecuteSimStep(std::chrono::nanoseconds timePoint, std::ch
{
Logging::LoggerMessage lm{_logger, Logging::Level::Trace};
lm.SetMessage("Starting next Simulation Step.");
lm.SetKeyValue(Logging::Keys::waitingTime, fmt::format("{}", std::chrono::duration_cast<DoubleMSecs>(_waitTimeMonitor.CurrentDuration()).count()));
lm.SetKeyValue(Logging::Keys::virtualTimeNS, fmt::format("{}", timePoint.count()));
lm.FormatKeyValue(Logging::Keys::waitingTime, "{}", std::chrono::duration_cast<DoubleMSecs>(_waitTimeMonitor.CurrentDuration()).count());
lm.FormatKeyValue(Logging::Keys::virtualTimeNS, "{}", timePoint.count());
lm.Dispatch();
}

Expand Down Expand Up @@ -536,8 +536,8 @@ void TimeSyncService::LogicalSimStepCompleted(std::chrono::duration<double, std:
_simStepCounterMetric->Add(1);
Logging::LoggerMessage lm{_logger, Logging::Level::Trace};
lm.SetMessage("Finished Simulation Step.");
lm.SetKeyValue(Logging::Keys::executionTime, fmt::format("{}", logicalSimStepTimeMs.count()));
lm.SetKeyValue(Logging::Keys::virtualTimeNS, fmt::format("{}", Now().count()));
lm.FormatKeyValue(Logging::Keys::executionTime, "{}", logicalSimStepTimeMs.count());
lm.FormatKeyValue(Logging::Keys::virtualTimeNS, "{}", Now().count());
lm.Dispatch();
_waitTimeMonitor.StartMeasurement();
}
Expand Down

0 comments on commit a25dad0

Please sign in to comment.