Create tid to pid mapping.

This commit is contained in:
Bartosz Taudul 2019-08-17 22:32:41 +02:00
parent fa573ef4cf
commit 20e8a5ecc8
4 changed files with 42 additions and 0 deletions

View File

@ -268,6 +268,17 @@ void SysTraceSendExternalName( uint64_t thread )
}
if( pid != 0 )
{
{
uint64_t _pid = pid;
Magic magic;
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::TidToPid );
MemWrite( &item->tidToPid.tid, thread );
MemWrite( &item->tidToPid.pid, _pid );
tail.store( magic + 1, std::memory_order_release );
}
if( pid == 4 )
{
GetProfiler().SendString( thread, "System", QueueType::ExternalName );
@ -549,6 +560,17 @@ void SysTraceSendExternalName( uint64_t thread )
fclose( f );
if( pid >= 0 )
{
{
uint64_t _pid = pid;
Magic magic;
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::TidToPid );
MemWrite( &item->tidToPid.tid, thread );
MemWrite( &item->tidToPid.pid, _pid );
tail.store( magic + 1, std::memory_order_release );
}
sprintf( fn, "/proc/%i/comm", pid );
f = fopen( fn, "rb" );
if( f )

View File

@ -58,6 +58,7 @@ enum class QueueType : uint8_t
SysTimeReport,
ContextSwitch,
ThreadWakeup,
TidToPid,
StringData,
ThreadName,
CustomStringData,
@ -319,6 +320,12 @@ struct QueueThreadWakeup
uint64_t thread;
};
struct QueueTidToPid
{
uint64_t tid;
uint64_t pid;
};
struct QueueHeader
{
union
@ -366,6 +373,7 @@ struct QueueItem
QueueSysTime sysTime;
QueueContextSwitch contextSwitch;
QueueThreadWakeup threadWakeup;
QueueTidToPid tidToPid;
};
};
#pragma pack()
@ -425,6 +433,7 @@ static const size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
sizeof( QueueHeader ) + sizeof( QueueContextSwitch ),
sizeof( QueueHeader ) + sizeof( QueueThreadWakeup ),
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
// keep all QueueStringTransfer below
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name

View File

@ -3085,6 +3085,9 @@ bool Worker::Process( const QueueItem& ev )
case QueueType::ThreadWakeup:
ProcessThreadWakeup( ev.threadWakeup );
break;
case QueueType::TidToPid:
ProcessTidToPid( ev.tidToPid );
break;
default:
assert( false );
break;
@ -4194,6 +4197,12 @@ void Worker::ProcessThreadWakeup( const QueueThreadWakeup& ev )
item.SetState( -1 );
}
void Worker::ProcessTidToPid( const QueueTidToPid& ev )
{
assert( m_data.tidToPid.find( ev.tid ) == m_data.tidToPid.end() );
m_data.tidToPid.emplace( ev.tid, ev.pid );
}
void Worker::MemAllocChanged( int64_t time )
{
const auto val = (double)m_data.memory.usage;

View File

@ -212,6 +212,7 @@ private:
std::pair<uint64_t, ContextSwitch*> ctxSwitchLast;
CpuData cpuData[256];
flat_hash_map<uint64_t, uint64_t, nohash<uint64_t>> tidToPid;
};
struct MbpsBlock
@ -442,6 +443,7 @@ private:
tracy_force_inline void ProcessSysTime( const QueueSysTime& ev );
tracy_force_inline void ProcessContextSwitch( const QueueContextSwitch& ev );
tracy_force_inline void ProcessThreadWakeup( const QueueThreadWakeup& ev );
tracy_force_inline void ProcessTidToPid( const QueueTidToPid& ev );
tracy_force_inline void ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev );
tracy_force_inline void ProcessZoneBeginAllocSrcLocImpl( ZoneEvent* zone, const QueueZoneBegin& ev );