Change namespace shortening to zone name shortening.

Namespace shortening was kinda ok for function names produced by MSVC, which
are generally clean looking. However, gcc/clang like to produce function names
which include template arguments, function parameters, return values, etc. In
such cases the old algorithm simply didn't work, because removal of everything
before the last :: could as well happen in midst of function parameters list.
The result was certainly not an usable function name.

With this new approach namespaces are no longer explicitly mentioned and this
functionality is simply called zone name shortening.

The user-selectable options were changed to make the shortening always
enabled, disabled, or to apply as needed. Note that the "as needed" approach
will be dynamic, trying to gradually remove more and more from the name, until
it fits in the requested area.

Current implementation is only the first step into making this work. In this
first step the function parameters are reduced to () and the template
arguments are reduced to <>. This alone greatly improves readability of the
zone names.

The option to reduce namespaces to one letter (i.e. std::tr1::hash would
become s:t:hash) will no longer be present, now or in the future.
This commit is contained in:
Bartosz Taudul 2022-08-15 14:19:57 +02:00
parent c01ad38d46
commit 47a2512957
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
4 changed files with 61 additions and 37 deletions

View File

@ -124,11 +124,11 @@ public:
Range m_waitStackRange; Range m_waitStackRange;
private: private:
enum class Namespace : uint8_t enum class ShortenName : uint8_t
{ {
Full, Never,
Mid, Always,
Short WhenNoSpace
}; };
enum class ShortcutAction : uint8_t enum class ShortcutAction : uint8_t
@ -177,7 +177,7 @@ private:
void InitMemory(); void InitMemory();
void InitTextEditor( ImFont* font ); void InitTextEditor( ImFont* font );
const char* ShortenNamespace( const char* name ) const; const char* ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const;
bool DrawImpl(); bool DrawImpl();
void DrawNotificationArea(); void DrawNotificationArea();
@ -483,7 +483,7 @@ private:
bool m_groupWaitStackTopDown = true; bool m_groupWaitStackTopDown = true;
ShortcutAction m_shortcut = ShortcutAction::None; ShortcutAction m_shortcut = ShortcutAction::None;
Namespace m_namespace = Namespace::Short; ShortenName m_shortenName = ShortenName::WhenNoSpace;
Animation m_zoomAnim; Animation m_zoomAnim;
BuzzAnim<int> m_callstackBuzzAnim; BuzzAnim<int> m_callstackBuzzAnim;
BuzzAnim<int> m_sampleParentBuzzAnim; BuzzAnim<int> m_sampleParentBuzzAnim;

View File

@ -221,16 +221,16 @@ void View::DrawOptions()
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::Unindent(); ImGui::Unindent();
m_vd.dynamicColors = ival; m_vd.dynamicColors = ival;
ival = (int)m_namespace; ival = (int)m_shortenName;
ImGui::TextUnformatted( ICON_FA_BOX_OPEN " Namespaces" ); ImGui::TextUnformatted( ICON_FA_RULER_HORIZONTAL " Zone name shortening" );
ImGui::Indent(); ImGui::Indent();
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
ImGui::RadioButton( "Full", &ival, 0 ); ImGui::RadioButton( "Never", &ival, 0 );
ImGui::RadioButton( "Shortened", &ival, 1 ); ImGui::RadioButton( "Always", &ival, 1 );
ImGui::RadioButton( "None", &ival, 2 ); ImGui::RadioButton( "When no space", &ival, 2 );
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::Unindent(); ImGui::Unindent();
m_namespace = (Namespace)ival; m_shortenName = (ShortenName)ival;
ImGui::Unindent(); ImGui::Unindent();
if( !m_worker.GetLockMap().empty() ) if( !m_worker.GetLockMap().empty() )

View File

@ -826,35 +826,61 @@ const char* View::GetFrameSetName( const FrameData& fd, const Worker& worker )
} }
} }
const char* View::ShortenNamespace( const char* name ) const const char* View::ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const
{ {
if( m_namespace == Namespace::Full ) return name; assert( m_shortenName != ShortenName::Never );
if( m_namespace == Namespace::Short ) if( m_shortenName == ShortenName::Always ) zsz = 0;
{
auto ptr = name; static char buf[64*1024];
while( *ptr != '\0' ) ptr++; char tmp[64*1024];
while( ptr > name && *ptr != ':' ) ptr--;
if( *ptr == ':' ) ptr++;
return ptr;
}
static char buf[1024];
auto dst = buf;
auto ptr = name; auto ptr = name;
auto dst = tmp;
int cnt = 0;
for(;;) for(;;)
{ {
auto start = ptr; auto start = ptr;
while( *ptr != '\0' && *ptr != ':' ) ptr++; while( *ptr && *ptr != '<' ) ptr++;
if( *ptr == '\0' )
{
memcpy( dst, start, ptr - start + 1 ); memcpy( dst, start, ptr - start + 1 );
if( !*ptr ) break;
dst += ptr - start + 1;
cnt++;
ptr++;
while( cnt > 0 )
{
if( !*ptr ) break;
if( *ptr == '<' ) cnt++;
else if( *ptr == '>' ) cnt--;
ptr++;
}
*dst++ = '>';
}
ptr = tmp;
dst = buf;
cnt = 0;
for(;;)
{
auto start = ptr;
while( *ptr && *ptr != '(' ) ptr++;
memcpy( dst, start, ptr - start + 1 );
if( !*ptr ) break;
dst += ptr - start + 1;
cnt++;
ptr++;
while( cnt > 0 )
{
if( !*ptr ) break;
if( *ptr == '(' ) cnt++;
else if( *ptr == ')' ) cnt--;
ptr++;
}
*dst++ = ')';
}
tsz = ImGui::CalcTextSize( buf );
return buf; return buf;
} }
*dst++ = *start;
*dst++ = ':';
while( *ptr == ':' ) ptr++;
}
}
const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program ) const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program )
{ {

View File

@ -217,10 +217,9 @@ int View::DrawGhostLevel( const Vector<GhostZone>& vec, bool hover, double pxns,
DrawLine( draw, dpos + ImVec2( px0, offset + tsz.y ), dpos + ImVec2( px1-1, offset + tsz.y ), dpos + ImVec2( px1-1, offset ), darkColor, 1.f ); DrawLine( draw, dpos + ImVec2( px0, offset + tsz.y ), dpos + ImVec2( px1-1, offset + tsz.y ), dpos + ImVec2( px1-1, offset ), darkColor, 1.f );
auto origSymName = symName; auto origSymName = symName;
if( tsz.x > zsz ) if( m_shortenName == ShortenName::Always || ( m_shortenName == ShortenName::WhenNoSpace && tsz.x > zsz ) )
{ {
symName = ShortenNamespace( symName ); symName = ShortenZoneName( symName, tsz, zsz );
tsz = ImGui::CalcTextSize( symName );
} }
if( tsz.x < zsz ) if( tsz.x < zsz )
@ -511,10 +510,9 @@ int View::DrawZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, co
} }
auto tsz = ImGui::CalcTextSize( zoneName ); auto tsz = ImGui::CalcTextSize( zoneName );
if( tsz.x > zsz ) if( m_shortenName == ShortenName::Always || ( m_shortenName == ShortenName::WhenNoSpace && tsz.x > zsz ) )
{ {
zoneName = ShortenNamespace( zoneName ); zoneName = ShortenZoneName( zoneName, tsz, zsz );
tsz = ImGui::CalcTextSize( zoneName );
} }
const auto pr0 = ( ev.Start() - m_vd.zvStart ) * pxns; const auto pr0 = ( ev.Start() - m_vd.zvStart ) * pxns;