mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00: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:
parent
c01ad38d46
commit
47a2512957
@ -124,11 +124,11 @@ public:
|
||||
Range m_waitStackRange;
|
||||
|
||||
private:
|
||||
enum class Namespace : uint8_t
|
||||
enum class ShortenName : uint8_t
|
||||
{
|
||||
Full,
|
||||
Mid,
|
||||
Short
|
||||
Never,
|
||||
Always,
|
||||
WhenNoSpace
|
||||
};
|
||||
|
||||
enum class ShortcutAction : uint8_t
|
||||
@ -177,7 +177,7 @@ private:
|
||||
void InitMemory();
|
||||
void InitTextEditor( ImFont* font );
|
||||
|
||||
const char* ShortenNamespace( const char* name ) const;
|
||||
const char* ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const;
|
||||
|
||||
bool DrawImpl();
|
||||
void DrawNotificationArea();
|
||||
@ -483,7 +483,7 @@ private:
|
||||
bool m_groupWaitStackTopDown = true;
|
||||
|
||||
ShortcutAction m_shortcut = ShortcutAction::None;
|
||||
Namespace m_namespace = Namespace::Short;
|
||||
ShortenName m_shortenName = ShortenName::WhenNoSpace;
|
||||
Animation m_zoomAnim;
|
||||
BuzzAnim<int> m_callstackBuzzAnim;
|
||||
BuzzAnim<int> m_sampleParentBuzzAnim;
|
||||
|
@ -221,16 +221,16 @@ void View::DrawOptions()
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Unindent();
|
||||
m_vd.dynamicColors = ival;
|
||||
ival = (int)m_namespace;
|
||||
ImGui::TextUnformatted( ICON_FA_BOX_OPEN " Namespaces" );
|
||||
ival = (int)m_shortenName;
|
||||
ImGui::TextUnformatted( ICON_FA_RULER_HORIZONTAL " Zone name shortening" );
|
||||
ImGui::Indent();
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
ImGui::RadioButton( "Full", &ival, 0 );
|
||||
ImGui::RadioButton( "Shortened", &ival, 1 );
|
||||
ImGui::RadioButton( "None", &ival, 2 );
|
||||
ImGui::RadioButton( "Never", &ival, 0 );
|
||||
ImGui::RadioButton( "Always", &ival, 1 );
|
||||
ImGui::RadioButton( "When no space", &ival, 2 );
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Unindent();
|
||||
m_namespace = (Namespace)ival;
|
||||
m_shortenName = (ShortenName)ival;
|
||||
ImGui::Unindent();
|
||||
|
||||
if( !m_worker.GetLockMap().empty() )
|
||||
|
@ -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 )
|
||||
|
@ -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 );
|
||||
|
||||
auto origSymName = symName;
|
||||
if( tsz.x > zsz )
|
||||
if( m_shortenName == ShortenName::Always || ( m_shortenName == ShortenName::WhenNoSpace && tsz.x > zsz ) )
|
||||
{
|
||||
symName = ShortenNamespace( symName );
|
||||
tsz = ImGui::CalcTextSize( symName );
|
||||
symName = ShortenZoneName( symName, tsz, 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 );
|
||||
if( tsz.x > zsz )
|
||||
if( m_shortenName == ShortenName::Always || ( m_shortenName == ShortenName::WhenNoSpace && tsz.x > zsz ) )
|
||||
{
|
||||
zoneName = ShortenNamespace( zoneName );
|
||||
tsz = ImGui::CalcTextSize( zoneName );
|
||||
zoneName = ShortenZoneName( zoneName, tsz, zsz );
|
||||
}
|
||||
|
||||
const auto pr0 = ( ev.Start() - m_vd.zvStart ) * pxns;
|
||||
|
Loading…
Reference in New Issue
Block a user