From 779165489607eb83a15c41fa9a38e3fa51aab6d3 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 30 Oct 2020 18:27:52 +0100 Subject: [PATCH] Allow copying callstack to clipboard. --- server/TracyView.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 84678a15..3a7b3f35 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -12927,6 +12928,80 @@ void View::DrawCallstackWindow() ImGui::SetNextWindowSize( ImVec2( 1400, 500 ), ImGuiCond_FirstUseEver ); ImGui::Begin( "Call stack", &show, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse ); + auto& cs = m_worker.GetCallstack( m_callstackInfoWindow ); + if( ClipboardButton() ) + { + std::ostringstream s; + int fidx = 0; + int bidx = 0; + for( auto& entry : cs ) + { + char buf[64*1024]; + auto frameData = m_worker.GetCallstackFrame( entry ); + if( !frameData ) + { + sprintf( buf, "%3i. %p\n", fidx++, (void*)m_worker.GetCanonicalPointer( entry ) ); + } + else + { + auto ptr = buf; + const auto fsz = frameData->size; + for( uint8_t f=0; fdata[f]; + auto txt = m_worker.GetString( frame.name ); + + if( fidx == 0 && f != fsz-1 ) + { + auto test = tracy::s_tracyStackFrames; + bool match = false; + do + { + if( strcmp( txt, *test ) == 0 ) + { + match = true; + break; + } + } + while( *++test ); + if( match ) continue; + } + + bidx++; + + if( f == fsz-1 ) + { + ptr += sprintf( ptr, "%3i. ", fidx++ ); + } + else + { + ptr += sprintf( ptr, "inl. " ); + } + ptr += sprintf( ptr, "%s ", txt ); + txt = m_worker.GetString( frame.file ); + if( frame.line == 0 ) + { + ptr += sprintf( ptr, "(%s)", txt ); + } + else + { + ptr += sprintf( ptr, "(%s:%" PRIu32 ")", txt, frame.line ); + } + if( frameData->imageName.Active() ) + { + ptr += sprintf( ptr, " %s\n", m_worker.GetString( frameData->imageName ) ); + } + else + { + ptr += sprintf( ptr, "\n" ); + } + } + } + s << buf; + } + ImGui::SetClipboardText( s.str().c_str() ); + } + ImGui::SameLine(); ImGui::TextUnformatted( ICON_FA_AT " Frame location:" ); ImGui::SameLine(); ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); @@ -12938,7 +13013,6 @@ void View::DrawCallstackWindow() ImGui::SameLine(); ImGui::RadioButton( "Symbol address", &m_showCallstackFrameAddress, 2 ); - auto& cs = m_worker.GetCallstack( m_callstackInfoWindow ); if( m_worker.AreCallstackSamplesReady() ) { auto frame = m_worker.GetCallstackFrame( *cs.begin() );