1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 20:33:52 +00:00

Extract more utility functions.

This commit is contained in:
Bartosz Taudul 2022-07-02 13:49:43 +02:00
parent 35f55c781b
commit 44e5218301
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 80 additions and 79 deletions

View File

@ -254,36 +254,6 @@ bool View::ViewDispatch( const char* fileName, int line, uint64_t symAddr )
} }
} }
const char* View::ShortenNamespace( const char* name ) 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;
}
static char buf[1024];
auto dst = buf;
auto ptr = name;
for(;;)
{
auto start = ptr;
while( *ptr != '\0' && *ptr != ':' ) ptr++;
if( *ptr == '\0' )
{
memcpy( dst, start, ptr - start + 1 );
return buf;
}
*dst++ = *start;
*dst++ = ':';
while( *ptr == ':' ) ptr++;
}
}
void View::DrawHelpMarker( const char* desc ) const void View::DrawHelpMarker( const char* desc ) const
{ {
TextDisabledUnformatted( "(?)" ); TextDisabledUnformatted( "(?)" );
@ -2366,55 +2336,6 @@ void View::HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, d
} }
} }
uint64_t View::GetFrameNumber( const FrameData& fd, int i, uint64_t offset ) const
{
if( fd.name == 0 )
{
if( offset == 0 )
{
return i;
}
else
{
return i + offset - 1;
}
}
else
{
return i + 1;
}
}
const char* View::GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint64_t offset ) const
{
const auto fnum = GetFrameNumber( fd, i, offset );
static char buf[1024];
if( fd.name == 0 )
{
if( i == 0 )
{
sprintf( buf, "Tracy init (%s)", TimeToString( ftime ) );
}
else if( offset == 0 )
{
sprintf( buf, "Frame %s (%s)", RealToString( fnum ), TimeToString( ftime ) );
}
else if( i == 1 )
{
sprintf( buf, "Missed frames (%s)", TimeToString( ftime ) );
}
else
{
sprintf( buf, "Frame %s (%s)", RealToString( fnum ), TimeToString( ftime ) );
}
}
else
{
sprintf( buf, "%s %s (%s)", m_worker.GetString( fd.name ), RealToString( fnum ), TimeToString( ftime ) );
}
return buf;
}
void View::DrawZoneFramesHeader() void View::DrawZoneFramesHeader()
{ {
const auto wpos = ImGui::GetCursorScreenPos(); const auto wpos = ImGui::GetCursorScreenPos();

View File

@ -1,4 +1,5 @@
#include "TracyColor.hpp" #include "TracyColor.hpp"
#include "TracyPrint.hpp"
#include "TracyView.hpp" #include "TracyView.hpp"
namespace tracy namespace tracy
@ -725,4 +726,83 @@ int64_t View::AdjustGpuTime( int64_t time, int64_t begin, int drift )
return time + t / 1000000000 * drift; return time + t / 1000000000 * drift;
} }
uint64_t View::GetFrameNumber( const FrameData& fd, int i, uint64_t offset ) const
{
if( fd.name == 0 )
{
if( offset == 0 )
{
return i;
}
else
{
return i + offset - 1;
}
}
else
{
return i + 1;
}
}
const char* View::GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint64_t offset ) const
{
const auto fnum = GetFrameNumber( fd, i, offset );
static char buf[1024];
if( fd.name == 0 )
{
if( i == 0 )
{
sprintf( buf, "Tracy init (%s)", TimeToString( ftime ) );
}
else if( offset == 0 )
{
sprintf( buf, "Frame %s (%s)", RealToString( fnum ), TimeToString( ftime ) );
}
else if( i == 1 )
{
sprintf( buf, "Missed frames (%s)", TimeToString( ftime ) );
}
else
{
sprintf( buf, "Frame %s (%s)", RealToString( fnum ), TimeToString( ftime ) );
}
}
else
{
sprintf( buf, "%s %s (%s)", m_worker.GetString( fd.name ), RealToString( fnum ), TimeToString( ftime ) );
}
return buf;
}
const char* View::ShortenNamespace( const char* name ) 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;
}
static char buf[1024];
auto dst = buf;
auto ptr = name;
for(;;)
{
auto start = ptr;
while( *ptr != '\0' && *ptr != ':' ) ptr++;
if( *ptr == '\0' )
{
memcpy( dst, start, ptr - start + 1 );
return buf;
}
*dst++ = *start;
*dst++ = ':';
while( *ptr == ':' ) ptr++;
}
}
} }