From 47a2512957c9b148b7c1fbc44ff9122f22f870d1 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 15 Aug 2022 14:19:57 +0200 Subject: [PATCH] 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. --- server/TracyView.hpp | 12 +++--- server/TracyView_Options.cpp | 12 +++--- server/TracyView_Utility.cpp | 64 ++++++++++++++++++++++--------- server/TracyView_ZoneTimeline.cpp | 10 ++--- 4 files changed, 61 insertions(+), 37 deletions(-) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 7fd57439..68a5cdbf 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -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 m_callstackBuzzAnim; BuzzAnim m_sampleParentBuzzAnim; diff --git a/server/TracyView_Options.cpp b/server/TracyView_Options.cpp index 34159e23..c264c6e7 100644 --- a/server/TracyView_Options.cpp +++ b/server/TracyView_Options.cpp @@ -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() ) diff --git a/server/TracyView_Utility.cpp b/server/TracyView_Utility.cpp index f9f7345b..2613f69c 100644 --- a/server/TracyView_Utility.cpp +++ b/server/TracyView_Utility.cpp @@ -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 ) diff --git a/server/TracyView_ZoneTimeline.cpp b/server/TracyView_ZoneTimeline.cpp index c11bad9a..73f1b310 100644 --- a/server/TracyView_ZoneTimeline.cpp +++ b/server/TracyView_ZoneTimeline.cpp @@ -217,10 +217,9 @@ int View::DrawGhostLevel( const Vector& 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;