Live updates of find zone data.

TODO: found zones list. Currently only histogram view is available.
This commit is contained in:
Bartosz Taudul 2018-03-18 02:43:17 +01:00
parent c807b3f7ef
commit 746df21ad9
2 changed files with 351 additions and 382 deletions

View File

@ -2714,17 +2714,6 @@ void View::DrawFindZone()
m_findZone.Reset(); m_findZone.Reset();
} }
if( ImGui::TreeNode( "Options" ) )
{
ImGui::InputInt( "max zones per thread", &m_findZone.maxZonesPerThread );
ImGui::SameLine();
DrawHelpMarker( "-1 for unlimited.\nHigh value or unlimited zone search may lead to performance issues." );
ImGui::InputInt( "max depth", &m_findZone.maxDepth );
ImGui::SameLine();
DrawHelpMarker( "-1 for unlimited." );
ImGui::TreePop();
}
if( findClicked ) if( findClicked )
{ {
m_findZone.Reset(); m_findZone.Reset();
@ -2746,18 +2735,11 @@ void View::DrawFindZone()
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextColored( ImVec4( 0.5, 0.5, 0.5, 1 ), "%s:%i", m_worker.GetString( srcloc.file ), srcloc.line ); ImGui::TextColored( ImVec4( 0.5, 0.5, 0.5, 1 ), "%s:%i", m_worker.GetString( srcloc.file ), srcloc.line );
ImGui::PopID(); ImGui::PopID();
if( v.second != tmp ) if( v.second != tmp ) v.second = tmp;
{
v.second = tmp;
RecalcFindMatches();
}
} }
ImGui::TreePop(); ImGui::TreePop();
} }
}
if( !m_findZone.result.empty() )
{
ImGui::Separator(); ImGui::Separator();
if( ImGui::TreeNode( "Histogram" ) ) if( ImGui::TreeNode( "Histogram" ) )
@ -2767,16 +2749,23 @@ void View::DrawFindZone()
int64_t tmin = std::numeric_limits<int64_t>::max(); int64_t tmin = std::numeric_limits<int64_t>::max();
int64_t tmax = std::numeric_limits<int64_t>::min(); int64_t tmax = std::numeric_limits<int64_t>::min();
for( auto& v : m_findZone.result ) for( auto& v : m_findZone.match )
{ {
for( auto& ev : v->timeline ) if( !v.second ) continue;
auto& zones = m_worker.GetZonesForSourceLocation( v.first );
for( auto& ev : zones )
{ {
const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start; const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start;
if( timeSpan != 0 )
{
tmin = std::min( tmin, timeSpan ); tmin = std::min( tmin, timeSpan );
tmax = std::max( tmax, timeSpan ); tmax = std::max( tmax, timeSpan );
} }
} }
}
if( tmin != std::numeric_limits<int64_t>::max() )
{
ImGui::Checkbox( "Log values", &m_findZone.logVal ); ImGui::Checkbox( "Log values", &m_findZone.logVal );
ImGui::SameLine(); ImGui::SameLine();
ImGui::Checkbox( "Log time", &m_findZone.logTime ); ImGui::Checkbox( "Log time", &m_findZone.logTime );
@ -2818,11 +2807,15 @@ void View::DrawFindZone()
{ {
const auto tMinLog = log10( tmin ); const auto tMinLog = log10( tmin );
const auto idt = numBins / ( log10( tmax ) - tMinLog ); const auto idt = numBins / ( log10( tmax ) - tMinLog );
for( auto& v : m_findZone.result ) for( auto& v : m_findZone.match )
{ {
for( auto& ev : v->timeline ) if( !v.second ) continue;
auto& zones = m_worker.GetZonesForSourceLocation( v.first );
for( auto& ev : zones )
{ {
const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start; const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start;
if( timeSpan != 0 )
{
const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) ); const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) );
bins[bin]++; bins[bin]++;
binTime[bin] += timeSpan; binTime[bin] += timeSpan;
@ -2830,14 +2823,19 @@ void View::DrawFindZone()
} }
} }
} }
}
else else
{ {
const auto idt = numBins / dt; const auto idt = numBins / dt;
for( auto& v : m_findZone.result ) for( auto& v : m_findZone.match )
{ {
for( auto& ev : v->timeline ) if( !v.second ) continue;
auto& zones = m_worker.GetZonesForSourceLocation( v.first );
for( auto& ev : zones )
{ {
const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start; const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start;
if( timeSpan != 0 )
{
const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) );
bins[bin]++; bins[bin]++;
binTime[bin] += timeSpan; binTime[bin] += timeSpan;
@ -2846,31 +2844,41 @@ void View::DrawFindZone()
} }
} }
} }
}
else else
{ {
if( m_findZone.logTime ) if( m_findZone.logTime )
{ {
const auto tMinLog = log10( tmin ); const auto tMinLog = log10( tmin );
const auto idt = numBins / ( log10( tmax ) - tMinLog ); const auto idt = numBins / ( log10( tmax ) - tMinLog );
for( auto& v : m_findZone.result ) for( auto& v : m_findZone.match )
{ {
for( auto& ev : v->timeline ) if( !v.second ) continue;
auto& zones = m_worker.GetZonesForSourceLocation( v.first );
for( auto& ev : zones )
{ {
const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start; const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start;
if( timeSpan != 0 )
{
const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) ); const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) );
bins[bin]++; bins[bin]++;
binTime[bin] += timeSpan; binTime[bin] += timeSpan;
} }
} }
} }
}
else else
{ {
const auto idt = numBins / dt; const auto idt = numBins / dt;
for( auto& v : m_findZone.result ) for( auto& v : m_findZone.match )
{ {
for( auto& ev : v->timeline ) if( !v.second ) continue;
auto& zones = m_worker.GetZonesForSourceLocation( v.first );
for( auto& ev : zones )
{ {
const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start; const auto timeSpan = m_worker.GetZoneEnd( *ev ) - ev->start;
if( timeSpan != 0 )
{
const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) );
bins[bin]++; bins[bin]++;
binTime[bin] += timeSpan; binTime[bin] += timeSpan;
@ -2878,6 +2886,7 @@ void View::DrawFindZone()
} }
} }
} }
}
int64_t timeTotal = binTime[0]; int64_t timeTotal = binTime[0];
int64_t maxVal; int64_t maxVal;
@ -3137,10 +3146,13 @@ void View::DrawFindZone()
} }
} }
} }
}
ImGui::TreePop(); ImGui::TreePop();
} }
// TODO
#if 0
ImGui::Separator(); ImGui::Separator();
ImGui::Text( "Found zones:" ); ImGui::Text( "Found zones:" );
@ -3229,6 +3241,7 @@ void View::DrawFindZone()
m_findZone.counts[i] = cnt; m_findZone.counts[i] = cnt;
} }
} }
#endif
} }
ImGui::End(); ImGui::End();
@ -3474,49 +3487,11 @@ void View::FindZones()
m_findZone.match.reserve( match.size() ); m_findZone.match.reserve( match.size() );
for( auto& v : match ) for( auto& v : match )
{
if( !m_worker.GetZonesForSourceLocation( v ).empty() )
{ {
m_findZone.match.emplace( v, true ); m_findZone.match.emplace( v, true );
} }
RecalcFindMatches();
}
void View::RecalcFindMatches()
{
m_findZone.result.clear();
m_findZone.counts.clear();
for( const auto& v : m_worker.GetThreadData() )
{
auto thrOut = std::make_unique<ThreadData>();
RecalcFindMatches( v->timeline, thrOut->timeline, m_findZone.maxDepth );
if( !thrOut->timeline.empty() )
{
thrOut->id = v->id;
m_findZone.counts.emplace_back( thrOut->timeline.size() );
m_findZone.result.emplace_back( std::move( thrOut ) );
}
}
}
void View::RecalcFindMatches( const Vector<ZoneEvent*>& events, Vector<ZoneEvent*>& out, const int maxdepth )
{
for( auto& ev : events )
{
if( out.size() >= m_findZone.maxZonesPerThread ) break;
if( m_worker.GetZoneEnd( *ev ) == ev->start ) continue;
auto it = m_findZone.match.find( ev->srcloc );
if( it != m_findZone.match.end() && it->second )
{
out.push_back( ev );
}
if( maxdepth != 0 )
{
RecalcFindMatches( ev->child, out, maxdepth - 1 );
}
} }
} }

View File

@ -98,8 +98,6 @@ private:
const GpuEvent* GetZoneParent( const GpuEvent& zone ) const; const GpuEvent* GetZoneParent( const GpuEvent& zone ) const;
void FindZones(); void FindZones();
void RecalcFindMatches();
void RecalcFindMatches( const Vector<ZoneEvent*> &events, Vector<ZoneEvent*> &out, const int maxdepth = 0 );
template <typename T> template <typename T>
bool& Visible( const T* ptr ) bool& Visible( const T* ptr )
@ -168,12 +166,9 @@ private:
struct { struct {
bool show; bool show;
std::vector<std::unique_ptr<ThreadData>> result;
std::vector<uint32_t> counts; std::vector<uint32_t> counts;
flat_hash_map<int32_t, bool> match; flat_hash_map<int32_t, bool> match;
char pattern[1024] = { "" }; char pattern[1024] = { "" };
int maxZonesPerThread = -1;
int maxDepth = -1;
bool logVal = false; bool logVal = false;
bool logTime = false; bool logTime = false;
bool cumulateTime = false; bool cumulateTime = false;
@ -181,7 +176,6 @@ private:
void Reset() void Reset()
{ {
result.clear();
match.clear(); match.clear();
counts.clear(); counts.clear();
highlight.active = false; highlight.active = false;