Extract zone name getting functionality.

This commit is contained in:
Bartosz Taudul 2018-06-29 15:14:20 +02:00
parent 102234321d
commit 865e8d8506
3 changed files with 47 additions and 51 deletions

View File

@ -1244,7 +1244,6 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
while( it < zitend ) while( it < zitend )
{ {
auto& ev = **it; auto& ev = **it;
auto& srcloc = m_worker.GetSourceLocation( ev.srcloc );
const auto color = GetZoneColor( ev ); const auto color = GetZoneColor( ev );
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto zsz = std::max( ( end - ev.start ) * pxns, pxns * 0.5 ); const auto zsz = std::max( ( end - ev.start ) * pxns, pxns * 0.5 );
@ -1306,16 +1305,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
} }
else else
{ {
const char* zoneName; const char* zoneName = m_worker.GetZoneName( ev );
if( srcloc.name.active )
{
zoneName = m_worker.GetString( srcloc.name );
}
else
{
zoneName = m_worker.GetString( srcloc.function );
}
int dmul = ev.text.active ? 2 : 1; int dmul = ev.text.active ? 2 : 1;
bool migration = false; bool migration = false;
@ -1514,7 +1504,6 @@ int View::DrawGpuZoneLevel( const Vector<GpuEvent*>& vec, bool hover, double pxn
while( it < zitend ) while( it < zitend )
{ {
auto& ev = **it; auto& ev = **it;
auto& srcloc = m_worker.GetSourceLocation( ev.srcloc );
const auto color = GetZoneColor( ev ); const auto color = GetZoneColor( ev );
auto end = m_worker.GetZoneEnd( ev ); auto end = m_worker.GetZoneEnd( ev );
if( end == std::numeric_limits<int64_t>::max() ) break; if( end == std::numeric_limits<int64_t>::max() ) break;
@ -1589,7 +1578,7 @@ int View::DrawGpuZoneLevel( const Vector<GpuEvent*>& vec, bool hover, double pxn
if( d > maxdepth ) maxdepth = d; if( d > maxdepth ) maxdepth = d;
} }
const char* zoneName = m_worker.GetString( srcloc.name ); const char* zoneName = m_worker.GetZoneName( ev );
auto tsz = ImGui::CalcTextSize( zoneName ); auto tsz = ImGui::CalcTextSize( zoneName );
const auto pr0 = ( start - m_zvStart ) * pxns; const auto pr0 = ( start - m_zvStart ) * pxns;
@ -3054,7 +3043,7 @@ void View::DrawZoneInfoWindow()
int idx = 0; int idx = 0;
DrawZoneTrace<const ZoneEvent*>( &ev, zoneTrace, m_worker, [&idx, this] ( const ZoneEvent* v ) { DrawZoneTrace<const ZoneEvent*>( &ev, zoneTrace, m_worker, [&idx, this] ( const ZoneEvent* v ) {
const auto& srcloc = m_worker.GetSourceLocation( v->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( v->srcloc );
const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function ); const auto txt = m_worker.GetZoneName( *v, srcloc );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
auto sel = ImGui::Selectable( txt, false ); auto sel = ImGui::Selectable( txt, false );
auto hover = ImGui::IsItemHovered(); auto hover = ImGui::IsItemHovered();
@ -3108,8 +3097,7 @@ void View::DrawZoneInfoWindow()
for( size_t i=0; i<ev.child.size(); i++ ) for( size_t i=0; i<ev.child.size(); i++ )
{ {
auto& cev = *ev.child[cti[i]]; auto& cev = *ev.child[cti[i]];
const auto& csl = m_worker.GetSourceLocation( cev.srcloc ); const auto txt = m_worker.GetZoneName( cev );
const auto txt = csl.name.active ? m_worker.GetString( csl.name ) : m_worker.GetString( csl.function );
bool b = false; bool b = false;
ImGui::PushID( (int)i ); ImGui::PushID( (int)i );
if( ImGui::Selectable( txt, &b, ImGuiSelectableFlags_SpanAllColumns ) ) if( ImGui::Selectable( txt, &b, ImGuiSelectableFlags_SpanAllColumns ) )
@ -3243,7 +3231,7 @@ void View::DrawGpuInfoWindow()
int idx = 0; int idx = 0;
DrawZoneTrace<const GpuEvent*>( &ev, zoneTrace, m_worker, [&idx, this] ( const GpuEvent* v ) { DrawZoneTrace<const GpuEvent*>( &ev, zoneTrace, m_worker, [&idx, this] ( const GpuEvent* v ) {
const auto& srcloc = m_worker.GetSourceLocation( v->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( v->srcloc );
const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function ); const auto txt = m_worker.GetZoneName( *v, srcloc );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
auto sel = ImGui::Selectable( txt, false ); auto sel = ImGui::Selectable( txt, false );
auto hover = ImGui::IsItemHovered(); auto hover = ImGui::IsItemHovered();
@ -3297,10 +3285,9 @@ void View::DrawGpuInfoWindow()
for( size_t i=0; i<ev.child.size(); i++ ) for( size_t i=0; i<ev.child.size(); i++ )
{ {
auto& cev = *ev.child[cti[i]]; auto& cev = *ev.child[cti[i]];
const auto& csl = m_worker.GetSourceLocation( cev.srcloc );
bool b = false; bool b = false;
ImGui::PushID( (int)i ); ImGui::PushID( (int)i );
if( ImGui::Selectable( m_worker.GetString( csl.name ), &b, ImGuiSelectableFlags_SpanAllColumns ) ) if( ImGui::Selectable( m_worker.GetZoneName( cev ), &b, ImGuiSelectableFlags_SpanAllColumns ) )
{ {
ShowZoneInfo( cev, m_gpuInfoWindowThread ); ShowZoneInfo( cev, m_gpuInfoWindowThread );
} }
@ -5787,36 +5774,16 @@ void View::ZoneTooltip( const ZoneEvent& ev )
const auto tid = GetZoneThread( ev ); const auto tid = GetZoneThread( ev );
auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); auto& srcloc = m_worker.GetSourceLocation( ev.srcloc );
const auto filename = m_worker.GetString( srcloc.file );
const auto line = srcloc.line;
const char* func;
const char* zoneName;
if( srcloc.name.active )
{
zoneName = m_worker.GetString( srcloc.name );
func = m_worker.GetString( srcloc.function );
}
else
{
func = zoneName = m_worker.GetString( srcloc.function );
}
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
ImGui::BeginTooltip(); ImGui::BeginTooltip();
if( srcloc.name.active ) if( srcloc.name.active )
{ {
ImGui::Text( "%s", zoneName ); ImGui::Text( "%s", m_worker.GetString( srcloc.name ) );
ImGui::Text( "%s", func );
}
else
{
ImGui::Text( "%s", func );
} }
ImGui::Text( "%s", m_worker.GetString( srcloc.function ) );
ImGui::Separator(); ImGui::Separator();
ImGui::Text( "%s:%i", filename, line ); ImGui::Text( "%s:%i", m_worker.GetString( srcloc.file ), srcloc.line );
ImGui::Text( "Thread: %s", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread: %s", m_worker.GetThreadString( tid ) );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(0x%" PRIX64 ")", tid ); ImGui::TextDisabled( "(0x%" PRIX64 ")", tid );
@ -5846,19 +5813,13 @@ void View::ZoneTooltip( const GpuEvent& ev )
{ {
const auto tid = GetZoneThread( ev ); const auto tid = GetZoneThread( ev );
const auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); const auto& srcloc = m_worker.GetSourceLocation( ev.srcloc );
const auto name = m_worker.GetString( srcloc.name );
const auto filename = m_worker.GetString( srcloc.file );
const auto line = srcloc.line;
const auto func = m_worker.GetString( srcloc.function );
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
ImGui::BeginTooltip(); ImGui::BeginTooltip();
ImGui::Text( "%s", name ); ImGui::Text( "%s", m_worker.GetString( srcloc.name ) );
ImGui::Text( "%s", func ); ImGui::Text( "%s", m_worker.GetString( srcloc.function ) );
ImGui::Separator(); ImGui::Separator();
ImGui::Text( "%s:%i", filename, line ); ImGui::Text( "%s:%i", m_worker.GetString( srcloc.file ), srcloc.line );
ImGui::Text( "Thread: %s", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread: %s", m_worker.GetThreadString( tid ) );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(0x%" PRIX64 ")", tid ); ImGui::TextDisabled( "(0x%" PRIX64 ")", tid );

View File

@ -853,6 +853,36 @@ const SourceLocation& Worker::GetSourceLocation( int32_t srcloc ) const
} }
} }
const char* Worker::GetZoneName( const ZoneEvent& ev ) const
{
auto& srcloc = GetSourceLocation( ev.srcloc );
return GetZoneName( ev, srcloc );
}
const char* Worker::GetZoneName( const ZoneEvent& ev, const SourceLocation& srcloc ) const
{
if( srcloc.name.active )
{
return GetString( srcloc.name );
}
else
{
return GetString( srcloc.function );
}
}
const char* Worker::GetZoneName( const GpuEvent& ev ) const
{
auto& srcloc = GetSourceLocation( ev.srcloc );
return GetZoneName( ev, srcloc );
}
const char* Worker::GetZoneName( const GpuEvent& ev, const SourceLocation& srcloc ) const
{
assert( srcloc.name.active );
return GetString( srcloc.name );
}
std::vector<int32_t> Worker::GetMatchingSourceLocation( const char* query ) const std::vector<int32_t> Worker::GetMatchingSourceLocation( const char* query ) const
{ {
std::vector<int32_t> match; std::vector<int32_t> match;

View File

@ -180,6 +180,11 @@ public:
const char* GetThreadString( uint64_t id ) const; const char* GetThreadString( uint64_t id ) const;
const SourceLocation& GetSourceLocation( int32_t srcloc ) const; const SourceLocation& GetSourceLocation( int32_t srcloc ) const;
const char* GetZoneName( const ZoneEvent& ev ) const;
const char* GetZoneName( const ZoneEvent& ev, const SourceLocation& srcloc ) const;
const char* GetZoneName( const GpuEvent& ev ) const;
const char* GetZoneName( const GpuEvent& ev, const SourceLocation& srcloc ) const;
std::vector<int32_t> GetMatchingSourceLocation( const char* query ) const; std::vector<int32_t> GetMatchingSourceLocation( const char* query ) const;
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS