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 ) 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 ) if( pid == 4 )
{ {
GetProfiler().SendString( thread, "System", QueueType::ExternalName ); GetProfiler().SendString( thread, "System", QueueType::ExternalName );
@ -549,6 +560,17 @@ void SysTraceSendExternalName( uint64_t thread )
fclose( f ); fclose( f );
if( pid >= 0 ) 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 ); sprintf( fn, "/proc/%i/comm", pid );
f = fopen( fn, "rb" ); f = fopen( fn, "rb" );
if( f ) if( f )

View File

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

View File

@ -3085,6 +3085,9 @@ bool Worker::Process( const QueueItem& ev )
case QueueType::ThreadWakeup: case QueueType::ThreadWakeup:
ProcessThreadWakeup( ev.threadWakeup ); ProcessThreadWakeup( ev.threadWakeup );
break; break;
case QueueType::TidToPid:
ProcessTidToPid( ev.tidToPid );
break;
default: default:
assert( false ); assert( false );
break; break;
@ -4194,6 +4197,12 @@ void Worker::ProcessThreadWakeup( const QueueThreadWakeup& ev )
item.SetState( -1 ); 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 ) void Worker::MemAllocChanged( int64_t time )
{ {
const auto val = (double)m_data.memory.usage; const auto val = (double)m_data.memory.usage;

View File

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