1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

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
4 changed files with 61 additions and 37 deletions
+45 -19
View File
@@ -826,34 +826,60 @@ 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;
if( m_namespace == Namespace::Short )
{
auto ptr = name;
while( *ptr != '\0' ) ptr++;
while( ptr > name && *ptr != ':' ) ptr--;
if( *ptr == ':' ) ptr++;
return ptr;
}
assert( m_shortenName != ShortenName::Never );
if( m_shortenName == ShortenName::Always ) zsz = 0;
static char buf[64*1024];
char tmp[64*1024];
static char buf[1024];
auto dst = buf;
auto ptr = name;
auto dst = tmp;
int cnt = 0;
for(;;)
{
auto start = ptr;
while( *ptr != '\0' && *ptr != ':' ) ptr++;
if( *ptr == '\0' )
while( *ptr && *ptr != '<' ) ptr++;
memcpy( dst, start, ptr - start + 1 );
if( !*ptr ) break;
dst += ptr - start + 1;
cnt++;
ptr++;
while( cnt > 0 )
{
memcpy( dst, start, ptr - start + 1 );
return buf;
if( !*ptr ) break;
if( *ptr == '<' ) cnt++;
else if( *ptr == '>' ) cnt--;
ptr++;
}
*dst++ = *start;
*dst++ = ':';
while( *ptr == ':' ) 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;
}
const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program )