From e40f029b197d01a7d1e7aa4f1eb2e7f89f3d694d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 12 Nov 2017 01:25:44 +0100 Subject: [PATCH] GPU info window. --- server/TracyView.cpp | 169 ++++++++++++++++++++++++++++++++++++++++--- server/TracyView.hpp | 7 +- 2 files changed, 166 insertions(+), 10 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 42c1af6b..537af6ea 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -139,6 +139,7 @@ View::View( const char* addr ) , m_zvScroll( 0 ) , m_zoneInfoWindow( nullptr ) , m_lockHighlight { -1 } + , m_gpuInfoWindow( nullptr ) , m_drawRegion( false ) , m_showOptions( false ) , m_showMessages( false ) @@ -179,6 +180,7 @@ View::View( FileRead& f ) , m_zvHeight( 0 ) , m_zvScroll( 0 ) , m_zoneInfoWindow( nullptr ) + , m_gpuInfoWindow( nullptr ) , m_drawRegion( false ) , m_showOptions( false ) , m_showMessages( false ) @@ -1524,7 +1526,7 @@ void View::DrawImpl() ImGui::End(); m_zoneHighlight = nullptr; - DrawZoneInfoWindow(); + DrawInfoWindow(); if( m_showOptions ) DrawOptions(); if( m_showMessages ) DrawMessages(); @@ -2266,6 +2268,7 @@ int View::DrawZoneLevel( const Vector& vec, bool hover, double pxns, if( ImGui::IsMouseClicked( 0 ) ) { m_zoneInfoWindow = &ev; + m_gpuInfoWindow = nullptr; } } } @@ -2380,6 +2383,7 @@ int View::DrawZoneLevel( const Vector& vec, bool hover, double pxns, if( ImGui::IsMouseClicked( 0 ) ) { m_zoneInfoWindow = &ev; + m_gpuInfoWindow = nullptr; } } @@ -2459,6 +2463,11 @@ int View::DrawGpuZoneLevel( const Vector& vec, bool hover, double pxn { ZoomToZone( ev ); } + if( ImGui::IsMouseClicked( 0 ) ) + { + m_zoneInfoWindow = nullptr; + m_gpuInfoWindow = &ev; + } m_gpuThread = ev.thread; m_gpuStart = ev.cpuStart; @@ -2535,6 +2544,11 @@ int View::DrawGpuZoneLevel( const Vector& vec, bool hover, double pxn { ZoomToZone( ev ); } + if( ImGui::IsMouseClicked( 0 ) ) + { + m_zoneInfoWindow = nullptr; + m_gpuInfoWindow = &ev; + } m_gpuThread = ev.thread; m_gpuStart = ev.cpuStart; @@ -3179,10 +3193,20 @@ void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint } } +void View::DrawInfoWindow() +{ + if( m_zoneInfoWindow ) + { + DrawZoneInfoWindow(); + } + else if( m_gpuInfoWindow ) + { + DrawGpuInfoWindow(); + } +} + void View::DrawZoneInfoWindow() { - if( !m_zoneInfoWindow ) return; - auto& ev = *m_zoneInfoWindow; int dmul = 1; @@ -3291,6 +3315,98 @@ void View::DrawZoneInfoWindow() if( !show ) m_zoneInfoWindow = nullptr; } +void View::DrawGpuInfoWindow() +{ + auto& ev = *m_gpuInfoWindow; + + bool show = true; + ImGui::Begin( "Zone info", &show, ImGuiWindowFlags_ShowBorders ); + + if( ImGui::Button( "Zoom to zone" ) ) + { + ZoomToZone( ev ); + } + ImGui::SameLine(); + if( ImGui::Button( "Go to parent" ) ) + { + auto parent = GetZoneParent( ev ); + if( parent ) + { + m_gpuInfoWindow = parent; + } + } + + ImGui::Separator(); + + ImGui::Text( "Zone name: %s", GetString( ev.name ) ); + auto& srcloc = GetSourceLocation( ev.srcloc ); + ImGui::Text( "Function: %s", GetString( srcloc.function ) ); + ImGui::Text( "Location: %s:%i", GetString( srcloc.file ), srcloc.line ); + + ImGui::Separator(); + + const auto end = GetZoneEnd( ev ); + const auto ztime = end - ev.gpuStart; + ImGui::Text( "Time from start of program: %s", TimeToString( ev.gpuStart - m_frames[0] ) ); + ImGui::Text( "GPU execution time: %s", TimeToString( ztime ) ); + ImGui::Text( "CPU command setup time: %s", TimeToString( ev.cpuEnd - ev.cpuStart ) ); + ImGui::Text( "Delay to execution: %s", TimeToString( ev.gpuStart - ev.cpuStart ) ); + + auto ctt = std::make_unique( ev.child.size() ); + auto cti = std::make_unique( ev.child.size() ); + uint64_t ctime = 0; + for( size_t i=0; igpuStart; + ctime += ct; + ctt[i] = ct; + cti[i] = uint32_t( i ); + } + + std::sort( cti.get(), cti.get() + ev.child.size(), [&ctt] ( const auto& lhs, const auto& rhs ) { return ctt[lhs] > ctt[rhs]; } ); + + if( !ev.child.empty() ) + { + const auto ty = ImGui::GetTextLineHeight(); + ImGui::Columns( 2 ); + ImGui::Separator(); + ImGui::Text( "Child zones: %" PRIu64, ev.child.size() ); + ImGui::NextColumn(); + ImGui::Text( "Exclusive time: %s (%.2f%%)", TimeToString( ztime - ctime ), double( ztime - ctime ) / ztime * 100 ); + ImGui::NextColumn(); + ImGui::Separator(); + for( size_t i=0; i( 0xFF, ( ( ( color & 0x00FF0000 ) >> 16 ) + 25 ) ) << 16 ) | - ( std::min( 0xFF, ( ( ( color & 0x0000FF00 ) >> 8 ) + 25 ) ) << 8 ) | - ( std::min( 0xFF, ( ( ( color & 0x000000FF ) ) + 25 ) ) ); + if( m_gpuInfoWindow == &ev ) + { + return 0xFF44DD44; + } + else + { + const auto color = GetZoneColor( ev ); + return 0xFF000000 | + ( std::min( 0xFF, ( ( ( color & 0x00FF0000 ) >> 16 ) + 25 ) ) << 16 ) | + ( std::min( 0xFF, ( ( ( color & 0x0000FF00 ) >> 8 ) + 25 ) ) << 8 ) | + ( std::min( 0xFF, ( ( ( color & 0x000000FF ) ) + 25 ) ) ); + } } float View::GetZoneThickness( const ZoneEvent& ev ) @@ -3418,7 +3541,14 @@ float View::GetZoneThickness( const ZoneEvent& ev ) float View::GetZoneThickness( const GpuEvent& ev ) { - return 1.f; + if( m_gpuInfoWindow == &ev ) + { + return 3.f; + } + else + { + return 1.f; + } } void View::ZoomToZone( const ZoneEvent& ev ) @@ -3532,6 +3662,27 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const return nullptr; } +const GpuEvent* View::GetZoneParent( const GpuEvent& zone ) const +{ + for( auto& ctx : m_gpuData ) + { + const GpuEvent* parent = nullptr; + const Vector* timeline = &ctx->timeline; + if( timeline->empty() ) continue; + for(;;) + { + auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.gpuStart, [] ( const auto& l, const auto& r ) { return l < r->gpuStart; } ); + if( it != timeline->begin() ) --it; + if( zone.gpuEnd != -1 && (*it)->gpuStart > zone.gpuEnd ) break; + if( *it == &zone ) return parent; + if( (*it)->child.empty() ) break; + parent = *it; + timeline = &parent->child; + } + } + return nullptr; +} + TextData* View::GetTextData( ZoneEvent& zone ) { if( zone.text == -1 ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 7032c21b..3c103675 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -124,12 +124,15 @@ private: int DrawZoneLevel( const Vector& vec, bool hover, double pxns, const ImVec2& wpos, int offset, int depth ); int DrawGpuZoneLevel( 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, LockHighlight& highlight ); - void DrawZoneInfoWindow(); int DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover ); void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev, bool merged ); void DrawOptions(); void DrawMessages(); + void DrawInfoWindow(); + void DrawZoneInfoWindow(); + void DrawGpuInfoWindow(); + void HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, double& pxns ); uint32_t GetZoneColor( const ZoneEvent& ev ); @@ -144,6 +147,7 @@ private: void ZoneTooltip( const ZoneEvent& ev ); void ZoneTooltip( const GpuEvent& ev ); const ZoneEvent* GetZoneParent( const ZoneEvent& zone ) const; + const GpuEvent* GetZoneParent( const GpuEvent& zone ) const; TextData* GetTextData( ZoneEvent& zone ); const TextData* GetTextData( const ZoneEvent& zone ) const; @@ -230,6 +234,7 @@ private: const ZoneEvent* m_zoneHighlight; LockHighlight m_lockHighlight; const MessageData* m_msgHighlight; + const GpuEvent* m_gpuInfoWindow; bool m_drawRegion; int64_t m_regionStart;