Skip to content

Commit

Permalink
SILKit-1607: Fix PR requests
Browse files Browse the repository at this point in the history
  • Loading branch information
VLukasBecker committed Oct 28, 2024
1 parent 853181d commit 2352cdf
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 52 deletions.
5 changes: 2 additions & 3 deletions Demos/Can/CanDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int main(int argc, char** argv)
std::cout << "now=" << now << ", duration=" << duration << std::endl;
SendFrame(canController, logger);
std::this_thread::sleep_for(sleepTimePerTick);
},
},
5ms);
}
else
Expand All @@ -207,8 +207,7 @@ int main(int argc, char** argv)
[sleepTimePerTick](std::chrono::nanoseconds now, std::chrono::nanoseconds duration) {
std::cout << "now=" << now << ", duration=" << duration << std::endl;
std::this_thread::sleep_for(sleepTimePerTick);
},
5ms);
}, 5ms);
}

auto finalStateFuture = lifecycleService->StartLifecycle();
Expand Down
5 changes: 2 additions & 3 deletions Demos/PubSub/PubSubDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int main(int argc, char** argv)
PublishData(gpsPublisher, temperaturePublisher);
}
std::this_thread::sleep_for(1s);
},
},
1s);
}
else
Expand All @@ -242,8 +242,7 @@ int main(int argc, char** argv)
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(now);
std::cout << "now=" << nowMs.count() << "ms" << std::endl;
std::this_thread::sleep_for(1s);
},
1s);
}, 1s);
}

auto finalStateFuture = lifecycleService->StartLifecycle();
Expand Down
2 changes: 1 addition & 1 deletion SilKit/source/core/vasio/ConnectKnownParticipants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ConnectKnownParticipants::ConnectKnownParticipants(IIoContext& ioContext, IConne
}


void ConnectKnownParticipants::SetLogger(SilKit::Services::Logging::ILoggerInternal& logger)
void ConnectKnownParticipants::SetLogger(SilKit::Services::Logging::ILogger& logger)
{
SILKIT_ASSERT(_logger == nullptr);
_logger = &logger;
Expand Down
4 changes: 2 additions & 2 deletions SilKit/source/core/vasio/ConnectKnownParticipants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ConnectKnownParticipants
IConnectKnownParticipantsListener* _listener{nullptr};
ConnectKnownParticipantsSettings _settings;

SilKit::Services::Logging::ILoggerInternal* _logger{nullptr};
SilKit::Services::Logging::ILogger* _logger{nullptr};
std::promise<std::vector<VAsioPeerInfo>> _knownParticipants;

std::atomic<ConnectStage> _connectStage{ConnectStage::INVALID};
Expand All @@ -152,7 +152,7 @@ class ConnectKnownParticipants
IConnectKnownParticipantsListener& listener,
const ConnectKnownParticipantsSettings& settings);

void SetLogger(SilKit::Services::Logging::ILoggerInternal& logger);
void SetLogger(SilKit::Services::Logging::ILogger& logger);

void SetKnownParticipants(const std::vector<VAsioPeerInfo>& peerInfos);
void StartConnecting();
Expand Down
8 changes: 2 additions & 6 deletions SilKit/source/services/logging/ILoggerInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

#include "silkit/services/logging/ILogger.hpp"

#include "StructuredLoggingKeys.hpp"

#include "SilKitFmtFormatters.hpp"
#include "fmt/format.h"
#include <unordered_map>
Expand Down Expand Up @@ -90,12 +92,6 @@ class LoggerMessage
_msg = std::move(newMsg);
}

template <typename Key, typename... Value>
void FormatKeyValue(Key&& key, fmt::format_string<Value...> fmt)
{
_keyValues[std::forward<Key>(key)] = fmt::format(fmt);
}

template<typename Key, typename Value>
void SetKeyValue(Key&& key, Value&& value)
{
Expand Down
23 changes: 11 additions & 12 deletions SilKit/source/services/logging/MessageTracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,40 @@ void TraceRx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add
const Core::ServiceDescriptor& from)
{
Logging::LoggerMessage lm{logger, Logging::Level::Trace};
lm.SetMessage("Recv event");
lm.SetMessage("Recv message");

std::unordered_map<std::string, std::string> serviceDescriptorKVs{addr->GetServiceDescriptor().to_keyValues()};
for (const auto& pair : serviceDescriptorKVs)
for (const auto& pair : addr->GetServiceDescriptor().to_keyValues())
{
lm.SetKeyValue(pair.first, pair.second);
}
lm.SetKeyValue("msg", (fmt::format("{}", msg)));
lm.SetKeyValue(Logging::Keys::MSG, (fmt::format("{}", msg)));

auto virtualTimeStamp = GetTimestamp(msg);
if (virtualTimeStamp != std::chrono::nanoseconds::duration::min())
{
lm.SetKeyValue("VirtualTimeNS", (fmt::format("{}", virtualTimeStamp.count() )));
lm.SetKeyValue(Logging::Keys::VIRTUAL_TIME_NS, (fmt::format("{}", virtualTimeStamp.count())));
}
lm.SetKeyValue("From", from.GetParticipantName());
lm.SetKeyValue(Logging::Keys::FROM, from.GetParticipantName());
lm.Dispatch();
//Logging::Trace(logger, "Recv on {} from {}: {}", addr->GetServiceDescriptor(), from.GetParticipantName(), msg);
}

template <class SilKitMessageT>
void TraceTx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* addr, const SilKitMessageT& msg)
{
Logging::LoggerMessage lm{logger, Logging::Level::Trace};
lm.SetMessage("Send event");
std::unordered_map<std::string, std::string> serviceDescriptorKVs{addr->GetServiceDescriptor().to_keyValues()};
for (const auto& pair : serviceDescriptorKVs)
lm.SetMessage("Send message");

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

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

auto virtualTimeStamp = GetTimestamp(msg);
if (virtualTimeStamp != std::chrono::nanoseconds::duration::min())
{
lm.SetKeyValue("VirtualTimeNS", (fmt::format("{}", virtualTimeStamp.count() )));
lm.SetKeyValue(Logging::Keys::VIRTUAL_TIME_NS, (fmt::format("{}", virtualTimeStamp.count())));
}
lm.Dispatch();
}
Expand Down
30 changes: 15 additions & 15 deletions SilKit/source/services/orchestration/SystemStateTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
{
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("Updating participant status");
lm.SetKeyValue("ParticipantName", participantName);
lm.SetKeyValue("OldParticipantState", fmt::format("{}", oldParticipantState));
lm.SetKeyValue("NewParticipantState", fmt::format("{}", newParticipantState));
lm.SetKeyValue(Log::Keys::PARTICIPANT_NAME, participantName);
lm.SetKeyValue(Log::Keys::OLD_PARTICIPANT_STATE, fmt::format("{}", oldParticipantState));
lm.SetKeyValue(Log::Keys::NEW_PARTICIPANT_STATE, fmt::format("{}", newParticipantState));
lm.Dispatch();
}
// Check if transition from the old to the new participant state is valid
Expand All @@ -154,11 +154,11 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar

Log::LoggerMessage lm{_logger, logLevel};
lm.SetMessage("SystemMonitor detected invalid ParticipantState transition!");
lm.SetKeyValue("ParticipantName", participantName);
lm.SetKeyValue("OldParticipantState", fmt::format("{}", oldParticipantState));
lm.SetKeyValue("NewParticipantState", fmt::format("{}", newParticipantState));
lm.SetKeyValue("EnterTime", FormatTimePoint(newParticipantStatus.enterTime));
lm.SetKeyValue("EnterReason", newParticipantStatus.enterReason);
lm.SetKeyValue(Log::Keys::PARTICIPANT_NAME, participantName);
lm.SetKeyValue(Log::Keys::OLD_PARTICIPANT_STATE, fmt::format("{}", oldParticipantState));
lm.SetKeyValue(Log::Keys::NEW_PARTICIPANT_STATE, fmt::format("{}", newParticipantState));
lm.SetKeyValue(Log::Keys::ENTER_TIME, FormatTimePoint(newParticipantStatus.enterTime));
lm.SetKeyValue(Log::Keys::ENTER_REASON, newParticipantStatus.enterReason);
lm.Dispatch();

// NB: Failing validation doesn't actually stop the participants state from being changed, it just logs the
Expand All @@ -183,7 +183,7 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
{
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("The participant state has changed!");
lm.SetKeyValue("ParticipantName", participantName);
lm.SetKeyValue(Log::Keys::PARTICIPANT_NAME, participantName);
lm.Dispatch();
}

Expand All @@ -195,19 +195,19 @@ auto SystemStateTracker::UpdateParticipantStatus(const ParticipantStatus& newPar
{
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("Computed new system state update!");
lm.SetKeyValue("ParticipantName", participantName);
lm.SetKeyValue("OldSystemState", fmt::format("{}", oldSystemState));
lm.SetKeyValue("NewSystemState", fmt::format("{}", newSystemState));
lm.SetKeyValue(Log::Keys::PARTICIPANT_NAME, participantName);
lm.SetKeyValue(Log::Keys::OLD_PARTICIPANT_STATE, fmt::format("{}", oldSystemState));
lm.SetKeyValue(Log::Keys::NEW_PARTICIPANT_STATE, fmt::format("{}", newSystemState));
lm.Dispatch();
}

if (oldSystemState != newSystemState)
{
Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("The system state has changed!");
lm.SetKeyValue("ParticipantName", participantName);
lm.SetKeyValue("OldSystemState", fmt::format("{}", oldSystemState));
lm.SetKeyValue("NewSystemState", fmt::format("{}", newSystemState));
lm.SetKeyValue(Log::Keys::PARTICIPANT_NAME, participantName);
lm.SetKeyValue(Log::Keys::OLD_PARTICIPANT_STATE, fmt::format("{}", oldSystemState));
lm.SetKeyValue(Log::Keys::NEW_PARTICIPANT_STATE, fmt::format("{}", newSystemState));
lm.Dispatch();

_systemState = newSystemState;
Expand Down
1 change: 0 additions & 1 deletion SilKit/source/services/orchestration/TimeConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <mutex>

#include "OrchestrationDatatypes.hpp"
//#include "silkit/services/logging/ILogger.hpp"
#include "ILoggerInternal.hpp"

namespace SilKit {
Expand Down
17 changes: 8 additions & 9 deletions SilKit/source/services/orchestration/TimeSyncService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void TimeSyncService::ReceiveMsg(const IServiceEndpoint* from, const NextSimTask
{
Logging::LoggerMessage lm{_logger, Logging::Level::Debug};
lm.SetMessage("Received NextSimTask from participant \'{}\' but TimeSyncPolicy is not yet configured");
lm.SetKeyValue("ParticipantName", from->GetServiceDescriptor().GetParticipantName());
lm.SetKeyValue(Logging::Keys::PARTICIPANT_NAME, from->GetServiceDescriptor().GetParticipantName());
lm.Dispatch();
}
}
Expand All @@ -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("WaitingTime", fmt::format("{}", std::chrono::duration_cast<DoubleMSecs>(_waitTimeMonitor.CurrentDuration()).count()));
lm.SetKeyValue("VirtualTimeNS", fmt::format("{}", timePoint.count()));
lm.SetKeyValue(Logging::Keys::WAITING_TIME, fmt::format("{}", std::chrono::duration_cast<DoubleMSecs>(_waitTimeMonitor.CurrentDuration()).count()));
lm.SetKeyValue(Logging::Keys::VIRTUAL_TIME_NS, fmt::format("{}", 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("ExecutionTime", fmt::format("{}", logicalSimStepTimeMs.count()));
lm.SetKeyValue("VirtualTimeNS", fmt::format("{}", Now().count()));
lm.SetKeyValue(Logging::Keys::EXECUTION_TIME, fmt::format("{}", logicalSimStepTimeMs.count()));
lm.SetKeyValue(Logging::Keys::VIRTUAL_TIME_NS, fmt::format("{}", Now().count()));
lm.Dispatch();
_waitTimeMonitor.StartMeasurement();
}
Expand Down Expand Up @@ -678,7 +678,7 @@ bool TimeSyncService::ParticipantHasAutonomousSynchronousCapability(const std::s
Logging::LoggerMessage lm{_participant->GetLoggerInternal(), Logging::Level::Error};
lm.SetMessage("Participant does not support simulations with participants that use an autonomous lifecycle "
"and virtual time synchronization. Please consider upgrading Participant. Aborting simulation...");
lm.SetKeyValue("ParticipantName", participantName);
lm.SetKeyValue(Logging::Keys::PARTICIPANT_NAME, participantName);
lm.Dispatch();
return false;
}
Expand All @@ -694,7 +694,7 @@ bool TimeSyncService::AbortHopOnForCoordinatedParticipants() const
Logging::LoggerMessage lm{_participant->GetLoggerInternal(), Logging::Level::Error};
lm.SetMessage("This participant is running with a coordinated lifecycle and virtual time synchronization and wants "
"to join an already running simulation. This is not allowed, aborting simulation...");
lm.SetKeyValue("ParticipantName", _participant->GetParticipantName());
lm.SetKeyValue(Logging::Keys::PARTICIPANT_NAME, _participant->GetParticipantName());
lm.Dispatch();

_participant->GetSystemController()->AbortSimulation();
Expand Down Expand Up @@ -771,7 +771,7 @@ void TimeSyncService::StartWallClockCouplingThread()
// AsyncSimStepHandler not completed? Execution is lagging behind. Don't send the NextSimStep now, but after completion.
Logging::LoggerMessage lm{_participant->GetLoggerInternal(), Logging::Level::Warn};
lm.SetMessage("Simulation step was not completed in time to achieve wall clock coupling.");
lm.SetKeyValue("ParticipantName", _participant->GetParticipantName());
lm.SetKeyValue(Logging::Keys::PARTICIPANT_NAME, _participant->GetParticipantName());
lm.Dispatch();

_wallClockReachedBeforeCompletion = true;
Expand All @@ -797,7 +797,6 @@ void TimeSyncService::StopWallClockCouplingThread()
}
}

// todo: evtl weg
bool TimeSyncService::IsBlocking() const
{
return _timeConfiguration.IsBlocking();
Expand Down

0 comments on commit 2352cdf

Please sign in to comment.