1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

remove logs and clean code

This commit is contained in:
n0lavar 2023-08-03 23:15:14 +03:00
parent bda9a21f40
commit b82e57bad6
5 changed files with 36 additions and 193 deletions

View File

@ -2,126 +2,78 @@
#include "TracyProfiler.hpp" #include "TracyProfiler.hpp"
#define DEBUG_TEMP 1 #if 0
#if DEBUG_TEMP #define ASSERT(x)
#include <syncstream> #else
#include <iostream> #define ASSERT(x) if(!(x)) __debugbreak();
#include <string>
#endif #endif
namespace tracy namespace tracy
{ {
class AsyncScopedZone; class AsyncScopedZone;
struct SourceLocationData; struct SourceLocationData;
inline thread_local tracy::AsyncScopedZone* g_pCurrentZone = nullptr; inline thread_local AsyncScopedZone* g_pCurrentZone = nullptr;
void StartAsyncEvent(const AsyncScopedZone* pAsyncScopedZone void StartAsyncEvent(AsyncScopedZone* pAsyncScopedZone);
#if DEBUG_TEMP void StopAsyncEvent(AsyncScopedZone* pAsyncScopedZone);
, size_t nFiber
#endif
);
void StopAsyncEvent();
class AsyncScopedZone class AsyncScopedZone
{ {
public: public:
AsyncScopedZone(const SourceLocationData* pSourceLocation AsyncScopedZone(const SourceLocationData* pSourceLocation);
#if DEBUG_TEMP
, size_t nFiber
#endif
);
~AsyncScopedZone(); ~AsyncScopedZone();
// private: // private:
const SourceLocationData* const m_pSourceLocation = nullptr; const SourceLocationData* const m_pSourceLocation = nullptr;
#if DEBUG_TEMP
const size_t m_nFiber = -1;
#endif
AsyncScopedZone* m_pParent = nullptr; AsyncScopedZone* m_pParent = nullptr;
// std::thread::id m_LockThreadId;
}; };
} }
inline void tracy::StartAsyncEvent(AsyncScopedZone* pAsyncScopedZone)
tracy_force_inline void tracy::StartAsyncEvent(const AsyncScopedZone* pAsyncScopedZone
#if DEBUG_TEMP
, size_t nFiber
#endif
)
{ {
ASSERT(pAsyncScopedZone);
ASSERT(!g_pCurrentZone);
// pAsyncScopedZone->m_LockThreadId = std::this_thread::get_id();
g_pCurrentZone = pAsyncScopedZone;
TracyQueuePrepare( QueueType::ZoneBegin ); TracyQueuePrepare( QueueType::ZoneBegin );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)pAsyncScopedZone->m_pSourceLocation ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)pAsyncScopedZone->m_pSourceLocation );
TracyQueueCommit( zoneBeginThread ); 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); TracyQueuePrepare(QueueType::ZoneEnd);
MemWrite(&item->zoneEnd.time, Profiler::GetTime()); MemWrite(&item->zoneEnd.time, Profiler::GetTime());
TracyQueueCommit(zoneEndThread); TracyQueueCommit(zoneEndThread);
} }
tracy_force_inline tracy::AsyncScopedZone::AsyncScopedZone(const SourceLocationData* pSourceLocation inline tracy::AsyncScopedZone::AsyncScopedZone(const SourceLocationData* pSourceLocation)
#if DEBUG_TEMP
, size_t nFiber
#endif
)
: m_pSourceLocation(pSourceLocation) : m_pSourceLocation(pSourceLocation)
#if DEBUG_TEMP
, m_nFiber(nFiber)
#endif
{ {
if (g_pCurrentZone) 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; m_pParent = g_pCurrentZone;
StopAsyncEvent(); StopAsyncEvent(g_pCurrentZone);
} }
#if DEBUG_TEMP StartAsyncEvent(this);
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
);
} }
tracy_force_inline tracy::AsyncScopedZone::~AsyncScopedZone() inline tracy::AsyncScopedZone::~AsyncScopedZone()
{ {
if (g_pCurrentZone) if (g_pCurrentZone)
{ {
StopAsyncEvent(); auto pZoneToContinue = g_pCurrentZone->m_pParent;
g_pCurrentZone = g_pCurrentZone->m_pParent; StopAsyncEvent(g_pCurrentZone);
if (g_pCurrentZone) if (pZoneToContinue)
StartAsyncEvent(g_pCurrentZone StartAsyncEvent(pZoneToContinue);
#if DEBUG_TEMP
, g_pCurrentZone->m_nFiber
#endif
);
} }
} }

View File

@ -11,11 +11,7 @@ namespace tracy
{ {
public: public:
Awaitable(BaseAwaitableType baseAwaitable); Awaitable(BaseAwaitableType baseAwaitable);
#if DEBUG_TEMP
~Awaitable(); ~Awaitable();
#endif
auto await_suspend(auto handle);
auto await_resume();
private: private:
AsyncScopedZone* m_pCurrentZone = nullptr; AsyncScopedZone* m_pCurrentZone = nullptr;
@ -25,84 +21,17 @@ namespace tracy
Awaitable<BaseAwaitableType>::Awaitable(BaseAwaitableType baseAwaitable) Awaitable<BaseAwaitableType>::Awaitable(BaseAwaitableType baseAwaitable)
: BaseAwaitableType(std::move(baseAwaitable)) : BaseAwaitableType(std::move(baseAwaitable))
{ {
#if DEBUG_TEMP if (g_pCurrentZone)
std::osyncstream(std::cout) << "Awaitable: constructor" {
<< ", thread id: " << std::this_thread::get_id() m_pCurrentZone = g_pCurrentZone;
<< ", frame: " << GetProfiler().GetFrame() StopAsyncEvent(g_pCurrentZone);
<< std::endl; }
#endif
} }
#if DEBUG_TEMP
template <class BaseAwaitableType> template <class BaseAwaitableType>
Awaitable<BaseAwaitableType>::~Awaitable() Awaitable<BaseAwaitableType>::~Awaitable()
{ {
std::osyncstream(std::cout) << "Awaitable: destructor"
<< ", thread id: " << std::this_thread::get_id()
<< ", frame: " << GetProfiler().GetFrame()
<< std::endl;
}
#endif
template<class BaseAwaitableType>
auto Awaitable<BaseAwaitableType>::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<class BaseAwaitableType>
auto Awaitable<BaseAwaitableType>::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 (m_pCurrentZone)
{ StartAsyncEvent(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();
} }
} }

View File

@ -237,11 +237,6 @@ public:
return m_zoneId.fetch_add( 1, std::memory_order_relaxed ); 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() static tracy_force_inline QueueItem* QueueSerial()
{ {
auto& p = GetProfiler(); auto& p = GetProfiler();

View File

@ -11,9 +11,6 @@ namespace tracy
{ {
public: public:
Result(BaseResultType&& result); Result(BaseResultType&& result);
#if DEBUG_TEMP
~Result();
#endif
auto operator co_await(); auto operator co_await();
}; };
@ -21,35 +18,11 @@ namespace tracy
Result<BaseResultType>::Result(BaseResultType&& result) Result<BaseResultType>::Result(BaseResultType&& result)
: BaseResultType(std::forward<BaseResultType>(result)) : BaseResultType(std::forward<BaseResultType>(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 <class BaseResultType>
Result<BaseResultType>::~Result()
{
std::osyncstream(std::cout) << "Result: destructor"
<< ", thread id: " << std::this_thread::get_id()
<< ", frame: " << GetProfiler().GetFrame()
<< std::endl;
}
#endif
template<class BaseResultType> template<class BaseResultType>
auto Result<BaseResultType>::operator co_await() auto Result<BaseResultType>::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()); return Awaitable(BaseResultType::operator co_await());
} }
} }

View File

@ -2,12 +2,6 @@
#include "../client/TracyResult.hpp" #include "../client/TracyResult.hpp"
#if DEBUG_TEMP #define ZoneAsyncC(color) \
#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) \
static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,TracyLine) { nullptr, TracyFunction, TracyFile, (uint32_t)TracyLine, 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) ); tracy::AsyncScopedZone ___tracy_async_scoped_zone( &TracyConcat(__tracy_source_location, TracyLine) );
#endif