diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 0f46143c..43cae2d1 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2735,88 +2735,6 @@ void View::DrawZones() } } -void View::DrawSamples( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ) -{ - auto it = std::lower_bound( vec.begin(), vec.end(), m_vd.zvStart, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); - if( it == vec.end() ) return; - const auto itend = std::lower_bound( it, vec.end(), m_vd.zvEnd, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); - if( it == itend ) return; - - const auto ty0375 = offset + round( ImGui::GetTextLineHeight() * 0.375f ); - const auto ty02 = round( ImGui::GetTextLineHeight() * 0.2f ); - const auto ty01 = round( ImGui::GetTextLineHeight() * 0.1f ); - const auto y0 = ty0375 - ty02 - 3; - const auto y1 = ty0375 + ty02 - 1; - auto draw = ImGui::GetWindowDrawList(); - - const auto MinVis = 6 * GetScale(); - bool tooltipDisplayed = false; - - while( it < itend ) - { - bool visible = true; - const auto px0 = ( it->time.Val() - m_vd.zvStart ) * pxns; - double px1; - auto next = it+1; - int num; - if( next != itend ) - { - auto px1ns = next->time.Val() - m_vd.zvStart; - px1 = px1ns * pxns; - if( px1 - px0 < MinVis ) - { - const auto MinVisNs = MinVis * nspx; - visible = false; - auto nextTime = px0 + MinVisNs; - for(;;) - { - const auto prev = next; - next = std::lower_bound( next, itend, nextTime, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); - if( prev == next ) ++next; - if( next == itend ) break; - const auto nsnext = next->time.Val() - m_vd.zvStart; - if( nsnext - px1ns >= MinVisNs ) break; - px1ns = nsnext; - nextTime = next->time.Val() + nspx; - } - num = next - it; - px1 = px1ns * pxns; - } - } - if( visible ) - { - draw->AddCircleFilled( wpos + ImVec2( px0, ty0375 ), ty02, 0xFFDD8888 ); - if( !tooltipDisplayed && hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0 - ty02 - 2, y0 ), wpos + ImVec2( px0 + ty02 + 1, y1 ) ) ) - { - tooltipDisplayed = true; - CallstackTooltip( it->callstack.Val() ); - if( IsMouseClicked( 0 ) ) - { - m_callstackInfoWindow = it->callstack.Val(); - } - } - } - else - { - DrawZigZag( draw, wpos + ImVec2( 0, ty0375 ), px0, std::max( px1, px0+MinVis ), ty01, 0xFF997777 ); - if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, y0 ), wpos + ImVec2( std::max( px1, px0+MinVis ), y1 ) ) ) - { - ImGui::BeginTooltip(); - ImGui::TextUnformatted( "Multiple call stack samples" ); - TextFocused( "Number of samples:", RealToString( num ) ); - ImGui::EndTooltip(); - - if( IsMouseClicked( 2 ) ) - { - const auto prev = next-1; - ZoomToRange( it->time.Val(), prev->time.Val() + 1 ); - } - } - } - it = next; - } -} - #ifndef TRACY_NO_STATISTICS int View::DispatchGhostLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid ) { diff --git a/server/TracyView_Samples.cpp b/server/TracyView_Samples.cpp index 4c96000a..8a56284f 100644 --- a/server/TracyView_Samples.cpp +++ b/server/TracyView_Samples.cpp @@ -1,6 +1,7 @@ #include #include "TracyFilesystem.hpp" +#include "TracyMouse.hpp" #include "TracyPrint.hpp" #include "TracySourceView.hpp" #include "TracyView.hpp" @@ -8,6 +9,88 @@ namespace tracy { +void View::DrawSamples( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ) +{ + auto it = std::lower_bound( vec.begin(), vec.end(), m_vd.zvStart, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); + if( it == vec.end() ) return; + const auto itend = std::lower_bound( it, vec.end(), m_vd.zvEnd, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); + if( it == itend ) return; + + const auto ty0375 = offset + round( ImGui::GetTextLineHeight() * 0.375f ); + const auto ty02 = round( ImGui::GetTextLineHeight() * 0.2f ); + const auto ty01 = round( ImGui::GetTextLineHeight() * 0.1f ); + const auto y0 = ty0375 - ty02 - 3; + const auto y1 = ty0375 + ty02 - 1; + auto draw = ImGui::GetWindowDrawList(); + + const auto MinVis = 6 * GetScale(); + bool tooltipDisplayed = false; + + while( it < itend ) + { + bool visible = true; + const auto px0 = ( it->time.Val() - m_vd.zvStart ) * pxns; + double px1; + auto next = it+1; + int num; + if( next != itend ) + { + auto px1ns = next->time.Val() - m_vd.zvStart; + px1 = px1ns * pxns; + if( px1 - px0 < MinVis ) + { + const auto MinVisNs = MinVis * nspx; + visible = false; + auto nextTime = px0 + MinVisNs; + for(;;) + { + const auto prev = next; + next = std::lower_bound( next, itend, nextTime, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); + if( prev == next ) ++next; + if( next == itend ) break; + const auto nsnext = next->time.Val() - m_vd.zvStart; + if( nsnext - px1ns >= MinVisNs ) break; + px1ns = nsnext; + nextTime = next->time.Val() + nspx; + } + num = next - it; + px1 = px1ns * pxns; + } + } + if( visible ) + { + draw->AddCircleFilled( wpos + ImVec2( px0, ty0375 ), ty02, 0xFFDD8888 ); + if( !tooltipDisplayed && hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0 - ty02 - 2, y0 ), wpos + ImVec2( px0 + ty02 + 1, y1 ) ) ) + { + tooltipDisplayed = true; + CallstackTooltip( it->callstack.Val() ); + if( IsMouseClicked( 0 ) ) + { + m_callstackInfoWindow = it->callstack.Val(); + } + } + } + else + { + DrawZigZag( draw, wpos + ImVec2( 0, ty0375 ), px0, std::max( px1, px0+MinVis ), ty01, 0xFF997777 ); + if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, y0 ), wpos + ImVec2( std::max( px1, px0+MinVis ), y1 ) ) ) + { + ImGui::BeginTooltip(); + ImGui::TextUnformatted( "Multiple call stack samples" ); + TextFocused( "Number of samples:", RealToString( num ) ); + ImGui::EndTooltip(); + + if( IsMouseClicked( 2 ) ) + { + const auto prev = next-1; + ZoomToRange( it->time.Val(), prev->time.Val() + 1 ); + } + } + } + it = next; + } +} + void View::DrawSamplesStatistics( Vector& data, int64_t timeRange, AccumulationMode accumulationMode ) { static unordered_flat_map inlineMap;