From d93c4bc271b31df8dc493d576502d4a53f1cac7f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 4 Oct 2017 21:27:06 +0200 Subject: [PATCH] Very crude drawing of lock events. --- server/TracyView.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++-- server/TracyView.hpp | 1 + 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 79688b95..8af40151 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1338,9 +1338,11 @@ void View::DrawZones() offset += ostep; m_lastCpu = -1; - const auto depth = DrawZoneLevel( v->timeline, hover, pxns, wpos, offset, 0 ); + auto depth = DrawZoneLevel( v->timeline, hover, pxns, wpos, offset, 0 ); + offset += ostep * ( depth + 1 ); - offset += ostep * ( depth + 1.2f ); + depth = DrawLocks( v->id, hover, pxns, wpos, offset ); + offset += ostep * ( depth + 0.2f ); } } @@ -1514,6 +1516,52 @@ int View::DrawZoneLevel( const Vector& vec, bool hover, double pxns, con return maxdepth; } +int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int _offset ) +{ + int cnt = 0; + for( auto& v : m_lockMap ) + { + auto& lockmap = v.second; + if( lockmap.threads.find( tid ) == lockmap.threads.end() ) continue; + auto& tl = lockmap.timeline; + auto it = std::lower_bound( tl.begin(), tl.end(), m_zvStart - m_delay, [] ( const auto& l, const auto& r ) { return l->time < r; } ); + if( it != tl.end() ) + { + const auto eit = std::lower_bound( tl.begin(), tl.end(), m_zvEnd + m_resolution, [] ( const auto& l, const auto& r ) { return l->time < r; } ); + if( it != eit ) + { + bool drawn = false; + const auto ty = ImGui::GetFontSize(); + const auto ostep = ty + 1; + const auto offset = _offset + ostep * cnt; + auto draw = ImGui::GetWindowDrawList(); + auto& srcloc = GetSourceLocation( lockmap.srcloc ); + + int64_t pos = std::distance( tl.begin(), it ); + int64_t last = std::distance( tl.begin(), eit ); + + while( pos < last ) + { + if( tl[pos]->thread == tid ) + { + const auto px0 = ( tl[pos]->time - m_zvStart ) * pxns; + draw->AddCircle( wpos + ImVec2( px0, offset + ty / 2 ), 5.f, tl[pos]->type == LockEvent::Type::Wait ? 0xFF0000FF : ( tl[pos]->type == LockEvent::Type::Obtain ? 0xFF00FF00 : 0xFF00FFFF ) ); + drawn = true; + } + pos++; + } + + if( drawn ) + { + draw->AddText( wpos + ImVec2( 0, offset ), 0xFF8888FF, GetString( srcloc.function ) ); + cnt++; + } + } + } + } + return cnt; +} + void View::DrawZoneInfoWindow() { if( !m_zoneInfoWindow ) return; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index f71aa673..e3bcf863 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -103,6 +103,7 @@ private: void DrawFrames(); void DrawZones(); int DrawZoneLevel( const Vector& vec, bool hover, double pxns, const ImVec2& wpos, int offset, int depth ); + int DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int offset ); void DrawZoneInfoWindow(); uint32_t GetZoneColor( const Event& ev );