1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Use adapters during zone level iteration.

This commit is contained in:
Bartosz Taudul 2019-11-09 23:05:01 +01:00
parent 85e7125fee
commit 7be19193d9
2 changed files with 23 additions and 17 deletions

View File

@ -3010,25 +3010,27 @@ int View::DispatchZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover
const auto yPos = wpos.y + offset; const auto yPos = wpos.y + offset;
if( yPos + ostep >= yMin && yPos <= yMax ) if( yPos + ostep >= yMin && yPos <= yMax )
{ {
return DrawZoneLevel( vec, hover, pxns, nspx, wpos, _offset, depth, yMin, yMax, tid ); return DrawZoneLevel<VectorAdapterPointer<ZoneEvent>>( vec, hover, pxns, nspx, wpos, _offset, depth, yMin, yMax, tid );
} }
else else
{ {
return SkipZoneLevel( vec, hover, pxns, nspx, wpos, _offset, depth, yMin, yMax, tid ); return SkipZoneLevel<VectorAdapterPointer<ZoneEvent>>( vec, hover, pxns, nspx, wpos, _offset, depth, yMin, yMax, tid );
} }
} }
int View::DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid ) template<typename Adapter, typename V>
int View::DrawZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid )
{ {
const auto delay = m_worker.GetDelay(); const auto delay = m_worker.GetDelay();
const auto resolution = m_worker.GetResolution(); const auto resolution = m_worker.GetResolution();
// cast to uint64_t, so that unended zones (end = -1) are still drawn // cast to uint64_t, so that unended zones (end = -1) are still drawn
auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_vd.zvStart - delay ), [] ( const auto& l, const auto& r ) { return (uint64_t)l->End() < (uint64_t)r; } ); auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_vd.zvStart - delay ), [] ( const auto& l, const auto& r ) { Adapter a; return (uint64_t)a(l).End() < (uint64_t)r; } );
if( it == vec.end() ) return depth; if( it == vec.end() ) return depth;
const auto zitend = std::lower_bound( it, vec.end(), m_vd.zvEnd + resolution, [] ( const auto& l, const auto& r ) { return l->Start() < r; } ); const auto zitend = std::lower_bound( it, vec.end(), m_vd.zvEnd + resolution, [] ( const auto& l, const auto& r ) { Adapter a; return a(l).Start() < r; } );
if( it == zitend ) return depth; if( it == zitend ) return depth;
if( (*it)->End() < 0 && m_worker.GetZoneEnd( **it ) < m_vd.zvStart ) return depth; Adapter a;
if( a(*it).End() < 0 && m_worker.GetZoneEnd( a(*it) ) < m_vd.zvStart ) return depth;
const auto w = ImGui::GetWindowContentRegionWidth() - 1; const auto w = ImGui::GetWindowContentRegionWidth() - 1;
const auto ty = ImGui::GetFontSize(); const auto ty = ImGui::GetFontSize();
@ -3043,7 +3045,7 @@ int View::DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, do
while( it < zitend ) while( it < zitend )
{ {
auto& ev = **it; auto& ev = a(*it);
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 ); const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 );
if( zsz < MinVisSize ) if( zsz < MinVisSize )
@ -3057,11 +3059,11 @@ int View::DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, do
for(;;) for(;;)
{ {
const auto prevIt = it; const auto prevIt = it;
it = std::lower_bound( it, zitend, nextTime, [] ( const auto& l, const auto& r ) { return (uint64_t)l->End() < (uint64_t)r; } ); it = std::lower_bound( it, zitend, nextTime, [] ( const auto& l, const auto& r ) { Adapter a; return (uint64_t)a(l).End() < (uint64_t)r; } );
if( it == prevIt ) ++it; if( it == prevIt ) ++it;
num += std::distance( prevIt, it ); num += std::distance( prevIt, it );
if( it == zitend ) break; if( it == zitend ) break;
const auto nend = m_worker.GetZoneEnd( **it ); const auto nend = m_worker.GetZoneEnd( a(*it) );
const auto pxnext = ( nend - m_vd.zvStart ) * pxns; const auto pxnext = ( nend - m_vd.zvStart ) * pxns;
if( pxnext - px1 >= MinVisSize * 2 ) break; if( pxnext - px1 >= MinVisSize * 2 ) break;
px1 = pxnext; px1 = pxnext;
@ -3237,23 +3239,25 @@ int View::DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, do
return maxdepth; return maxdepth;
} }
int View::SkipZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid ) template<typename Adapter, typename V>
int View::SkipZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid )
{ {
const auto delay = m_worker.GetDelay(); const auto delay = m_worker.GetDelay();
const auto resolution = m_worker.GetResolution(); const auto resolution = m_worker.GetResolution();
// cast to uint64_t, so that unended zones (end = -1) are still drawn // cast to uint64_t, so that unended zones (end = -1) are still drawn
auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_vd.zvStart - delay ), [] ( const auto& l, const auto& r ) { return (uint64_t)l->End() < (uint64_t)r; } ); auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_vd.zvStart - delay ), [] ( const auto& l, const auto& r ) { Adapter a; return (uint64_t)a(l).End() < (uint64_t)r; } );
if( it == vec.end() ) return depth; if( it == vec.end() ) return depth;
const auto zitend = std::lower_bound( it, vec.end(), m_vd.zvEnd + resolution, [] ( const auto& l, const auto& r ) { return l->Start() < r; } ); const auto zitend = std::lower_bound( it, vec.end(), m_vd.zvEnd + resolution, [] ( const auto& l, const auto& r ) { Adapter a; return a(l).Start() < r; } );
if( it == zitend ) return depth; if( it == zitend ) return depth;
depth++; depth++;
int maxdepth = depth; int maxdepth = depth;
Adapter a;
while( it < zitend ) while( it < zitend )
{ {
auto& ev = **it; auto& ev = a(*it);
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 ); const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 );
if( zsz < MinVisSize ) if( zsz < MinVisSize )
@ -3263,10 +3267,10 @@ int View::SkipZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, do
for(;;) for(;;)
{ {
const auto prevIt = it; const auto prevIt = it;
it = std::lower_bound( it, zitend, nextTime, [] ( const auto& l, const auto& r ) { return (uint64_t)l->End() < (uint64_t)r; } ); it = std::lower_bound( it, zitend, nextTime, [] ( const auto& l, const auto& r ) { Adapter a; return (uint64_t)a(l).End() < (uint64_t)r; } );
if( it == prevIt ) ++it; if( it == prevIt ) ++it;
if( it == zitend ) break; if( it == zitend ) break;
const auto nend = m_worker.GetZoneEnd( **it ); const auto nend = m_worker.GetZoneEnd( a(*it) );
const auto pxnext = ( nend - m_vd.zvStart ) * pxns; const auto pxnext = ( nend - m_vd.zvStart ) * pxns;
if( pxnext - px1 >= MinVisSize * 2 ) break; if( pxnext - px1 >= MinVisSize * 2 ) break;
px1 = pxnext; px1 = pxnext;

View File

@ -120,8 +120,10 @@ private:
void DrawZones(); void DrawZones();
void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset ); void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset );
int DispatchZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int DispatchZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );
int DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); template<typename Adapter, typename V>
int SkipZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int DrawZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );
template<typename Adapter, typename V>
int SkipZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
int DrawGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int DrawGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
int SkipGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int SkipGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );