Share the lock display name resolution.

This commit is contained in:
Bartosz Taudul
2026-09-23 22:59:18 +02:00
parent eee89de2d9
commit ae32c0fff8
3 changed files with 13 additions and 48 deletions

View File

@@ -327,6 +327,7 @@ private:
template<typename Adapter, typename V>
int SkipGpuZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
void DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLocation& srcloc, bool hover, ImDrawList* draw, const ImVec2& wpos, float w, float ty, float offset, uint16_t tid );
static const char* GetLockDisplayName( const Worker& worker, const LockMap& lockmap );
int DrawLocks( const TimelineContext& ctx, const std::vector<std::unique_ptr<LockDraw>>& lockDraw, uint64_t tid, int _offset, LockHighlight& highlight );
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem& item, double prev, PlotType type, PlotValueFormatting format, float PlotHeight, uint64_t name );
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, double val, PlotValueFormatting format, float PlotHeight );

View File

@@ -45,17 +45,16 @@ static bool SharedHoldEnded( const LockMap& lockmap, uint16_t slot, const LockSe
return ev.thread == slot && ( LockEvent::Type )ev.type == LockEvent::Type::ReleaseShared;
}
const char* View::GetLockDisplayName( const Worker& worker, const LockMap& lockmap )
{
if( lockmap.customName.Active() ) return worker.GetString( lockmap.customName );
return worker.GetString( worker.GetSourceLocation( lockmap.srcloc ).function );
}
void View::DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLocation& srcloc, bool hover, ImDrawList* draw, const ImVec2& wpos, float w, float ty, float offset, uint16_t tid )
{
char buf[1024];
if( lockmap.customName.Active() )
{
sprintf( buf, "%" PRIu32 ": %s", id, m_worker.GetString( lockmap.customName ) );
}
else
{
sprintf( buf, "%" PRIu32 ": %s", id, m_worker.GetString( srcloc.function ) );
}
sprintf( buf, "%" PRIu32 ": %s", id, GetLockDisplayName( m_worker, lockmap ) );
ImGui::PushFont( g_fonts.normal, FontSmall );
DrawTextContrast( draw, wpos + ImVec2( 0, offset ), 0xFF8888FF, buf );
ImGui::PopFont();
@@ -266,14 +265,7 @@ int View::DrawLocks( const TimelineContext& ctx, const std::vector<std::unique_p
}
ImGui::BeginTooltip();
if( lockmap.customName.Active() )
{
ImGui::Text( "Lock #%" PRIu32 ": %s", lock.id, m_worker.GetString( lockmap.customName ) );
}
else
{
ImGui::Text( "Lock #%" PRIu32 ": %s", lock.id, m_worker.GetString( srcloc.function ) );
}
ImGui::Text( "Lock #%" PRIu32 ": %s", lock.id, GetLockDisplayName( m_worker, lockmap ) );
ImGui::Separator();
ImGui::TextUnformatted( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) );
TextFocused( "Time:", TimeToString( t1 - t0 ) );
@@ -517,14 +509,7 @@ void View::DrawLockInfoWindow()
}
ImGui::PushFont( g_fonts.normal, FontBig );
if( lock.customName.Active() )
{
ImGui::Text( "Lock #%" PRIu32 ": %s", m_lockInfoWindow, m_worker.GetString( lock.customName ) );
}
else
{
ImGui::Text( "Lock #%" PRIu32 ": %s", m_lockInfoWindow, m_worker.GetString( srcloc.function ) );
}
ImGui::Text( "Lock #%" PRIu32 ": %s", m_lockInfoWindow, GetLockDisplayName( m_worker, lock ) );
ImGui::PopFont();
if( lock.customName.Active() )
{

View File

@@ -445,14 +445,7 @@ void View::DrawOptions()
auto fileName = m_worker.GetString( sl.file );
char buf[1024];
if( l.second->customName.Active() )
{
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( l.second->customName ) );
}
else
{
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) );
}
sprintf( buf, "%" PRIu32 ": %s", l.first, GetLockDisplayName( m_worker, *l.second ) );
SmallCheckbox( buf, &Vis( l.second ) );
if( ImGui::IsItemHovered() )
{
@@ -532,14 +525,7 @@ void View::DrawOptions()
auto fileName = m_worker.GetString( sl.file );
char buf[1024];
if( l.second->customName.Active() )
{
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( l.second->customName ) );
}
else
{
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) );
}
sprintf( buf, "%" PRIu32 ": %s", l.first, GetLockDisplayName( m_worker, *l.second ) );
SmallCheckbox( buf, &Vis( l.second ) );
if( ImGui::IsItemHovered() )
{
@@ -619,14 +605,7 @@ void View::DrawOptions()
auto fileName = m_worker.GetString( sl.file );
char buf[1024];
if( l.second->customName.Active() )
{
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( l.second->customName ) );
}
else
{
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) );
}
sprintf( buf, "%" PRIu32 ": %s", l.first, GetLockDisplayName( m_worker, *l.second ) );
SmallCheckbox( buf, &Vis( l.second ) );
if( ImGui::IsItemHovered() )
{