1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

View::Draw() is no longer static.

This commit is contained in:
Bartosz Taudul 2022-10-13 19:50:35 +02:00
parent c89c4f46ea
commit 0a7ae94fcb
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 34 additions and 45 deletions

View File

@ -44,8 +44,6 @@ namespace tracy
double s_time = 0;
static View* s_instance = nullptr;
View::View( void(*cbMainThread)(std::function<void()>, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb )
: m_worker( addr, port )
, m_staticView( false )
@ -66,9 +64,6 @@ View::View( void(*cbMainThread)(std::function<void()>, bool), const char* addr,
, m_userData()
, m_cbMainThread( cbMainThread )
{
assert( s_instance == nullptr );
s_instance = this;
InitMemory();
InitTextEditor( fixedWidth );
}
@ -90,9 +85,6 @@ View::View( void(*cbMainThread)(std::function<void()>, bool), FileRead& f, ImFon
, m_userData( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() )
, m_cbMainThread( cbMainThread )
{
assert( s_instance == nullptr );
s_instance = this;
m_notificationTime = 4;
m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() );
@ -122,9 +114,6 @@ View::~View()
if( m_frameTexture ) FreeTexture( m_frameTexture, m_cbMainThread );
if( m_playback.texture ) FreeTexture( m_playback.texture, m_cbMainThread );
assert( s_instance != nullptr );
s_instance = nullptr;
}
void View::InitMemory()
@ -240,7 +229,7 @@ static_assert( sizeof( CompressionName ) == sizeof( CompressionDesc ), "Unmatche
bool View::Draw()
{
HandshakeStatus status = (HandshakeStatus)s_instance->m_worker.GetHandshakeStatus();
HandshakeStatus status = (HandshakeStatus)m_worker.GetHandshakeStatus();
switch( status )
{
case HandshakeProtocolMismatch:
@ -256,7 +245,7 @@ bool View::Draw()
break;
}
const auto& failure = s_instance->m_worker.GetFailureType();
const auto& failure = m_worker.GetFailureType();
if( failure != Worker::Failure::None )
{
ImGui::OpenPopup( "Instrumentation failure" );
@ -264,7 +253,7 @@ bool View::Draw()
if( ImGui::BeginPopupModal( "Protocol mismatch", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui::PushFont( s_instance->m_bigFont );
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
ImGui::PopFont();
ImGui::TextUnformatted( "The client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server." );
@ -280,7 +269,7 @@ bool View::Draw()
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
s_instance->m_reconnectRequested = true;
m_reconnectRequested = true;
return false;
}
ImGui::EndPopup();
@ -288,7 +277,7 @@ bool View::Draw()
if( ImGui::BeginPopupModal( "Client not ready", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui::PushFont( s_instance->m_bigFont );
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_LIGHTBULB );
ImGui::PopFont();
ImGui::TextUnformatted( "The client you are trying to connect to is no longer able to sent profiling data,\nbecause another server was already connected to it.\nYou can do the following:\n\n 1. Restart the client application.\n 2. Rebuild the client application with on-demand mode enabled." );
@ -304,7 +293,7 @@ bool View::Draw()
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
s_instance->m_reconnectRequested = true;
m_reconnectRequested = true;
return false;
}
ImGui::EndPopup();
@ -312,7 +301,7 @@ bool View::Draw()
if( ImGui::BeginPopupModal( "Client disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui::PushFont( s_instance->m_bigFont );
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_HANDSHAKE );
ImGui::PopFont();
ImGui::TextUnformatted( "The client you are trying to connect to has disconnected during the initial\nconnection handshake. Please check your network configuration." );
@ -328,7 +317,7 @@ bool View::Draw()
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
s_instance->m_reconnectRequested = true;
m_reconnectRequested = true;
return false;
}
ImGui::EndPopup();
@ -336,8 +325,8 @@ bool View::Draw()
if( ImGui::BeginPopupModal( "Instrumentation failure", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
const auto& data = s_instance->m_worker.GetFailureData();
ImGui::PushFont( s_instance->m_bigFont );
const auto& data = m_worker.GetFailureData();
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_SKULL );
ImGui::PopFont();
ImGui::TextUnformatted( "Profiling session terminated due to improper instrumentation.\nPlease correct your program and try again." );
@ -347,22 +336,22 @@ bool View::Draw()
ImGui::Separator();
if( data.srcloc != 0 )
{
const auto& srcloc = s_instance->m_worker.GetSourceLocation( data.srcloc );
const auto& srcloc = m_worker.GetSourceLocation( data.srcloc );
if( srcloc.name.active )
{
TextFocused( "Zone name:", s_instance->m_worker.GetString( srcloc.name ) );
TextFocused( "Zone name:", m_worker.GetString( srcloc.name ) );
}
TextFocused( "Function:", s_instance->m_worker.GetString( srcloc.function ) );
TextFocused( "Function:", m_worker.GetString( srcloc.function ) );
TextDisabledUnformatted( "Location:" );
ImGui::SameLine();
ImGui::TextUnformatted( LocationToString( s_instance->m_worker.GetString( srcloc.file ), srcloc.line ) );
ImGui::TextUnformatted( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) );
}
if( data.thread != 0 )
{
TextFocused( "Thread:", s_instance->m_worker.GetThreadName( data.thread ) );
TextFocused( "Thread:", m_worker.GetThreadName( data.thread ) );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( data.thread ) );
if( s_instance->m_worker.IsThreadFiber( data.thread ) )
if( m_worker.IsThreadFiber( data.thread ) )
{
ImGui::SameLine();
TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
@ -385,11 +374,11 @@ bool View::Draw()
ImGui::TableSetupColumn( "Image" );
ImGui::TableHeadersRow();
auto& cs = s_instance->m_worker.GetCallstack( data.callstack );
auto& cs = m_worker.GetCallstack( data.callstack );
int fidx = 0;
for( auto& entry : cs )
{
auto frameData = s_instance->m_worker.GetCallstackFrame( entry );
auto frameData = m_worker.GetCallstackFrame( entry );
if( !frameData )
{
ImGui::TableNextRow();
@ -397,7 +386,7 @@ bool View::Draw()
ImGui::Text( "%i", fidx++ );
ImGui::TableNextColumn();
char buf[32];
sprintf( buf, "%p", (void*)s_instance->m_worker.GetCanonicalPointer( entry ) );
sprintf( buf, "%p", (void*)m_worker.GetCanonicalPointer( entry ) );
ImGui::TextUnformatted( buf );
if( ImGui::IsItemHovered() )
{
@ -416,7 +405,7 @@ bool View::Draw()
for( uint8_t f=0; f<fsz; f++ )
{
const auto& frame = frameData->data[f];
auto txt = s_instance->m_worker.GetString( frame.name );
auto txt = m_worker.GetString( frame.name );
if( fidx == 0 && f != fsz-1 )
{
@ -469,7 +458,7 @@ bool View::Draw()
}
ImGui::TableNextColumn();
ImGui::PushTextWrapPos( 0.0f );
txt = s_instance->m_worker.GetString( frame.file );
txt = m_worker.GetString( frame.file );
TextDisabledUnformatted( LocationToString( txt, frame.line ) );
if( ImGui::IsItemHovered() )
{
@ -485,7 +474,7 @@ bool View::Draw()
ImGui::TableNextColumn();
if( frameData->imageName.Active() )
{
TextDisabledUnformatted( s_instance->m_worker.GetString( frameData->imageName ) );
TextDisabledUnformatted( m_worker.GetString( frameData->imageName ) );
}
}
}
@ -500,21 +489,21 @@ bool View::Draw()
if( ImGui::Button( "I understand" ) )
{
ImGui::CloseCurrentPopup();
s_instance->m_worker.ClearFailure();
m_worker.ClearFailure();
}
ImGui::EndPopup();
}
bool saveFailed = false;
if( !s_instance->m_filenameStaging.empty() )
if( !m_filenameStaging.empty() )
{
ImGui::OpenPopup( "Save trace" );
}
if( ImGui::BeginPopupModal( "Save trace", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
assert( !s_instance->m_filenameStaging.empty() );
auto fn = s_instance->m_filenameStaging.c_str();
ImGui::PushFont( s_instance->m_bigFont );
assert( !m_filenameStaging.empty() );
auto fn = m_filenameStaging.c_str();
ImGui::PushFont( m_bigFont );
TextFocused( "Path:", fn );
ImGui::PopFont();
ImGui::Separator();
@ -545,7 +534,7 @@ bool View::Draw()
ImGui::Unindent();
static bool buildDict = false;
if( s_instance->m_worker.GetFrameImageCount() != 0 )
if( m_worker.GetFrameImageCount() != 0 )
{
ImGui::Separator();
ImGui::Checkbox( "Build frame images dictionary", &buildDict );
@ -556,14 +545,14 @@ bool View::Draw()
ImGui::Separator();
if( ImGui::Button( ICON_FA_FLOPPY_DISK " Save trace" ) )
{
saveFailed = !s_instance->Save( fn, comp, zlvl, buildDict );
s_instance->m_filenameStaging.clear();
saveFailed = !Save( fn, comp, zlvl, buildDict );
m_filenameStaging.clear();
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if( ImGui::Button( "Cancel" ) )
{
s_instance->m_filenameStaging.clear();
m_filenameStaging.clear();
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
@ -572,7 +561,7 @@ bool View::Draw()
if( saveFailed ) ImGui::OpenPopup( "Save failed" );
if( ImGui::BeginPopupModal( "Save failed", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui::PushFont( s_instance->m_bigFont );
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
ImGui::PopFont();
ImGui::TextUnformatted( "Could not save trace at the specified location. Try again somewhere else." );
@ -582,7 +571,7 @@ bool View::Draw()
}
s_time += ImGui::GetIO().DeltaTime;
return s_instance->DrawImpl();
return DrawImpl();
}
static const char* MainWindowButtons[] = {

View File

@ -95,7 +95,7 @@ public:
View( void(*cbMainThread)(std::function<void()>, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb );
~View();
static bool Draw();
bool Draw();
bool WasActive() const;
void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; }