mirror of
https://github.com/wolfpld/tracy
synced 2025-05-01 21:23:52 +00:00
Extract ShortenZoneName() function to a separate file.
This commit is contained in:
parent
07a1383304
commit
8531ef6591
@ -138,6 +138,7 @@
|
|||||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyTimelineController.cpp" />
|
<ClCompile Include="..\..\..\server\TracyTimelineController.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyUserData.cpp" />
|
<ClCompile Include="..\..\..\server\TracyUserData.cpp" />
|
||||||
|
<ClCompile Include="..\..\..\server\TracyUtility.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView_Annotations.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView_Annotations.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView_Callstack.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView_Callstack.cpp" />
|
||||||
@ -272,6 +273,7 @@
|
|||||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyTimelineController.hpp" />
|
<ClInclude Include="..\..\..\server\TracyTimelineController.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyUserData.hpp" />
|
<ClInclude Include="..\..\..\server\TracyUserData.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\server\TracyUtility.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyVarArray.hpp" />
|
<ClInclude Include="..\..\..\server\TracyVarArray.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||||
<ClInclude Include="..\..\..\server\TracyVersion.hpp" />
|
<ClInclude Include="..\..\..\server\TracyVersion.hpp" />
|
||||||
|
@ -354,6 +354,9 @@
|
|||||||
<ClCompile Include="..\..\..\server\TracyTimelineController.cpp">
|
<ClCompile Include="..\..\..\server\TracyTimelineController.cpp">
|
||||||
<Filter>server</Filter>
|
<Filter>server</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\server\TracyUtility.cpp">
|
||||||
|
<Filter>server</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\server\TracyEvent.hpp">
|
<ClInclude Include="..\..\..\server\TracyEvent.hpp">
|
||||||
@ -719,6 +722,9 @@
|
|||||||
<ClInclude Include="..\..\..\server\TracyTimelineController.hpp">
|
<ClInclude Include="..\..\..\server\TracyTimelineController.hpp">
|
||||||
<Filter>server</Filter>
|
<Filter>server</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\server\TracyUtility.hpp">
|
||||||
|
<Filter>server</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Natvis Include="DebugVis.natvis" />
|
<Natvis Include="DebugVis.natvis" />
|
||||||
|
120
server/TracyUtility.cpp
Normal file
120
server/TracyUtility.cpp
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
server/TracyUtility.hpp
Normal file
24
server/TracyUtility.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef __TRACYUTILITY_HPP__
|
||||||
|
#define __TRACYUTILITY_HPP__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#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
|
@ -18,6 +18,7 @@
|
|||||||
#include "TracySourceContents.hpp"
|
#include "TracySourceContents.hpp"
|
||||||
#include "TracyTimelineController.hpp"
|
#include "TracyTimelineController.hpp"
|
||||||
#include "TracyUserData.hpp"
|
#include "TracyUserData.hpp"
|
||||||
|
#include "TracyUtility.hpp"
|
||||||
#include "TracyVector.hpp"
|
#include "TracyVector.hpp"
|
||||||
#include "TracyViewData.hpp"
|
#include "TracyViewData.hpp"
|
||||||
#include "TracyWorker.hpp"
|
#include "TracyWorker.hpp"
|
||||||
@ -124,15 +125,6 @@ public:
|
|||||||
Range m_waitStackRange;
|
Range m_waitStackRange;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class ShortenName : uint8_t
|
|
||||||
{
|
|
||||||
Never,
|
|
||||||
Always,
|
|
||||||
OnlyNormalize,
|
|
||||||
NoSpace,
|
|
||||||
NoSpaceAndNormalize,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ShortcutAction : uint8_t
|
enum class ShortcutAction : uint8_t
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
@ -179,8 +171,6 @@ private:
|
|||||||
void InitMemory();
|
void InitMemory();
|
||||||
void InitTextEditor( ImFont* font );
|
void InitTextEditor( ImFont* font );
|
||||||
|
|
||||||
const char* ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const;
|
|
||||||
|
|
||||||
bool DrawImpl();
|
bool DrawImpl();
|
||||||
void DrawNotificationArea();
|
void DrawNotificationArea();
|
||||||
bool DrawConnection();
|
bool DrawConnection();
|
||||||
|
@ -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 )
|
const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program )
|
||||||
{
|
{
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
|
@ -219,7 +219,7 @@ int View::DrawGhostLevel( const Vector<GhostZone>& vec, bool hover, double pxns,
|
|||||||
auto origSymName = symName;
|
auto origSymName = symName;
|
||||||
if( m_shortenName != ShortenName::Never && ( m_shortenName != ShortenName::NoSpace || tsz.x > zsz ) )
|
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 )
|
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 );
|
auto tsz = ImGui::CalcTextSize( zoneName );
|
||||||
if( m_shortenName != ShortenName::Never && ( m_shortenName != ShortenName::NoSpace || tsz.x > zsz ) )
|
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;
|
const auto pr0 = ( ev.Start() - m_vd.zvStart ) * pxns;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user