diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index 8c1a59f9..13a3e773 100755 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -1,6 +1,7 @@ #ifndef __TRACYLOCK_HPP__ #define __TRACYLOCK_HPP__ +#include "../common/TracySystem.hpp" #include "TracyProfiler.hpp" namespace tracy @@ -26,17 +27,64 @@ public: void lock() { + int8_t cpu; + const auto thread = GetThreadHandle(); + { + Magic magic; + auto& token = s_token; + auto item = s_queue.enqueue_begin( token, magic ); + item->hdr.type = QueueType::LockWait; + item->lockWait.id = (uint64_t)&m_lockable; + item->lockWait.thread = thread; + item->lockWait.time = Profiler::GetTime( item->zoneBegin.cpu ); + s_queue.enqueue_finish( token, magic ); + } + m_lockable.lock(); + + { + Magic magic; + auto& token = s_token; + auto item = s_queue.enqueue_begin( token, magic ); + item->hdr.type = QueueType::LockObtain; + item->lockObtain.id = (uint64_t)&m_lockable; + item->lockObtain.thread = thread; + item->lockObtain.time = Profiler::GetTime( item->zoneBegin.cpu ); + s_queue.enqueue_finish( token, magic ); + } } void unlock() { m_lockable.unlock(); + + int8_t cpu; + Magic magic; + auto& token = s_token; + auto item = s_queue.enqueue_begin( token, magic ); + item->hdr.type = QueueType::LockRelease; + item->lockRelease.id = (uint64_t)&m_lockable; + item->lockRelease.thread = GetThreadHandle(); + item->lockRelease.time = Profiler::GetTime( item->zoneBegin.cpu ); + s_queue.enqueue_finish( token, magic ); } bool try_lock() { - return m_lockable.try_lock(); + const auto ret = m_lockable.try_lock(); + if( ret ) + { + int8_t cpu; + Magic magic; + auto& token = s_token; + auto item = s_queue.enqueue_begin( token, magic ); + item->hdr.type = QueueType::LockObtain; + item->lockObtain.id = (uint64_t)&m_lockable; + item->lockObtain.thread = GetThreadHandle(); + item->lockObtain.time = Profiler::GetTime( item->zoneBegin.cpu ); + s_queue.enqueue_finish( token, magic ); + } + return ret; } private: diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 2657bbe5..aa1ed3b9 100755 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -80,14 +80,23 @@ struct QueueLockAnnounce struct QueueLockWait { + uint64_t id; // ptr + int64_t time; + uint64_t thread; }; struct QueueLockObtain { + uint64_t id; // ptr + int64_t time; + uint64_t thread; }; struct QueueLockRelease { + uint64_t id; // ptr + int64_t time; + uint64_t thread; }; struct QueueHeader diff --git a/server/TracyView.cpp b/server/TracyView.cpp index b95d369a..64f8a475 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -376,6 +376,12 @@ void View::Process( const QueueItem& ev ) case QueueType::LockAnnounce: ProcessLockAnnounce( ev.lockAnnounce ); break; + case QueueType::LockWait: + break; + case QueueType::LockObtain: + break; + case QueueType::LockRelease: + break; default: assert( false ); break;