diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 081735dc..fd149776 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -138,6 +138,7 @@ + @@ -272,6 +273,7 @@ + diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index d1731d98..161c1ef2 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -354,6 +354,9 @@ server + + server + @@ -719,6 +722,9 @@ server + + server + diff --git a/server/TracyUtility.cpp b/server/TracyUtility.cpp new file mode 100644 index 00000000..684637f5 --- /dev/null +++ b/server/TracyUtility.cpp @@ -0,0 +1,120 @@ +#include + +#include "TracyUtility.hpp" + +namespace tracy +{ + +// Short list based on GetTypes() in TracySourceTokenizer.cpp +constexpr const char* TypesList[] = { + "bool ", "char ", "double ", "float ", "int ", "long ", "short ", + "signed ", "unsigned ", "void ", "wchar_t ", "size_t ", "int8_t ", + "int16_t ", "int32_t ", "int64_t ", "intptr_t ", "uint8_t ", "uint16_t ", + "uint32_t ", "uint64_t ", "ptrdiff_t ", nullptr +}; + +const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, float zsz ) +{ + assert( type != ShortenName::Never ); + if( name[0] == '<' ) return name; + if( type == ShortenName::Always ) zsz = 0; + + static char buf[64*1024]; + char tmp[64*1024]; + + auto end = name; + while( *end ) end++; + + auto ptr = name; + auto dst = tmp; + int cnt = 0; + for(;;) + { + auto start = ptr; + while( ptr < end && *ptr != '<' ) ptr++; + memcpy( dst, start, ptr - start + 1 ); + dst += ptr - start + 1; + if( ptr == end ) break; + cnt++; + ptr++; + while( cnt > 0 ) + { + if( ptr == end ) break; + if( *ptr == '<' ) cnt++; + else if( *ptr == '>' ) cnt--; + ptr++; + } + *dst++ = '>'; + } + + end = dst-1; + ptr = tmp; + dst = buf; + cnt = 0; + for(;;) + { + auto start = ptr; + while( ptr < end && *ptr != '(' ) ptr++; + memcpy( dst, start, ptr - start + 1 ); + dst += ptr - start + 1; + if( ptr == end ) break; + cnt++; + ptr++; + while( cnt > 0 ) + { + if( ptr == end ) break; + if( *ptr == '(' ) cnt++; + else if( *ptr == ')' ) cnt--; + ptr++; + } + *dst++ = ')'; + } + + end = dst-1; + if( end - buf > 6 && memcmp( end-6, " const", 6 ) == 0 ) + { + dst[-7] = '\0'; + end -= 6; + } + + ptr = buf; + for(;;) + { + auto match = TypesList; + while( *match ) + { + auto m = *match; + auto p = ptr; + while( *m ) + { + if( *m != *p ) break; + m++; + p++; + } + if( !*m ) + { + ptr = p; + break; + } + match++; + } + if( !*match ) break; + } + + tsz = ImGui::CalcTextSize( ptr, end ); + if( type == ShortenName::OnlyNormalize || tsz.x < zsz ) return ptr; + + for(;;) + { + auto p = ptr; + while( p < end && *p != ':' ) p++; + if( p == end ) return ptr; + p++; + while( p < end && *p == ':' ) p++; + ptr = p; + tsz = ImGui::CalcTextSize( ptr, end ); + if( tsz.x < zsz ) return ptr; + } +} + +} diff --git a/server/TracyUtility.hpp b/server/TracyUtility.hpp new file mode 100644 index 00000000..d30c727d --- /dev/null +++ b/server/TracyUtility.hpp @@ -0,0 +1,24 @@ +#ifndef __TRACYUTILITY_HPP__ +#define __TRACYUTILITY_HPP__ + +#include + +#include "imgui.h" + +namespace tracy +{ + +enum class ShortenName : uint8_t +{ + Never, + Always, + OnlyNormalize, + NoSpace, + NoSpaceAndNormalize, +}; + +const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, float zsz ); + +} + +#endif diff --git a/server/TracyView.hpp b/server/TracyView.hpp index a3b2f98b..459cc5b4 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -18,6 +18,7 @@ #include "TracySourceContents.hpp" #include "TracyTimelineController.hpp" #include "TracyUserData.hpp" +#include "TracyUtility.hpp" #include "TracyVector.hpp" #include "TracyViewData.hpp" #include "TracyWorker.hpp" @@ -124,15 +125,6 @@ public: Range m_waitStackRange; private: - enum class ShortenName : uint8_t - { - Never, - Always, - OnlyNormalize, - NoSpace, - NoSpaceAndNormalize, - }; - enum class ShortcutAction : uint8_t { None, @@ -179,8 +171,6 @@ private: void InitMemory(); void InitTextEditor( ImFont* font ); - const char* ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const; - bool DrawImpl(); void DrawNotificationArea(); bool DrawConnection(); diff --git a/server/TracyView_Utility.cpp b/server/TracyView_Utility.cpp index 63415bb5..1b63f04d 100644 --- a/server/TracyView_Utility.cpp +++ b/server/TracyView_Utility.cpp @@ -826,118 +826,6 @@ const char* View::GetFrameSetName( const FrameData& fd, const Worker& worker ) } } -// Short list based on GetTypes() in TracySourceTokenizer.cpp -constexpr const char* TypesList[] = { - "bool ", "char ", "double ", "float ", "int ", "long ", "short ", - "signed ", "unsigned ", "void ", "wchar_t ", "size_t ", "int8_t ", - "int16_t ", "int32_t ", "int64_t ", "intptr_t ", "uint8_t ", "uint16_t ", - "uint32_t ", "uint64_t ", "ptrdiff_t ", nullptr -}; - -const char* View::ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const -{ - assert( m_shortenName != ShortenName::Never ); - if( name[0] == '<' ) return name; - if( m_shortenName == ShortenName::Always ) zsz = 0; - - static char buf[64*1024]; - char tmp[64*1024]; - - auto end = name; - while( *end ) end++; - - auto ptr = name; - auto dst = tmp; - int cnt = 0; - for(;;) - { - auto start = ptr; - while( ptr < end && *ptr != '<' ) ptr++; - memcpy( dst, start, ptr - start + 1 ); - dst += ptr - start + 1; - if( ptr == end ) break; - cnt++; - ptr++; - while( cnt > 0 ) - { - if( ptr == end ) break; - if( *ptr == '<' ) cnt++; - else if( *ptr == '>' ) cnt--; - ptr++; - } - *dst++ = '>'; - } - - end = dst-1; - ptr = tmp; - dst = buf; - cnt = 0; - for(;;) - { - auto start = ptr; - while( ptr < end && *ptr != '(' ) ptr++; - memcpy( dst, start, ptr - start + 1 ); - dst += ptr - start + 1; - if( ptr == end ) break; - cnt++; - ptr++; - while( cnt > 0 ) - { - if( ptr == end ) break; - if( *ptr == '(' ) cnt++; - else if( *ptr == ')' ) cnt--; - ptr++; - } - *dst++ = ')'; - } - - end = dst-1; - if( end - buf > 6 && memcmp( end-6, " const", 6 ) == 0 ) - { - dst[-7] = '\0'; - end -= 6; - } - - ptr = buf; - for(;;) - { - auto match = TypesList; - while( *match ) - { - auto m = *match; - auto p = ptr; - while( *m ) - { - if( *m != *p ) break; - m++; - p++; - } - if( !*m ) - { - ptr = p; - break; - } - match++; - } - if( !*match ) break; - } - - tsz = ImGui::CalcTextSize( ptr, end ); - if( m_shortenName == ShortenName::OnlyNormalize || tsz.x < zsz ) return ptr; - - for(;;) - { - auto p = ptr; - while( p < end && *p != ':' ) p++; - if( p == end ) return ptr; - p++; - while( p < end && *p == ':' ) p++; - ptr = p; - tsz = ImGui::CalcTextSize( ptr, end ); - if( tsz.x < zsz ) return ptr; - } -} - const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program ) { static char buf[256]; diff --git a/server/TracyView_ZoneTimeline.cpp b/server/TracyView_ZoneTimeline.cpp index 73450e89..41a3decd 100644 --- a/server/TracyView_ZoneTimeline.cpp +++ b/server/TracyView_ZoneTimeline.cpp @@ -219,7 +219,7 @@ int View::DrawGhostLevel( const Vector& vec, bool hover, double pxns, auto origSymName = symName; if( m_shortenName != ShortenName::Never && ( m_shortenName != ShortenName::NoSpace || tsz.x > zsz ) ) { - symName = ShortenZoneName( symName, tsz, zsz ); + symName = ShortenZoneName( m_shortenName, symName, tsz, zsz ); } if( tsz.x < zsz ) @@ -512,7 +512,7 @@ int View::DrawZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, co auto tsz = ImGui::CalcTextSize( zoneName ); if( m_shortenName != ShortenName::Never && ( m_shortenName != ShortenName::NoSpace || tsz.x > zsz ) ) { - zoneName = ShortenZoneName( zoneName, tsz, zsz ); + zoneName = ShortenZoneName( m_shortenName, zoneName, tsz, zsz ); } const auto pr0 = ( ev.Start() - m_vd.zvStart ) * pxns;