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:
parent
bda9a21f40
commit
b82e57bad6
@ -2,126 +2,78 @@
|
||||
|
||||
#include "TracyProfiler.hpp"
|
||||
|
||||
#define DEBUG_TEMP 1
|
||||
#if DEBUG_TEMP
|
||||
#include <syncstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<BaseAwaitableType>::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 <class BaseAwaitableType>
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<BaseResultType>::Result(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>
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user