From 0a7ae94fcb7eba8687610ab06c0dce628ff25538 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 13 Oct 2022 19:50:35 +0200 Subject: View::Draw() is no longer static. --- server/TracyView.cpp | 77 ++++++++++++++++++++++------------------------------ server/TracyView.hpp | 2 +- 2 files changed, 34 insertions(+), 45 deletions(-) (limited to 'server') diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 25c8d21d..e2d740db 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -44,8 +44,6 @@ namespace tracy double s_time = 0; -static View* s_instance = nullptr; - View::View( void(*cbMainThread)(std::function, 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, 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, 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; fdata[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[] = { diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 3c942cc6..c3c5312f 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -95,7 +95,7 @@ public: View( void(*cbMainThread)(std::function, 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; } -- cgit v1.2.3