mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Use the same algorithm for selection group binning.
This commit is contained in:
parent
c1630936d4
commit
5733b420a1
@ -4628,6 +4628,34 @@ void View::DrawFindZone()
|
|||||||
m_findZone.sortedNum = i;
|
m_findZone.sortedNum = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_findZone.selGroup != m_findZone.Unselected )
|
||||||
|
{
|
||||||
|
if( m_findZone.selSortNum != m_findZone.sortedNum )
|
||||||
|
{
|
||||||
|
const auto selGroup = m_findZone.selGroup;
|
||||||
|
const auto groupBy = m_findZone.groupBy;
|
||||||
|
|
||||||
|
auto& vec = m_findZone.selSort;
|
||||||
|
vec.reserve( zsz );
|
||||||
|
auto act = m_findZone.selSortActive;
|
||||||
|
size_t i;
|
||||||
|
for( i=m_findZone.selSortNum; i<m_findZone.sortedNum; i++ )
|
||||||
|
{
|
||||||
|
auto& ev = zones[i];
|
||||||
|
if( selGroup == GetSelectionTarget( ev, groupBy ) )
|
||||||
|
{
|
||||||
|
vec.emplace_back( ev.zone->end - ev.zone->start );
|
||||||
|
act++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto mid = vec.begin() + m_findZone.selSortActive;
|
||||||
|
pdqsort_branchless( mid, vec.end() );
|
||||||
|
std::inplace_merge( vec.begin(), mid, vec.end() );
|
||||||
|
m_findZone.selSortNum = m_findZone.sortedNum;
|
||||||
|
m_findZone.selSortActive = act;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( tmin != std::numeric_limits<int64_t>::max() )
|
if( tmin != std::numeric_limits<int64_t>::max() )
|
||||||
{
|
{
|
||||||
ImGui::Checkbox( "Log values", &m_findZone.logVal );
|
ImGui::Checkbox( "Log values", &m_findZone.logVal );
|
||||||
@ -4649,8 +4677,6 @@ void View::DrawFindZone()
|
|||||||
ImGui::Text( "%s - %s (%s)", TimeToString( tmin ), TimeToString( tmax ), TimeToString( tmax - tmin ) );
|
ImGui::Text( "%s - %s (%s)", TimeToString( tmin ), TimeToString( tmax ), TimeToString( tmax - tmin ) );
|
||||||
|
|
||||||
const auto dt = double( tmax - tmin );
|
const auto dt = double( tmax - tmin );
|
||||||
const auto selGroup = m_findZone.selGroup;
|
|
||||||
const auto groupBy = m_findZone.groupBy;
|
|
||||||
const auto cumulateTime = m_findZone.cumulateTime;
|
const auto cumulateTime = m_findZone.cumulateTime;
|
||||||
|
|
||||||
if( dt > 0 )
|
if( dt > 0 )
|
||||||
@ -4686,42 +4712,47 @@ void View::DrawFindZone()
|
|||||||
{
|
{
|
||||||
const auto tMinLog = log10( tmin );
|
const auto tMinLog = log10( tmin );
|
||||||
const auto zmax = ( log10( tmax ) - tMinLog ) / numBins;
|
const auto zmax = ( log10( tmax ) - tMinLog ) / numBins;
|
||||||
auto zit = sorted.begin();
|
|
||||||
while( zit != sorted.end() && *zit == 0 ) zit++;
|
|
||||||
for( int64_t i=0; i<numBins; i++ )
|
|
||||||
{
|
{
|
||||||
const auto nextBinVal = int64_t( pow( 10.0, tMinLog + ( i+1 ) * zmax ) );
|
auto zit = sorted.begin();
|
||||||
auto nit = std::lower_bound( zit, sorted.end(), nextBinVal );
|
while( zit != sorted.end() && *zit == 0 ) zit++;
|
||||||
const auto distance = std::distance( zit, nit );
|
for( int64_t i=0; i<numBins; i++ )
|
||||||
const auto timeSum = std::accumulate( zit, nit, int64_t( 0 ) );
|
|
||||||
bins[i] = distance;
|
|
||||||
binTime[i] = timeSum;
|
|
||||||
if( m_findZone.highlight.active )
|
|
||||||
{
|
{
|
||||||
auto end = nit == zit ? zit : nit-1;
|
const auto nextBinVal = int64_t( pow( 10.0, tMinLog + ( i+1 ) * zmax ) );
|
||||||
if( *zit >= s && *end <= e ) selectionTime += timeSum;
|
auto nit = std::lower_bound( zit, sorted.end(), nextBinVal );
|
||||||
}
|
const auto distance = std::distance( zit, nit );
|
||||||
zit = nit;
|
const auto timeSum = std::accumulate( zit, nit, int64_t( 0 ) );
|
||||||
}
|
bins[i] = distance;
|
||||||
const auto timeSum = std::accumulate( zit, sorted.end(), int64_t( 0 ) );
|
binTime[i] = timeSum;
|
||||||
bins[numBins-1] += std::distance( zit, sorted.end() );
|
if( m_findZone.highlight.active )
|
||||||
binTime[numBins-1] += timeSum;
|
|
||||||
if( m_findZone.highlight.active && *zit >= s && *(sorted.end()-1) <= e ) selectionTime += timeSum;
|
|
||||||
|
|
||||||
if( selGroup != m_findZone.Unselected )
|
|
||||||
{
|
|
||||||
const auto idt = numBins / ( log10( tmax ) - tMinLog );
|
|
||||||
for( auto& ev : zones )
|
|
||||||
{
|
|
||||||
if( selGroup == GetSelectionTarget( ev, groupBy ) )
|
|
||||||
{
|
{
|
||||||
const auto timeSpan = m_worker.GetZoneEndDirect( *ev.zone ) - ev.zone->start;
|
auto end = nit == zit ? zit : nit-1;
|
||||||
if( timeSpan != 0 )
|
if( *zit >= s && *end <= e ) selectionTime += timeSum;
|
||||||
{
|
|
||||||
const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) );
|
|
||||||
if( cumulateTime ) selBin[bin] += timeSpan; else selBin[bin]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
zit = nit;
|
||||||
|
}
|
||||||
|
const auto timeSum = std::accumulate( zit, sorted.end(), int64_t( 0 ) );
|
||||||
|
bins[numBins-1] += std::distance( zit, sorted.end() );
|
||||||
|
binTime[numBins-1] += timeSum;
|
||||||
|
if( m_findZone.highlight.active && *zit >= s && *(sorted.end()-1) <= e ) selectionTime += timeSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m_findZone.selGroup != m_findZone.Unselected )
|
||||||
|
{
|
||||||
|
auto zit = m_findZone.selSort.begin();
|
||||||
|
while( zit != m_findZone.selSort.end() && *zit == 0 ) zit++;
|
||||||
|
for( int64_t i=0; i<numBins; i++ )
|
||||||
|
{
|
||||||
|
const auto nextBinVal = int64_t( pow( 10.0, tMinLog + ( i+1 ) * zmax ) );
|
||||||
|
auto nit = std::lower_bound( zit, m_findZone.selSort.end(), nextBinVal );
|
||||||
|
if( cumulateTime )
|
||||||
|
{
|
||||||
|
selBin[i] = std::accumulate( zit, nit, int64_t( 0 ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selBin[i] = std::distance( zit, nit );
|
||||||
|
}
|
||||||
|
zit = nit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4750,20 +4781,23 @@ void View::DrawFindZone()
|
|||||||
binTime[numBins-1] += timeSum;
|
binTime[numBins-1] += timeSum;
|
||||||
if( m_findZone.highlight.active && *zit >= s && *(sorted.end()-1) <= e ) selectionTime += timeSum;
|
if( m_findZone.highlight.active && *zit >= s && *(sorted.end()-1) <= e ) selectionTime += timeSum;
|
||||||
|
|
||||||
if( selGroup != m_findZone.Unselected )
|
if( m_findZone.selGroup != m_findZone.Unselected )
|
||||||
{
|
{
|
||||||
const auto idt = numBins / dt;
|
auto zit = m_findZone.selSort.begin();
|
||||||
for( auto& ev : zones )
|
while( zit != m_findZone.selSort.end() && *zit == 0 ) zit++;
|
||||||
|
for( int64_t i=0; i<numBins; i++ )
|
||||||
{
|
{
|
||||||
if( selGroup == GetSelectionTarget( ev, groupBy ) )
|
const auto nextBinVal = ( i+1 ) * zmax / numBins;
|
||||||
|
auto nit = std::lower_bound( zit, m_findZone.selSort.end(), nextBinVal );
|
||||||
|
if( cumulateTime )
|
||||||
{
|
{
|
||||||
const auto timeSpan = m_worker.GetZoneEndDirect( *ev.zone ) - ev.zone->start;
|
selBin[i] = std::accumulate( zit, nit, int64_t( 0 ) );
|
||||||
if( timeSpan != 0 )
|
|
||||||
{
|
|
||||||
const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) );
|
|
||||||
if( cumulateTime ) selBin[bin] += timeSpan; else selBin[bin]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selBin[i] = std::distance( zit, nit );
|
||||||
|
}
|
||||||
|
zit = nit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4825,9 +4859,9 @@ void View::DrawFindZone()
|
|||||||
{
|
{
|
||||||
TextFocused( "Selection time:", "none" );
|
TextFocused( "Selection time:", "none" );
|
||||||
}
|
}
|
||||||
if( selGroup != m_findZone.Unselected )
|
if( m_findZone.selGroup != m_findZone.Unselected )
|
||||||
{
|
{
|
||||||
TextFocused( "Zone group time:", TimeToString( m_findZone.groups[selGroup].time ) );
|
TextFocused( "Zone group time:", TimeToString( m_findZone.groups[m_findZone.selGroup].time ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -5257,6 +5291,7 @@ void View::DrawFindZone()
|
|||||||
if( ImGui::IsItemClicked() )
|
if( ImGui::IsItemClicked() )
|
||||||
{
|
{
|
||||||
m_findZone.selGroup = v->first;
|
m_findZone.selGroup = v->first;
|
||||||
|
m_findZone.ResetSelection();
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@ -5327,6 +5362,7 @@ void View::DrawFindZone()
|
|||||||
if( ImGui::IsItemHovered() && ImGui::IsMouseClicked( 1 ) )
|
if( ImGui::IsItemHovered() && ImGui::IsMouseClicked( 1 ) )
|
||||||
{
|
{
|
||||||
m_findZone.selGroup = m_findZone.Unselected;
|
m_findZone.selGroup = m_findZone.Unselected;
|
||||||
|
m_findZone.ResetSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -292,8 +292,8 @@ private:
|
|||||||
int64_t hlOrig_t0, hlOrig_t1;
|
int64_t hlOrig_t0, hlOrig_t1;
|
||||||
int64_t numBins = -1;
|
int64_t numBins = -1;
|
||||||
std::unique_ptr<int64_t[]> bins, binTime, selBin;
|
std::unique_ptr<int64_t[]> bins, binTime, selBin;
|
||||||
std::vector<int64_t> sorted;
|
std::vector<int64_t> sorted, selSort;
|
||||||
size_t sortedNum;
|
size_t sortedNum, selSortNum, selSortActive;
|
||||||
float average;
|
float average;
|
||||||
float median;
|
float median;
|
||||||
int64_t total;
|
int64_t total;
|
||||||
@ -314,10 +314,18 @@ private:
|
|||||||
|
|
||||||
void ResetGroups()
|
void ResetGroups()
|
||||||
{
|
{
|
||||||
|
ResetSelection();
|
||||||
groups.clear();
|
groups.clear();
|
||||||
processed = 0;
|
processed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResetSelection()
|
||||||
|
{
|
||||||
|
selSort.clear();
|
||||||
|
selSortNum = 0;
|
||||||
|
selSortActive = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ShowZone( int32_t srcloc, const char* name )
|
void ShowZone( int32_t srcloc, const char* name )
|
||||||
{
|
{
|
||||||
show = true;
|
show = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user