mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Implement retrieval of external process names.
This commit is contained in:
+25
-25
@@ -3967,47 +3967,45 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover,
|
||||
ZoomToRange( start, rend );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto thread = it->Thread();
|
||||
const auto local = thread != 0 && m_worker.IsThreadLocal( thread );
|
||||
const auto local = m_worker.IsThreadLocal( thread );
|
||||
const auto pr0 = ( start - m_zvStart ) * pxns;
|
||||
const auto pr1 = ( end - m_zvStart ) * pxns;
|
||||
const auto px0 = std::max( pr0, -10.0 );
|
||||
const auto px1 = std::max( { std::min( pr1, double( w + 10 ) ), px0 + pxns * 0.5, px0 + MinVisSize } );
|
||||
draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + sty ), local ? 0xFF334488 : 0xFF444444 );
|
||||
draw->AddRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + sty ), local ? 0xFF5566AA : 0xFF666666 );
|
||||
if( local )
|
||||
|
||||
auto txt = local ? m_worker.GetThreadString( thread ) : m_worker.GetExternalName( thread );
|
||||
auto tsz = ImGui::CalcTextSize( txt );
|
||||
if( tsz.x < zsz )
|
||||
{
|
||||
auto txt = m_worker.GetThreadString( thread );
|
||||
auto tsz = ImGui::CalcTextSize( txt );
|
||||
if( tsz.x < zsz )
|
||||
const auto x = ( start - m_zvStart ) * pxns + ( ( end - start ) * pxns - tsz.x ) / 2;
|
||||
if( x < 0 || x > w - tsz.x )
|
||||
{
|
||||
const auto x = ( start - m_zvStart ) * pxns + ( ( end - start ) * pxns - tsz.x ) / 2;
|
||||
if( x < 0 || x > w - tsz.x )
|
||||
{
|
||||
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
|
||||
DrawTextContrast( draw, wpos + ImVec2( std::max( std::max( 0., px0 ), std::min( double( w - tsz.x ), x ) ), offset-1 ), 0xFFFFFFFF, txt );
|
||||
ImGui::PopClipRect();
|
||||
}
|
||||
else if( start == end )
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( px0 + ( px1 - px0 - tsz.x ) * 0.5, offset-1 ), 0xFFFFFFFF, txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( x, offset-1 ), 0xFFFFFFFF, txt );
|
||||
}
|
||||
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
|
||||
DrawTextContrast( draw, wpos + ImVec2( std::max( std::max( 0., px0 ), std::min( double( w - tsz.x ), x ) ), offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, txt );
|
||||
ImGui::PopClipRect();
|
||||
}
|
||||
else if( start == end )
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( px0 + ( px1 - px0 - tsz.x ) * 0.5, offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
|
||||
DrawTextContrast( draw, wpos + ImVec2( ( start - m_zvStart ) * pxns, offset ), 0xFFFFFFFF, txt );
|
||||
ImGui::PopClipRect();
|
||||
DrawTextContrast( draw, wpos + ImVec2( x, offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, txt );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
|
||||
DrawTextContrast( draw, wpos + ImVec2( ( start - m_zvStart ) * pxns, offset ), local ? 0xFFFFFFFF : 0xAAFFFFFF, txt );
|
||||
ImGui::PopClipRect();
|
||||
}
|
||||
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset-1 ), wpos + ImVec2( px1, offset + sty - 1 ) ) )
|
||||
{
|
||||
ImGui::PopFont();
|
||||
@@ -4022,7 +4020,9 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover,
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "Program:", "<external>" );
|
||||
TextFocused( "Program:", txt );
|
||||
ImGui::SameLine();
|
||||
TextDisabledUnformatted( "(external)" );
|
||||
}
|
||||
ImGui::Separator();
|
||||
TextFocused( "Start time:", TimeToString( start ) );
|
||||
|
||||
+44
-3
@@ -246,6 +246,7 @@ Worker::Worker( const char* addr )
|
||||
, m_bufferOffset( 0 )
|
||||
, m_pendingStrings( 0 )
|
||||
, m_pendingThreads( 0 )
|
||||
, m_pendingExternalNames( 0 )
|
||||
, m_pendingSourceLocation( 0 )
|
||||
, m_pendingCallstackFrames( 0 )
|
||||
, m_pendingCallstackSubframes( 0 )
|
||||
@@ -1838,6 +1839,19 @@ const SourceLocation& Worker::GetSourceLocation( int16_t srcloc ) const
|
||||
}
|
||||
}
|
||||
|
||||
const char* Worker::GetExternalName( uint64_t id ) const
|
||||
{
|
||||
const auto it = m_data.externalNames.find( id );
|
||||
if( it == m_data.externalNames.end() )
|
||||
{
|
||||
return "???";
|
||||
}
|
||||
else
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
const char* Worker::GetZoneName( const SourceLocation& srcloc ) const
|
||||
{
|
||||
if( srcloc.name.active )
|
||||
@@ -2160,7 +2174,7 @@ void Worker::Exec()
|
||||
{
|
||||
if( m_pendingStrings != 0 || m_pendingThreads != 0 || m_pendingSourceLocation != 0 || m_pendingCallstackFrames != 0 ||
|
||||
!m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 ||
|
||||
m_pendingCallstackSubframes != 0 || !m_pendingFrameImageData.empty() )
|
||||
m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || !m_pendingFrameImageData.empty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -2255,6 +2269,9 @@ bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr )
|
||||
case QueueType::CallstackAllocPayload:
|
||||
AddCallstackAllocPayload( ev.stringTransfer.ptr, ptr, sz );
|
||||
break;
|
||||
case QueueType::ExternalName:
|
||||
AddExternalName( ev.stringTransfer.ptr, ptr, sz );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
@@ -2483,6 +2500,16 @@ void Worker::CheckThreadString( uint64_t id )
|
||||
Query( ServerQueryThreadString, id );
|
||||
}
|
||||
|
||||
void Worker::CheckExternalName( uint64_t id )
|
||||
{
|
||||
if( m_data.externalNames.find( id ) != m_data.externalNames.end() ) return;
|
||||
|
||||
m_data.externalNames.emplace( id, "???" );
|
||||
m_pendingExternalNames++;
|
||||
|
||||
Query( ServerQueryExternalName, id );
|
||||
}
|
||||
|
||||
void Worker::AddSourceLocation( const QueueSourceLocation& srcloc )
|
||||
{
|
||||
assert( m_pendingSourceLocation > 0 );
|
||||
@@ -2575,6 +2602,16 @@ void Worker::AddCustomString( uint64_t ptr, char* str, size_t sz )
|
||||
m_pendingCustomStrings.emplace( ptr, StoreString( str, sz ) );
|
||||
}
|
||||
|
||||
void Worker::AddExternalName( uint64_t ptr, char* str, size_t sz )
|
||||
{
|
||||
assert( m_pendingExternalNames > 0 );
|
||||
m_pendingExternalNames--;
|
||||
auto it = m_data.externalNames.find( ptr );
|
||||
assert( it != m_data.externalNames.end() && strcmp( it->second, "???" ) == 0 );
|
||||
const auto sl = StoreString( str, sz );
|
||||
it->second = sl.ptr;
|
||||
}
|
||||
|
||||
static const uint8_t DxtcIndexTable[256] = {
|
||||
85, 87, 86, 84, 93, 95, 94, 92, 89, 91, 90, 88, 81, 83, 82, 80,
|
||||
117, 119, 118, 116, 125, 127, 126, 124, 121, 123, 122, 120, 113, 115, 114, 112,
|
||||
@@ -4063,6 +4100,12 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
||||
auto& cx = cs.push_next();
|
||||
cx.SetStart( time );
|
||||
cx.SetThread( ev.newThread );
|
||||
|
||||
// At this point that check is approximate
|
||||
if( !IsThreadLocal( ev.newThread ) )
|
||||
{
|
||||
CheckExternalName( ev.newThread );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4886,8 +4929,6 @@ void Worker::Write( FileWrite& f )
|
||||
WriteTimeOffset( f, refTime, cx.Start() );
|
||||
WriteTimeOffset( f, refTime, cx.End() );
|
||||
uint64_t thread = cx.Thread();
|
||||
// Don't care about external thread identifiers
|
||||
if( m_data.threadMap.find( thread ) == m_data.threadMap.end() ) thread = 0;
|
||||
f.Write( &thread, sizeof( thread ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ private:
|
||||
Vector<const char*> stringData;
|
||||
flat_hash_map<charutil::StringKey, uint32_t, charutil::StringKey::HasherPOT, charutil::StringKey::Comparator> stringMap;
|
||||
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> threadNames;
|
||||
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> externalNames;
|
||||
|
||||
flat_hash_map<uint64_t, SourceLocation, nohash<uint64_t>> sourceLocation;
|
||||
Vector<SourceLocation*> sourceLocationPayload;
|
||||
@@ -334,6 +335,7 @@ public:
|
||||
const char* GetThreadString( uint64_t id ) const;
|
||||
bool IsThreadLocal( uint64_t id ) const;
|
||||
const SourceLocation& GetSourceLocation( int16_t srcloc ) const;
|
||||
const char* GetExternalName( uint64_t id ) const;
|
||||
|
||||
const char* GetZoneName( const SourceLocation& srcloc ) const;
|
||||
const char* GetZoneName( const ZoneEvent& ev ) const;
|
||||
@@ -477,6 +479,7 @@ private:
|
||||
|
||||
void CheckString( uint64_t ptr );
|
||||
void CheckThreadString( uint64_t id );
|
||||
void CheckExternalName( uint64_t id );
|
||||
|
||||
void AddSourceLocation( const QueueSourceLocation& srcloc );
|
||||
void AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz );
|
||||
@@ -484,6 +487,7 @@ private:
|
||||
void AddString( uint64_t ptr, char* str, size_t sz );
|
||||
void AddThreadString( uint64_t id, char* str, size_t sz );
|
||||
void AddCustomString( uint64_t ptr, char* str, size_t sz );
|
||||
void AddExternalName( uint64_t ptr, char* str, size_t sz );
|
||||
void AddFrameImageData( uint64_t ptr, char* data, size_t sz );
|
||||
|
||||
tracy_force_inline void AddCallstackPayload( uint64_t ptr, char* data, size_t sz );
|
||||
@@ -560,6 +564,7 @@ private:
|
||||
|
||||
uint32_t m_pendingStrings;
|
||||
uint32_t m_pendingThreads;
|
||||
uint32_t m_pendingExternalNames;
|
||||
uint32_t m_pendingSourceLocation;
|
||||
uint32_t m_pendingCallstackFrames;
|
||||
uint8_t m_pendingCallstackSubframes;
|
||||
|
||||
Reference in New Issue
Block a user