diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index 7391d246..4af48732 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -332,7 +332,7 @@ private: void DrawFindZone(); void AccumulationModeComboBox(); void DrawStatistics(); - void DrawSamplesStatistics(Vector& data, int64_t timeRange, AccumulationMode accumulationMode); + void DrawSamplesStatistics(Vector& data, int64_t timeRange, uint64_t totalSamples, AccumulationMode accumulationMode); void DrawMemory(); void DrawAllocList(); void DrawCompare(); diff --git a/profiler/src/profiler/TracyView_FindZone.cpp b/profiler/src/profiler/TracyView_FindZone.cpp index 181522d0..d6aefdad 100644 --- a/profiler/src/profiler/TracyView_FindZone.cpp +++ b/profiler/src/profiler/TracyView_FindZone.cpp @@ -2136,9 +2136,14 @@ void View::DrawFindZone() Vector data; data.reserve( m_findZone.samples.counts.size() ); - for( auto it: m_findZone.samples.counts ) data.push_back_no_space_check( it ); + uint64_t totalSamples = 0; + for( auto it: m_findZone.samples.counts ) + { + data.push_back_no_space_check( it ); + totalSamples += it.excl; + } int64_t timeRange = ( m_findZone.selGroup != m_findZone.Unselected ) ? m_findZone.selTotal : m_findZone.total; - DrawSamplesStatistics( data, timeRange, AccumulationMode::SelfOnly ); + DrawSamplesStatistics( data, timeRange, totalSamples, AccumulationMode::SelfOnly ); ImGui::TreePop(); } diff --git a/profiler/src/profiler/TracyView_Samples.cpp b/profiler/src/profiler/TracyView_Samples.cpp index eb18c2ed..a61bd9cd 100644 --- a/profiler/src/profiler/TracyView_Samples.cpp +++ b/profiler/src/profiler/TracyView_Samples.cpp @@ -85,7 +85,7 @@ void View::DrawSampleList( const TimelineContext& ctx, const std::vector& data, int64_t timeRange, AccumulationMode accumulationMode ) +void View::DrawSamplesStatistics( Vector& data, int64_t timeRange, uint64_t totalSamples, AccumulationMode accumulationMode ) { static unordered_flat_map inlineMap; assert( inlineMap.empty() ); @@ -156,32 +156,6 @@ void View::DrawSamplesStatistics( Vector& data, int64_t timeRange, Accu ImGui::TableSetupColumn( "Code size", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize ); ImGui::TableHeadersRow(); - // The denominator is the number of collected samples, excluding context - // switch samples, which do not participate in the sampling statistics. This - // way the percentages have the same meaning with and without an active - // range filter. - uint64_t totalSamples; - if( m_statRange.active ) - { - static const auto CountInRange = []( const auto& vec, int64_t min, int64_t max ) -> uint64_t { - auto it = std::lower_bound( vec.begin(), vec.end(), min, []( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } ); - auto end = std::lower_bound( it, vec.end(), max, []( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } ); - return end - it; - }; - totalSamples = 0; - for( auto& td : m_worker.GetThreadData() ) - { - const auto cnt = CountInRange( td->samples, m_statRange.min, m_statRange.max ); - const auto ctx = CountInRange( td->ctxSwitchSamples, m_statRange.min, m_statRange.max ); - if( cnt > ctx ) totalSamples += cnt - ctx; - } - } - else - { - const auto cnt = m_worker.GetCallstackSampleCount(); - const auto ctx = m_worker.GetContextSwitchSampleCount(); - totalSamples = cnt > ctx ? cnt - ctx : 0; - } const double revSampleCount100 = totalSamples == 0 ? 0 : 100. / totalSamples; const bool showAll = m_showAllSymbols; diff --git a/profiler/src/profiler/TracyView_Statistics.cpp b/profiler/src/profiler/TracyView_Statistics.cpp index 8540b791..93195452 100644 --- a/profiler/src/profiler/TracyView_Statistics.cpp +++ b/profiler/src/profiler/TracyView_Statistics.cpp @@ -1000,7 +1000,33 @@ void View::DrawStatistics() } } - DrawSamplesStatistics( data, timeRange, m_statAccumulationMode ); + // The denominator is the number of collected samples, excluding context + // switch samples, which do not participate in the sampling statistics. This + // way the percentages have the same meaning with and without an active + // range filter. + uint64_t totalSamples; + if( m_statRange.active ) + { + static const auto CountInRange = []( const auto& vec, int64_t min, int64_t max ) -> uint64_t { + auto it = std::lower_bound( vec.begin(), vec.end(), min, []( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } ); + auto end = std::lower_bound( it, vec.end(), max, []( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } ); + return end - it; + }; + totalSamples = 0; + for( auto& td : m_worker.GetThreadData() ) + { + const auto cnt = CountInRange( td->samples, m_statRange.min, m_statRange.max ); + const auto ctx = CountInRange( td->ctxSwitchSamples, m_statRange.min, m_statRange.max ); + if( cnt > ctx ) totalSamples += cnt - ctx; + } + } + else + { + const auto cnt = m_worker.GetCallstackSampleCount(); + const auto ctx = m_worker.GetContextSwitchSampleCount(); + totalSamples = cnt > ctx ? cnt - ctx : 0; + } + DrawSamplesStatistics( data, timeRange, totalSamples, m_statAccumulationMode ); } ImGui::End(); }