Merge pull request #257 from xxxbxxx/filter-by-srcloc

Filter samples by zones source locations
This commit is contained in:
Bartosz Taudul 2021-09-23 22:12:42 +02:00 committed by GitHub
commit b6eee83463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 581 additions and 393 deletions

View File

@ -268,6 +268,7 @@ enum { SampleDataSize = sizeof( SampleData ) };
struct SampleDataRange struct SampleDataRange
{ {
Int48 time; Int48 time;
uint16_t thread;
CallstackFrameId ip; CallstackFrameId ip;
}; };

View File

@ -10698,6 +10698,7 @@ void View::DrawFindZone()
ImGui::Separator(); ImGui::Separator();
SmallCheckbox( "Show zone time in frames", &m_findZone.showZoneInFrames ); SmallCheckbox( "Show zone time in frames", &m_findZone.showZoneInFrames );
ImGui::Separator(); ImGui::Separator();
ImGui::TextUnformatted( "Found zones:" ); ImGui::TextUnformatted( "Found zones:" );
ImGui::SameLine(); ImGui::SameLine();
DrawHelpMarker( "Left click to highlight entry." ); DrawHelpMarker( "Left click to highlight entry." );
@ -10752,7 +10753,8 @@ void View::DrawFindZone()
const auto highlightActive = m_findZone.highlight.active; const auto highlightActive = m_findZone.highlight.active;
const auto limitRange = m_findZone.range.active; const auto limitRange = m_findZone.range.active;
FindZone::Group* group = nullptr; FindZone::Group* group = nullptr;
uint64_t lastGid = std::numeric_limits<uint64_t>::max() - 1; const uint64_t invalidGid = std::numeric_limits<uint64_t>::max() - 1;
uint64_t lastGid = invalidGid;
auto zptr = zones.data() + m_findZone.processed; auto zptr = zones.data() + m_findZone.processed;
const auto zend = zones.data() + zones.size(); const auto zend = zones.data() + zones.size();
while( zptr < zend ) while( zptr < zend )
@ -10848,14 +10850,25 @@ void View::DrawFindZone()
{ {
it = m_findZone.groups.emplace( gid, FindZone::Group { m_findZone.groupId++ } ).first; it = m_findZone.groups.emplace( gid, FindZone::Group { m_findZone.groupId++ } ).first;
it->second.zones.reserve( 1024 ); it->second.zones.reserve( 1024 );
if( m_findZone.samples.enabled )
it->second.zonesTids.reserve( 1024 );
} }
group = &it->second; group = &it->second;
} }
group->time += timespan; group->time += timespan;
group->zones.push_back_non_empty( ev.Zone() ); group->zones.push_back_non_empty( ev.Zone() );
if( m_findZone.samples.enabled )
group->zonesTids.push_back_non_empty( ev.Thread() );
} }
m_findZone.processed = zptr - zones.data(); m_findZone.processed = zptr - zones.data();
const bool groupsUpdated = lastGid != invalidGid;
if( m_findZone.samples.enabled && groupsUpdated )
{
m_findZone.samples.scheduleUpdate = true;
}
Vector<decltype( m_findZone.groups )::iterator> groups; Vector<decltype( m_findZone.groups )::iterator> groups;
groups.reserve_and_use( m_findZone.groups.size() ); groups.reserve_and_use( m_findZone.groups.size() );
int idx = 0; int idx = 0;
@ -11070,6 +11083,159 @@ void View::DrawFindZone()
} }
} }
} }
if( m_findZone.samples.enabled && m_findZone.samples.scheduleUpdate && !m_findZone.scheduleResetMatch )
{
m_findZone.samples.scheduleUpdate = false;
const auto& symMap = m_worker.GetSymbolMap();
m_findZone.samples.counts.clear();
m_findZone.samples.counts.reserve( symMap.size() );
struct GroupRange {
const FindZone::Group* group;
Vector<short_ptr<ZoneEvent>>::const_iterator begin;
Vector<short_ptr<ZoneEvent>>::const_iterator end;
};
Vector<GroupRange> selectedGroups;
selectedGroups.reserve( m_findZone.groups.size() );
for( auto it = m_findZone.groups.begin(); it != m_findZone.groups.end(); ++it )
{
assert( it->second.zones.size() == it->second.zonesTids.size() );
if( ( m_findZone.selGroup == m_findZone.Unselected || it->first == m_findZone.selGroup )
&& !it->second.zones.empty() )
{
selectedGroups.push_back_no_space_check( GroupRange{&it->second} );
}
}
for( auto& v : symMap )
{
bool pass = ( m_statShowKernel || ( v.first >> 63 ) == 0 );
if( !pass && v.second.size.Val() == 0 )
{
const auto parentAddr = m_worker.GetSymbolForAddress( v.first );
if( parentAddr != 0 )
{
auto pit = symMap.find( parentAddr );
if( pit != symMap.end() )
{
pass = ( m_statShowKernel || ( parentAddr >> 63 ) == 0 );
}
}
}
if( !pass ) continue;
auto samples = m_worker.GetSamplesForSymbol( v.first );
if( !samples ) continue;
auto samplesBegin = samples->begin();
auto samplesEnd = samples->end();
if( m_findZone.range.active )
{
const auto rangeMin = m_findZone.range.min;
const auto rangeMax = m_findZone.range.max;
samplesBegin = std::lower_bound( samplesBegin, samplesEnd, rangeMin, [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } );
samplesEnd = std::lower_bound( samplesBegin, samplesEnd, rangeMax, [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } );
}
if( samplesBegin == samplesEnd ) continue;
bool empty = true;
const auto firstTime = samplesBegin->time.Val();
const auto lastTime = samplesEnd->time.Val();
for( auto& g: selectedGroups )
{
const auto& zones = g.group->zones;
auto begin = std::lower_bound( zones.begin(), zones.end(), firstTime, [] ( const auto& l, const auto& r ) { return l->Start() < r; } );
auto end = std::upper_bound( begin, zones.end(), lastTime, [] ( const auto& l, const auto& r ) { return l <= r->Start(); } );
g.begin = begin;
g.end = end;
empty = empty && (begin == end);
}
if (empty) continue;
uint32_t count = 0;
for( auto it = samplesBegin; it != samplesEnd; ++it )
{
const auto time = it->time.Val();
bool pass = false;
for( auto& g: selectedGroups )
{
while( g.begin != g.end && time > (*g.begin)->End() ) ++g.begin;
if( g.begin == g.end ) continue;
if( time < (*g.begin)->Start() ) continue;
const auto& tids = g.group->zonesTids;
const auto firstZone = g.group->zones.begin();
for (auto z = g.begin; z != g.end && (*z)->Start() <= time; ++z)
{
auto zoneIndex = z - firstZone;
if( (*z)->End() > time && it->thread == tids[zoneIndex] )
{
pass = true;
break;
}
}
}
if( pass ) count ++;
}
if( count > 0 ) m_findZone.samples.counts.push_back_no_space_check( SymList { v.first, 0, count } );
}
}
ImGui::Separator();
const bool hasSamples = m_worker.AreCallstackSamplesReady() && m_worker.GetCallstackSampleCount() > 0;
if( hasSamples && ImGui::TreeNodeEx( "Samples", ImGuiTreeNodeFlags_None ) )
{
{
ImGui::Checkbox( ICON_FA_STOPWATCH " Show time", &m_statSampleTime );
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
ImGui::Checkbox( ICON_FA_EYE_SLASH " Hide unknown", &m_statHideUnknown );
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
ImGui::Checkbox( ICON_FA_SITEMAP " Inlines", &m_statSeparateInlines );
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
ImGui::Checkbox( ICON_FA_AT " Address", &m_statShowAddress );
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
if( ImGui::Checkbox( ICON_FA_HAT_WIZARD " Include kernel", &m_statShowKernel ))
{
m_findZone.samples.scheduleUpdate = true;
}
}
if( !m_findZone.samples.enabled )
{
m_findZone.samples.enabled = true;
m_findZone.samples.scheduleUpdate = true;
m_findZone.scheduleResetMatch = true;
}
Vector<SymList> data;
data.reserve( m_findZone.samples.counts.size() );
for( auto it: m_findZone.samples.counts ) data.push_back_no_space_check( it );
int64_t timeRange = ( m_findZone.selGroup != m_findZone.Unselected ) ? m_findZone.selTotal : m_findZone.total;
DrawSamplesStatistics( data, timeRange, AccumulationMode::SelfOnly );
ImGui::TreePop();
}
else
{
if( m_findZone.samples.enabled )
{
m_findZone.samples.enabled = false;
m_findZone.samples.scheduleUpdate = false;
m_findZone.samples.counts = Vector<SymList>();
for( auto& it: m_findZone.groups ) it.second.zonesTids.clear();
}
}
ImGui::EndChild(); ImGui::EndChild();
} }
#endif #endif
@ -12810,13 +12976,6 @@ void View::DrawStatistics()
const auto& symMap = m_worker.GetSymbolMap(); const auto& symMap = m_worker.GetSymbolMap();
const auto& symStat = m_worker.GetSymbolStats(); const auto& symStat = m_worker.GetSymbolStats();
struct SymList
{
uint64_t symAddr;
uint32_t incl, excl;
uint32_t count;
};
Vector<SymList> data; Vector<SymList> data;
if( m_showAllSymbols ) if( m_showAllSymbols )
{ {
@ -13000,6 +13159,15 @@ void View::DrawStatistics()
} }
} }
DrawSamplesStatistics(data, timeRange, m_statAccumulationMode);
}
#endif
ImGui::End();
}
void View::DrawSamplesStatistics(Vector<SymList>& data, int64_t timeRange, AccumulationMode accumulationMode)
{
static unordered_flat_map<uint64_t, SymList> inlineMap; static unordered_flat_map<uint64_t, SymList> inlineMap;
assert( inlineMap.empty() ); assert( inlineMap.empty() );
if( !m_statSeparateInlines ) if( !m_statSeparateInlines )
@ -13038,7 +13206,9 @@ void View::DrawStatistics()
} }
else else
{ {
if( m_statAccumulationMode == AccumulationMode::SelfOnly ) const auto& symMap = m_worker.GetSymbolMap();
if( accumulationMode == AccumulationMode::SelfOnly )
{ {
pdqsort_branchless( data.begin(), data.end(), []( const auto& l, const auto& r ) { return l.excl != r.excl ? l.excl > r.excl : l.symAddr < r.symAddr; } ); pdqsort_branchless( data.begin(), data.end(), []( const auto& l, const auto& r ) { return l.excl != r.excl ? l.excl > r.excl : l.symAddr < r.symAddr; } );
} }
@ -13075,7 +13245,7 @@ void View::DrawStatistics()
int idx = 0; int idx = 0;
for( auto& v : data ) for( auto& v : data )
{ {
const auto cnt = m_statAccumulationMode == AccumulationMode::SelfOnly ? v.excl : v.incl; const auto cnt = accumulationMode == AccumulationMode::SelfOnly ? v.excl : v.incl;
if( cnt > 0 || showAll ) if( cnt > 0 || showAll )
{ {
const char* name = "[unknown]"; const char* name = "[unknown]";
@ -13314,7 +13484,7 @@ void View::DrawStatistics()
inSymList.push_back( SymList { v.symAddr, statIt->second.incl, statIt->second.excl } ); inSymList.push_back( SymList { v.symAddr, statIt->second.incl, statIt->second.excl } );
} }
if( m_statAccumulationMode == AccumulationMode::SelfOnly ) if( accumulationMode == AccumulationMode::SelfOnly )
{ {
pdqsort_branchless( inSymList.begin(), inSymList.end(), []( const auto& l, const auto& r ) { return l.excl != r.excl ? l.excl > r.excl : l.symAddr < r.symAddr; } ); pdqsort_branchless( inSymList.begin(), inSymList.end(), []( const auto& l, const auto& r ) { return l.excl != r.excl ? l.excl > r.excl : l.symAddr < r.symAddr; } );
} }
@ -13328,7 +13498,7 @@ void View::DrawStatistics()
{ {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
const auto cnt = m_statAccumulationMode == AccumulationMode::SelfOnly ? iv.excl : iv.incl; const auto cnt = accumulationMode == AccumulationMode::SelfOnly ? iv.excl : iv.incl;
if( cnt > 0 || showAll ) if( cnt > 0 || showAll )
{ {
auto sit = symMap.find( iv.symAddr ); auto sit = symMap.find( iv.symAddr );
@ -13456,9 +13626,6 @@ void View::DrawStatistics()
inlineMap.clear(); inlineMap.clear();
} }
}
#endif
ImGui::End();
} }
void View::DrawCallstackWindow() void View::DrawCallstackWindow()

View File

@ -153,6 +153,13 @@ private:
bool highlight; bool highlight;
}; };
struct SymList
{
uint64_t symAddr;
uint32_t incl, excl;
uint32_t count;
};
void InitMemory(); void InitMemory();
void InitTextEditor( ImFont* font ); void InitTextEditor( ImFont* font );
@ -196,6 +203,7 @@ private:
void DrawFindZone(); void DrawFindZone();
void AccumulationModeComboBox(); void AccumulationModeComboBox();
void DrawStatistics(); void DrawStatistics();
void DrawSamplesStatistics(Vector<SymList>& data, int64_t timeRange, AccumulationMode accumulationMode);
void DrawMemory(); void DrawMemory();
void DrawAllocList(); void DrawAllocList();
void DrawCompare(); void DrawCompare();
@ -508,6 +516,7 @@ private:
{ {
uint16_t id; uint16_t id;
Vector<short_ptr<ZoneEvent>> zones; Vector<short_ptr<ZoneEvent>> zones;
Vector<uint16_t> zonesTids;
int64_t time = 0; int64_t time = 0;
}; };
@ -554,6 +563,12 @@ private:
ptrdiff_t distEnd; ptrdiff_t distEnd;
} binCache; } binCache;
struct {
Vector<SymList> counts;
bool scheduleUpdate = false;
bool enabled = false;
} samples;
void Reset() void Reset()
{ {
ResetMatch(); ResetMatch();
@ -561,6 +576,7 @@ private:
selMatch = 0; selMatch = 0;
selGroup = Unselected; selGroup = Unselected;
highlight.active = false; highlight.active = false;
samples.counts.clear();
} }
void ResetMatch() void ResetMatch()
@ -595,6 +611,7 @@ private:
selTotal = 0; selTotal = 0;
selTime = 0; selTime = 0;
binCache.numBins = -1; binCache.numBins = -1;
samples.scheduleUpdate = true;
} }
void ShowZone( int16_t srcloc, const char* name ) void ShowZone( int16_t srcloc, const char* name )

View File

@ -1931,6 +1931,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
jobs.emplace_back( std::thread( [this] { jobs.emplace_back( std::thread( [this] {
for( auto& t : m_data.threads ) for( auto& t : m_data.threads )
{ {
uint16_t tid = CompressThread( t->id );
for( auto& v : t->samples ) for( auto& v : t->samples )
{ {
const auto& time = v.time; const auto& time = v.time;
@ -1944,11 +1945,11 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
auto it = m_data.symbolSamples.find( symAddr ); auto it = m_data.symbolSamples.find( symAddr );
if( it == m_data.symbolSamples.end() ) if( it == m_data.symbolSamples.end() )
{ {
m_data.symbolSamples.emplace( symAddr, Vector<SampleDataRange>( SampleDataRange { time, ip } ) ); m_data.symbolSamples.emplace( symAddr, Vector<SampleDataRange>( SampleDataRange { time, tid, ip } ) );
} }
else else
{ {
it->second.push_back_non_empty( SampleDataRange { time, ip } ); it->second.push_back_non_empty( SampleDataRange { time, tid, ip } );
} }
} }
for( uint16_t i=1; i<callstack.size(); i++ ) for( uint16_t i=1; i<callstack.size(); i++ )
@ -5970,6 +5971,8 @@ void Worker::ProcessCallstackSampleImpl( const SampleData& sd, ThreadData& td, i
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
{ {
uint16_t tid = CompressThread( td.id );
auto frame = GetCallstackFrame( ip ); auto frame = GetCallstackFrame( ip );
if( frame ) if( frame )
{ {
@ -5994,18 +5997,18 @@ void Worker::ProcessCallstackSampleImpl( const SampleData& sd, ThreadData& td, i
auto sit = m_data.symbolSamples.find( symAddr ); auto sit = m_data.symbolSamples.find( symAddr );
if( sit == m_data.symbolSamples.end() ) if( sit == m_data.symbolSamples.end() )
{ {
m_data.symbolSamples.emplace( symAddr, Vector<SampleDataRange>( SampleDataRange { sd.time, ip } ) ); m_data.symbolSamples.emplace( symAddr, Vector<SampleDataRange>( SampleDataRange { sd.time, tid, ip } ) );
} }
else else
{ {
if( sit->second.back().time.Val() <= sd.time.Val() ) if( sit->second.back().time.Val() <= sd.time.Val() )
{ {
sit->second.push_back_non_empty( SampleDataRange { sd.time, ip } ); sit->second.push_back_non_empty( SampleDataRange { sd.time, tid, ip } );
} }
else else
{ {
auto iit = std::upper_bound( sit->second.begin(), sit->second.end(), sd.time.Val(), [] ( const auto& lhs, const auto& rhs ) { return lhs < rhs.time.Val(); } ); auto iit = std::upper_bound( sit->second.begin(), sit->second.end(), sd.time.Val(), [] ( const auto& lhs, const auto& rhs ) { return lhs < rhs.time.Val(); } );
sit->second.insert( iit, SampleDataRange { sd.time, ip } ); sit->second.insert( iit, SampleDataRange { sd.time, tid, ip } );
} }
} }
} }
@ -6023,11 +6026,11 @@ void Worker::ProcessCallstackSampleImpl( const SampleData& sd, ThreadData& td, i
auto sit = m_data.pendingSymbolSamples.find( ip ); auto sit = m_data.pendingSymbolSamples.find( ip );
if( sit == m_data.pendingSymbolSamples.end() ) if( sit == m_data.pendingSymbolSamples.end() )
{ {
m_data.pendingSymbolSamples.emplace( ip, Vector<SampleDataRange>( SampleDataRange { sd.time, ip } ) ); m_data.pendingSymbolSamples.emplace( ip, Vector<SampleDataRange>( SampleDataRange { sd.time, tid, ip } ) );
} }
else else
{ {
sit->second.push_back_non_empty( SampleDataRange { sd.time, ip } ); sit->second.push_back_non_empty( SampleDataRange { sd.time, tid, ip } );
} }
} }
} }