From 87bfb71f2bdb73c19bd5d4bb3095ef1f4cbcdba2 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Mon, 8 Jul 2024 02:41:22 +0000 Subject: [PATCH] Add trace logs to InitComponents --- include/cserver/engine/components.hpp | 54 +++++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index ae6ff39..493ced6 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -187,21 +188,46 @@ inline constexpr auto InitComponents(T& ccontext, int ac, const char** av) -> vo static utempl::Tuple inited = TransformDependencyGraphToTupleWithDependenciesToInitedFlagChanges(ioContext); auto work = make_work_guard(ioContext); - [](std::index_sequence) { + [](auto... is) { // clang-format off - (boost::asio::co_spawn(ioContext, []() -> cserver::Task<> { - using Current = decltype(Get(decltype(T::kUtils)::kComponentConfigs)); - auto& dependencies = Get(inited); + (boost::asio::co_spawn(ioContext, [](auto is) -> cserver::Task<> { + using Current = decltype(Get(decltype(T::kUtils)::kComponentConfigs)); + auto& dependencies = Get(inited); + constexpr auto logLevel = T::kConfig.template Get<"logging">().template Get<"level">(); + if constexpr(logLevel == LoggingLevel::kTrace) { + fmt::println("[TRACE] Started coroutine for initialisation component {} with flag address {}", + static_cast(Current::kName), + static_cast(&GetInitFlagFor(ioContext))); + }; for(auto* flag : dependencies) { + if constexpr(logLevel == LoggingLevel::kTrace) { + fmt::println("[TRACE] {} Component: Waiting flag on address {}", + static_cast(Current::kName), + static_cast(flag)); + }; co_await flag->AsyncWait(); + if constexpr(logLevel == LoggingLevel::kTrace) { + fmt::println("[TRACE] {} Component: Waited flag on address {}", + static_cast(Current::kName), + static_cast(flag)); + }; + }; try { if constexpr(Current::kName == cliArgs) { ServiceContextForComponentWithCliArgs currentContext{context, argc, argv}; - Get(context.storage).emplace(currentContext); + if constexpr(logLevel == LoggingLevel::kTrace) { + fmt::println("[TRACE] {} Component: call constructor with cli args", + static_cast(Current::kName)); + }; + Get(context.storage).emplace(currentContext); } else { ServiceContextForComponent currentContext{context}; - Get(context.storage).emplace(currentContext); + if constexpr(logLevel == LoggingLevel::kTrace) { + fmt::println("[TRACE] {} Component: call constructor", + static_cast(Current::kName)); + }; + Get(context.storage).emplace(currentContext); }; } catch(std::exception& error) { auto typeName = boost::core::demangle(__cxxabiv1::__cxa_current_exception_type()->name()); @@ -217,14 +243,18 @@ inline constexpr auto InitComponents(T& ccontext, int ac, const char** av) -> vo typeName); ioContext.stop(); }; - auto& componentInitFlag = GetInitFlagFor(ioContext); - componentInitFlag.NotifyAll(); - if constexpr(requires{Get(context.storage)->Run();}) { - Get(context.storage)->Run(); + auto& componentInitFlag = GetInitFlagFor(ioContext); + if constexpr(logLevel == LoggingLevel::kTrace) { + fmt::println("[TRACE] {} Component: notify", + static_cast(Current::kName)); }; - }(), boost::asio::detached), ...); + componentInitFlag.NotifyAll(); + if constexpr(requires{Get(context.storage)->Run();}) { + Get(context.storage)->Run(); + }; + }(is), boost::asio::detached), ...); // clang-format on - }(std::make_index_sequence>()); + } | utempl::kSeq>; }; template