From 5f22e35c269cd718afed738178aef725b2c70694 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 17 Apr 2020 18:38:14 +0200 Subject: [PATCH] Add UI for source location substitutions. --- server/TracyView.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++- server/TracyView.hpp | 11 +++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index e7608a75..6bc246ba 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -12292,7 +12292,7 @@ void View::DrawInfo() buf[descsz] = '\0'; memcpy( buf, desc.c_str(), descsz ); ImGui::SetNextItemWidth( -1 ); - if( ImGui::InputTextWithHint( "", "Enter description of the trace", buf, 256 ) ) + if( ImGui::InputTextWithHint( "##traceDesc", "Enter description of the trace", buf, 256 ) ) { m_userData.SetDescription( buf ); } @@ -12944,6 +12944,79 @@ void View::DrawInfo() } } + if( ImGui::TreeNode( "Source location substitutions" ) ) + { + static char test[1024] = {}; + ImGui::SetNextItemWidth( -1 ); + ImGui::InputTextWithHint( "##srcSubstTest", "Enter example source location to test substitutions", test, 1024 ); + std::string res = test; + std::string tmp; + if( m_sourceRegexValid ) + { + for( auto& v : m_sourceSubstitutions ) + { + tmp = std::regex_replace( res, v.regex, v.target ); + std::swap( tmp, res ); + } + TextFocused( "Result:", res.c_str() ); + } + else + { + ImGui::TextColored( ImVec4( 255, 0, 0, 255 ), "Error in regular expression" ); + } + if( ImGui::SmallButton( "Add new substitution" ) ) m_sourceSubstitutions.emplace_back( SourceRegex {} ); + int idx = 0, remove = -1; + bool changed = false; + ImGui::Columns( 2, nullptr, false ); + for( auto& v : m_sourceSubstitutions ) + { + ImGui::PushID( idx ); + if( ImGui::Button( ICON_FA_TRASH_ALT ) ) remove = idx; + ImGui::SameLine(); + char tmp[1024]; + strncpy( tmp, v.pattern.c_str(), 1024 ); + ImGui::SetNextItemWidth( -1 ); + if( ImGui::InputTextWithHint( "##pattern", "Regex pattern", tmp, 1024 ) ) + { + v.pattern.assign( tmp ); + changed = true; + } + ImGui::NextColumn(); + strncpy( tmp, v.target.c_str(), 1024 ); + ImGui::SetNextItemWidth( -1 ); + if( ImGui::InputTextWithHint( "##replacement", "Regex replacement", tmp, 1024 ) ) v.target.assign( tmp ); + ImGui::PopID(); + ImGui::NextColumn(); + idx++; + } + ImGui::EndColumns(); + if( remove != -1 ) + { + m_sourceSubstitutions.erase( m_sourceSubstitutions.begin() + remove ); + changed = true; + } + + if( changed ) + { + bool regexValid = true; + for( auto& v : m_sourceSubstitutions ) + { + try + { + v.regex.assign( v.pattern ); + } + catch( std::regex_error& err ) + { + regexValid = false; + break; + } + } + m_sourceRegexValid = regexValid; + } + + ImGui::TreePop(); + } + ImGui::Separator(); TextFocused( "Profiler FPS:", RealToString( int( io.Framerate ) ) ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 44b66b5f..f1514f20 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "TracyBuzzAnim.hpp" @@ -423,6 +424,16 @@ private: bool m_reconnectRequested = false; bool m_firstFrame = true; + struct SourceRegex + { + std::string pattern; + std::string target; + std::regex regex; + }; + + std::vector m_sourceSubstitutions; + bool m_sourceRegexValid = true; + struct FindZone { enum : uint64_t { Unselected = std::numeric_limits::max() - 1 }; enum class GroupBy : int { Thread, UserText, Callstack, Parent, NoGrouping };