From c36d1a5680e412211a3fc4021dd16d4233882ca2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 3 May 2021 19:23:16 +0200 Subject: [PATCH] Add automatic profile events for engine services events --- Source/Engine/Engine/EngineService.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Engine/EngineService.cpp b/Source/Engine/Engine/EngineService.cpp index 90e9a8d78..9f653a0b8 100644 --- a/Source/Engine/Engine/EngineService.cpp +++ b/Source/Engine/Engine/EngineService.cpp @@ -4,6 +4,7 @@ #include "Engine/Core/Log.h" #include "Engine/Core/Collections/Array.h" #include "Engine/Core/Collections/Sorting.h" +#include static bool CompareEngineServices(EngineService* const& a, EngineService* const& b) { @@ -14,6 +15,7 @@ static bool CompareEngineServices(EngineService* const& a, EngineService* const& void EngineService::name() { } \ void EngineService::On##name() \ { \ + ZoneScoped; \ auto& services = GetServices(); \ for (int32 i = 0; i < services.Count(); i++) \ services[i]->name(); \ @@ -22,6 +24,7 @@ static bool CompareEngineServices(EngineService* const& a, EngineService* const& void EngineService::name() { } \ void EngineService::On##name() \ { \ + ZoneScoped; \ auto& services = GetServices(); \ for (int32 i = 0; i < services.Count(); i++) \ services[i]->name(); \ @@ -63,18 +66,33 @@ bool EngineService::Init() void EngineService::OnInit() { + ZoneScoped; Sort(); // Init services from front to back auto& services = GetServices(); +#if TRACY_ENABLE + Char nameBuffer[100]; +#endif for (int32 i = 0; i < services.Count(); i++) { const auto service = services[i]; - LOG(Info, "Initialize {0}...", service->Name); + const StringView name(service->Name); +#if TRACY_ENABLE + ZoneScoped; + int32 nameBufferLength = 0; + for (int32 j = 0; j < name.Length(); j++) + if (name[j] != ' ') + nameBuffer[nameBufferLength++] = name[j]; + Platform::MemoryCopy(nameBuffer + nameBufferLength, TEXT("::Init"), 7 * sizeof(Char)); + nameBufferLength += 7; + ZoneName(nameBuffer, nameBufferLength); +#endif + LOG(Info, "Initialize {0}...", name); service->IsInitialized = true; if (service->Init()) { - Platform::Fatal(String::Format(TEXT("Failed to initialize {0}."), service->Name)); + Platform::Fatal(String::Format(TEXT("Failed to initialize {0}."), name)); } } @@ -87,6 +105,7 @@ void EngineService::Dispose() void EngineService::OnDispose() { + ZoneScoped; // Dispose services from back to front auto& services = GetServices(); for (int32 i = services.Count() - 1; i >= 0; i--)