From 9898066a7a44f30937792b79d8f3f9c48fb779ec Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 27 May 2018 20:11:33 +0200 Subject: [PATCH] Display additional memory event info in mem plot tooltips. --- server/TracyView.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index bd4d0953..f2e48b8c 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2612,7 +2612,64 @@ void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint ImGui::Text( "Value: %s", RealToString( item->val, true ) ); if( hasPrev ) { - ImGui::Text( "Change: %s", RealToString( item->val - prev, true ) ); + const auto change = item->val - prev; + ImGui::Text( "Change: %s", RealToString( change, true ) ); + + if( type == PlotType::Memory ) + { + auto& mem = m_worker.GetMemData(); + const MemEvent* ev = nullptr; + if( change > 0 ) + { + auto it = std::lower_bound( mem.data.begin(), mem.data.end(), item->time, [] ( const auto& lhs, const auto& rhs ) { return lhs.timeAlloc < rhs; } ); + if( it != mem.data.end() && it->timeAlloc == item->time ) + { + ev = it; + } + } + else + { + const auto& data = mem.data; + auto it = std::lower_bound( mem.frees.begin(), mem.frees.end(), item->time, [&data] ( const auto& lhs, const auto& rhs ) { return data[lhs].timeFree < rhs; } ); + if( it != mem.frees.end() && data[*it].timeFree == item->time ) + { + ev = &data[*it]; + } + } + if( ev ) + { + ImGui::Separator(); + ImGui::Text( "Address: 0x%" PRIx64, ev->ptr ); + ImGui::Text( "Appeared at %s", TimeToString( m_worker.GetLastTime() - ev->timeAlloc ) ); + if( change > 0 ) + { + ImGui::SameLine(); + ImGui::TextDisabled( "(this event)" ); + } + if( ev->timeFree < 0 ) + { + ImGui::Text( "Allocation still active" ); + } + else + { + ImGui::Text( "Freed at %s", TimeToString( m_worker.GetLastTime() - ev->timeFree ) ); + if( change < 0 ) + { + ImGui::SameLine(); + ImGui::TextDisabled( "(this event)" ); + } + ImGui::Text( "Duration: %s", TimeToString( ev->timeFree - ev->timeAlloc ) ); + } + if( change > 0 ) + { + ImGui::Text( "Thread: %s", m_worker.GetThreadString( m_worker.DecompressThread( ev->threadAlloc ) ) ); + } + else + { + ImGui::Text( "Thread: %s", m_worker.GetThreadString( m_worker.DecompressThread( ev->threadFree ) ) ); + } + } + } } ImGui::EndTooltip(); }