From b82e57bad65bcb9c3939e3ce20f37a45a891db1e Mon Sep 17 00:00:00 2001 From: n0lavar Date: Thu, 3 Aug 2023 23:15:14 +0300 Subject: [PATCH] remove logs and clean code --- public/client/TracyAsyncEvents.hpp | 106 ++++++++--------------------- public/client/TracyAwaitable.hpp | 83 ++-------------------- public/client/TracyProfiler.hpp | 5 -- public/client/TracyResult.hpp | 27 -------- public/tracy/TracyAsync.hpp | 8 +-- 5 files changed, 36 insertions(+), 193 deletions(-) diff --git a/public/client/TracyAsyncEvents.hpp b/public/client/TracyAsyncEvents.hpp index 93d2ab73..b7f46a86 100644 --- a/public/client/TracyAsyncEvents.hpp +++ b/public/client/TracyAsyncEvents.hpp @@ -2,126 +2,78 @@ #include "TracyProfiler.hpp" -#define DEBUG_TEMP 1 -#if DEBUG_TEMP -#include -#include -#include +#if 0 + #define ASSERT(x) +#else + #define ASSERT(x) if(!(x)) __debugbreak(); #endif namespace tracy { class AsyncScopedZone; struct SourceLocationData; - inline thread_local tracy::AsyncScopedZone* g_pCurrentZone = nullptr; + inline thread_local AsyncScopedZone* g_pCurrentZone = nullptr; - void StartAsyncEvent(const AsyncScopedZone* pAsyncScopedZone -#if DEBUG_TEMP - , size_t nFiber -#endif - ); - void StopAsyncEvent(); + void StartAsyncEvent(AsyncScopedZone* pAsyncScopedZone); + void StopAsyncEvent(AsyncScopedZone* pAsyncScopedZone); class AsyncScopedZone { public: - AsyncScopedZone(const SourceLocationData* pSourceLocation -#if DEBUG_TEMP - , size_t nFiber -#endif - ); + AsyncScopedZone(const SourceLocationData* pSourceLocation); ~AsyncScopedZone(); // private: const SourceLocationData* const m_pSourceLocation = nullptr; -#if DEBUG_TEMP - const size_t m_nFiber = -1; -#endif AsyncScopedZone* m_pParent = nullptr; + // std::thread::id m_LockThreadId; }; } - -tracy_force_inline void tracy::StartAsyncEvent(const AsyncScopedZone* pAsyncScopedZone -#if DEBUG_TEMP - , size_t nFiber -#endif -) +inline void tracy::StartAsyncEvent(AsyncScopedZone* pAsyncScopedZone) { + ASSERT(pAsyncScopedZone); + ASSERT(!g_pCurrentZone); + // pAsyncScopedZone->m_LockThreadId = std::this_thread::get_id(); + g_pCurrentZone = pAsyncScopedZone; + TracyQueuePrepare( QueueType::ZoneBegin ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)pAsyncScopedZone->m_pSourceLocation ); TracyQueueCommit( zoneBeginThread ); - -#if DEBUG_TEMP - if (nFiber == 0) - { - const std::string sMessage = "fiber: " + std::to_string(nFiber); - tracy::Profiler::Message(sMessage.c_str(), sMessage.size(), 0); - } -#endif } -tracy_force_inline void tracy::StopAsyncEvent() +inline void tracy::StopAsyncEvent(AsyncScopedZone* pAsyncScopedZone) { + ASSERT(pAsyncScopedZone); + ASSERT(pAsyncScopedZone == g_pCurrentZone); + // ASSERT(pAsyncScopedZone->m_LockThreadId == std::this_thread::get_id()); + g_pCurrentZone = nullptr; + TracyQueuePrepare(QueueType::ZoneEnd); MemWrite(&item->zoneEnd.time, Profiler::GetTime()); TracyQueueCommit(zoneEndThread); } -tracy_force_inline tracy::AsyncScopedZone::AsyncScopedZone(const SourceLocationData* pSourceLocation -#if DEBUG_TEMP - , size_t nFiber -#endif -) +inline tracy::AsyncScopedZone::AsyncScopedZone(const SourceLocationData* pSourceLocation) : m_pSourceLocation(pSourceLocation) -#if DEBUG_TEMP - , m_nFiber(nFiber) -#endif { if (g_pCurrentZone) { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "AsyncScopedZone: constructor, StopAsyncEvent" - << ", location: " << g_pCurrentZone->m_pSourceLocation->function - << ", fiber: " << nFiber - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - m_pParent = g_pCurrentZone; - StopAsyncEvent(); + StopAsyncEvent(g_pCurrentZone); } -#if DEBUG_TEMP - std::osyncstream(std::cout) << "AsyncScopedZone: constructor, StartAsyncEvent" - << ", location: " << pSourceLocation->function - << ", fiber: " << nFiber - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - - g_pCurrentZone = this; - StartAsyncEvent(this -#if DEBUG_TEMP - , nFiber -#endif - ); + StartAsyncEvent(this); } -tracy_force_inline tracy::AsyncScopedZone::~AsyncScopedZone() +inline tracy::AsyncScopedZone::~AsyncScopedZone() { if (g_pCurrentZone) { - StopAsyncEvent(); - g_pCurrentZone = g_pCurrentZone->m_pParent; - if (g_pCurrentZone) - StartAsyncEvent(g_pCurrentZone -#if DEBUG_TEMP - , g_pCurrentZone->m_nFiber -#endif - ); + auto pZoneToContinue = g_pCurrentZone->m_pParent; + StopAsyncEvent(g_pCurrentZone); + if (pZoneToContinue) + StartAsyncEvent(pZoneToContinue); } } diff --git a/public/client/TracyAwaitable.hpp b/public/client/TracyAwaitable.hpp index 266d2a8c..a37f6326 100644 --- a/public/client/TracyAwaitable.hpp +++ b/public/client/TracyAwaitable.hpp @@ -11,11 +11,7 @@ namespace tracy { public: Awaitable(BaseAwaitableType baseAwaitable); -#if DEBUG_TEMP ~Awaitable(); -#endif - auto await_suspend(auto handle); - auto await_resume(); private: AsyncScopedZone* m_pCurrentZone = nullptr; @@ -25,84 +21,17 @@ namespace tracy Awaitable::Awaitable(BaseAwaitableType baseAwaitable) : BaseAwaitableType(std::move(baseAwaitable)) { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Awaitable: constructor" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif + if (g_pCurrentZone) + { + m_pCurrentZone = g_pCurrentZone; + StopAsyncEvent(g_pCurrentZone); + } } -#if DEBUG_TEMP template Awaitable::~Awaitable() { - std::osyncstream(std::cout) << "Awaitable: destructor" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; - } -#endif - - template - auto Awaitable::await_suspend(auto handle) - { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Awaitable: await_suspend" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - - if (g_pCurrentZone) - { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Awaitable: await_suspend, StopAsyncEvent" - << ", location: " << g_pCurrentZone->m_pSourceLocation->function - << ", fiber: " << g_pCurrentZone->m_nFiber - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - - m_pCurrentZone = g_pCurrentZone; - g_pCurrentZone = nullptr; - StopAsyncEvent(); - } - - return BaseAwaitableType::await_suspend(handle); - } - - template - auto Awaitable::await_resume() - { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Awaitable: await_resume" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - if (m_pCurrentZone) - { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Awaitable: await_resume, StartAsyncEvent" - << ", location: " << m_pCurrentZone->m_pSourceLocation->function - << ", fiber: " << m_pCurrentZone->m_nFiber - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - - StartAsyncEvent(m_pCurrentZone -#if DEBUG_TEMP - , m_pCurrentZone->m_nFiber -#endif - ); - g_pCurrentZone = m_pCurrentZone; - m_pCurrentZone = nullptr; - } - - return BaseAwaitableType::await_resume(); + StartAsyncEvent(m_pCurrentZone); } } diff --git a/public/client/TracyProfiler.hpp b/public/client/TracyProfiler.hpp index 326cdb34..9b8f8433 100644 --- a/public/client/TracyProfiler.hpp +++ b/public/client/TracyProfiler.hpp @@ -237,11 +237,6 @@ public: return m_zoneId.fetch_add( 1, std::memory_order_relaxed ); } - tracy_force_inline uint64_t GetFrame() const - { - return m_frameCount.load( std::memory_order_relaxed ); - } - static tracy_force_inline QueueItem* QueueSerial() { auto& p = GetProfiler(); diff --git a/public/client/TracyResult.hpp b/public/client/TracyResult.hpp index d6b11325..cfdba773 100644 --- a/public/client/TracyResult.hpp +++ b/public/client/TracyResult.hpp @@ -11,9 +11,6 @@ namespace tracy { public: Result(BaseResultType&& result); -#if DEBUG_TEMP - ~Result(); -#endif auto operator co_await(); }; @@ -21,35 +18,11 @@ namespace tracy Result::Result(BaseResultType&& result) : BaseResultType(std::forward(result)) { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Result: constructor" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif } -#if DEBUG_TEMP - template - Result::~Result() - { - std::osyncstream(std::cout) << "Result: destructor" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; - } -#endif - template auto Result::operator co_await() { -#if DEBUG_TEMP - std::osyncstream(std::cout) << "Result: operator co_await" - << ", thread id: " << std::this_thread::get_id() - << ", frame: " << GetProfiler().GetFrame() - << std::endl; -#endif - return Awaitable(BaseResultType::operator co_await()); } } diff --git a/public/tracy/TracyAsync.hpp b/public/tracy/TracyAsync.hpp index 79fdce45..0ea8e4ca 100644 --- a/public/tracy/TracyAsync.hpp +++ b/public/tracy/TracyAsync.hpp @@ -2,12 +2,6 @@ #include "../client/TracyResult.hpp" -#if DEBUG_TEMP -#define ZoneAsyncC(color, fiber) \ - static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,TracyLine) { nullptr, TracyFunction, TracyFile, (uint32_t)TracyLine, color }; \ - tracy::AsyncScopedZone ___tracy_async_scoped_zone( &TracyConcat(__tracy_source_location, TracyLine), fiber ); -#else -#define ZoneAsyncC(color, fiber) \ +#define ZoneAsyncC(color) \ static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,TracyLine) { nullptr, TracyFunction, TracyFile, (uint32_t)TracyLine, color }; \ tracy::AsyncScopedZone ___tracy_async_scoped_zone( &TracyConcat(__tracy_source_location, TracyLine) ); -#endif