mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Let's not worry about lock memory reuse.
This commit is contained in:
parent
0011573fa9
commit
8c90eab044
@ -1,23 +1,28 @@
|
|||||||
#ifndef __TRACYLOCK_HPP__
|
#ifndef __TRACYLOCK_HPP__
|
||||||
#define __TRACYLOCK_HPP__
|
#define __TRACYLOCK_HPP__
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "../common/TracySystem.hpp"
|
#include "../common/TracySystem.hpp"
|
||||||
#include "TracyProfiler.hpp"
|
#include "TracyProfiler.hpp"
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static std::atomic<uint64_t> s_lockCounter( 0 );
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class Lockable
|
class Lockable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Lockable( const SourceLocation* srcloc )
|
Lockable( const SourceLocation* srcloc )
|
||||||
|
: m_id( s_lockCounter.fetch_add( 1, std::memory_order_relaxed ) )
|
||||||
{
|
{
|
||||||
Magic magic;
|
Magic magic;
|
||||||
auto& token = s_token;
|
auto& token = s_token;
|
||||||
auto item = s_queue.enqueue_begin( token, magic );
|
auto item = s_queue.enqueue_begin( token, magic );
|
||||||
item->hdr.type = QueueType::LockAnnounce;
|
item->hdr.type = QueueType::LockAnnounce;
|
||||||
item->lockAnnounce.id = (uint64_t)&m_lockable;
|
item->lockAnnounce.id = m_id;
|
||||||
item->lockAnnounce.srcloc = (uint64_t)srcloc;
|
item->lockAnnounce.srcloc = (uint64_t)srcloc;
|
||||||
s_queue.enqueue_finish( token, magic );
|
s_queue.enqueue_finish( token, magic );
|
||||||
}
|
}
|
||||||
@ -34,7 +39,7 @@ public:
|
|||||||
auto& token = s_token;
|
auto& token = s_token;
|
||||||
auto item = s_queue.enqueue_begin( token, magic );
|
auto item = s_queue.enqueue_begin( token, magic );
|
||||||
item->hdr.type = QueueType::LockWait;
|
item->hdr.type = QueueType::LockWait;
|
||||||
item->lockWait.id = (uint64_t)&m_lockable;
|
item->lockWait.id = m_id;
|
||||||
item->lockWait.thread = thread;
|
item->lockWait.thread = thread;
|
||||||
item->lockWait.time = Profiler::GetTime( item->zoneBegin.cpu );
|
item->lockWait.time = Profiler::GetTime( item->zoneBegin.cpu );
|
||||||
s_queue.enqueue_finish( token, magic );
|
s_queue.enqueue_finish( token, magic );
|
||||||
@ -47,7 +52,7 @@ public:
|
|||||||
auto& token = s_token;
|
auto& token = s_token;
|
||||||
auto item = s_queue.enqueue_begin( token, magic );
|
auto item = s_queue.enqueue_begin( token, magic );
|
||||||
item->hdr.type = QueueType::LockObtain;
|
item->hdr.type = QueueType::LockObtain;
|
||||||
item->lockObtain.id = (uint64_t)&m_lockable;
|
item->lockObtain.id = m_id;
|
||||||
item->lockObtain.thread = thread;
|
item->lockObtain.thread = thread;
|
||||||
item->lockObtain.time = Profiler::GetTime( item->zoneBegin.cpu );
|
item->lockObtain.time = Profiler::GetTime( item->zoneBegin.cpu );
|
||||||
s_queue.enqueue_finish( token, magic );
|
s_queue.enqueue_finish( token, magic );
|
||||||
@ -63,7 +68,7 @@ public:
|
|||||||
auto& token = s_token;
|
auto& token = s_token;
|
||||||
auto item = s_queue.enqueue_begin( token, magic );
|
auto item = s_queue.enqueue_begin( token, magic );
|
||||||
item->hdr.type = QueueType::LockRelease;
|
item->hdr.type = QueueType::LockRelease;
|
||||||
item->lockRelease.id = (uint64_t)&m_lockable;
|
item->lockRelease.id = m_id;
|
||||||
item->lockRelease.thread = GetThreadHandle();
|
item->lockRelease.thread = GetThreadHandle();
|
||||||
item->lockRelease.time = Profiler::GetTime( item->zoneBegin.cpu );
|
item->lockRelease.time = Profiler::GetTime( item->zoneBegin.cpu );
|
||||||
s_queue.enqueue_finish( token, magic );
|
s_queue.enqueue_finish( token, magic );
|
||||||
@ -89,6 +94,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
T m_lockable;
|
T m_lockable;
|
||||||
|
uint64_t m_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -74,27 +74,27 @@ struct QueueZoneName
|
|||||||
|
|
||||||
struct QueueLockAnnounce
|
struct QueueLockAnnounce
|
||||||
{
|
{
|
||||||
uint64_t id; // ptr
|
uint64_t id;
|
||||||
uint64_t srcloc; // ptr
|
uint64_t srcloc; // ptr
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueueLockWait
|
struct QueueLockWait
|
||||||
{
|
{
|
||||||
uint64_t id; // ptr
|
uint64_t id;
|
||||||
int64_t time;
|
int64_t time;
|
||||||
uint64_t thread;
|
uint64_t thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueueLockObtain
|
struct QueueLockObtain
|
||||||
{
|
{
|
||||||
uint64_t id; // ptr
|
uint64_t id;
|
||||||
int64_t time;
|
int64_t time;
|
||||||
uint64_t thread;
|
uint64_t thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueueLockRelease
|
struct QueueLockRelease
|
||||||
{
|
{
|
||||||
uint64_t id; // ptr
|
uint64_t id;
|
||||||
int64_t time;
|
int64_t time;
|
||||||
uint64_t thread;
|
uint64_t thread;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -457,15 +457,8 @@ void View::ProcessLockAnnounce( const QueueLockAnnounce& ev )
|
|||||||
auto ptr = m_slab.Alloc<LockEvent>();
|
auto ptr = m_slab.Alloc<LockEvent>();
|
||||||
ptr->srcloc = ev.srcloc;
|
ptr->srcloc = ev.srcloc;
|
||||||
|
|
||||||
auto it = m_lockMap.find( ev.id );
|
assert( m_lockMap.find( ev.id ) == m_lockMap.end() );
|
||||||
if( it == m_lockMap.end() )
|
m_lockMap.emplace( ev.id, ptr );
|
||||||
{
|
|
||||||
m_lockMap.emplace( ev.id, ptr );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it->second = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock( m_lock );
|
std::lock_guard<std::mutex> lock( m_lock );
|
||||||
m_locks.push_back( ptr );
|
m_locks.push_back( ptr );
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user