1
0
mirror of https://github.com/wolfpld/tracy synced 2025-01-26 01:16:35 +00:00

Compare commits

...

15 Commits

Author SHA1 Message Date
Bartosz Taudul
8ddf26fff2
Simplify code. 2021-03-27 15:24:42 +01:00
Bartosz Taudul
741aebaa77
Update NEWS. 2021-03-27 14:16:11 +01:00
Bartosz Taudul
4c4fc7197c
Add source preview to entry call stacks window. 2021-03-27 14:15:18 +01:00
Bartosz Taudul
9bbffcb67f
Add source tooltip in memory frame trees. 2021-03-27 14:09:40 +01:00
Bartosz Taudul
5ebffe388a
Check for file name pointer validity. 2021-03-27 14:09:35 +01:00
Bartosz Taudul
ff6ecef5f3
Add source preview to statistics window. 2021-03-27 14:02:52 +01:00
Bartosz Taudul
62ac5544b6
Trim empty lines at top and bottom of source preview. 2021-03-27 13:55:22 +01:00
Bartosz Taudul
a15ba0c7fb
Show source preview tooltip in find zones. 2021-03-27 13:47:20 +01:00
Bartosz Taudul
895a63b41a
Add source preview to call stack window. 2021-03-27 13:43:12 +01:00
Bartosz Taudul
e2be45c0ba
Show preview of lock source locations in options window. 2021-03-27 13:43:12 +01:00
Bartosz Taudul
8f0c5e867e
Source tooltip implementation. 2021-03-27 13:43:11 +01:00
Bartosz Taudul
0b6e55ee87
Store fixed-width font in View. 2021-03-27 13:43:11 +01:00
Bartosz Taudul
d56f7dab09
Remove unneeded forward declarations. 2021-03-27 13:05:59 +01:00
Bartosz Taudul
1cb6c17991
Move syntax color tables to a common header. 2021-03-27 13:03:19 +01:00
Bartosz Taudul
ff5435ff67
Cosmetics. 2021-03-27 13:03:19 +01:00
7 changed files with 253 additions and 126 deletions

3
NEWS
View File

@ -34,8 +34,7 @@ v0.x.x (xxxx-xx-xx)
without an intermediate free.
- Renamed "call stack parents" to "entry call stacks".
- Display number of entry call stacks in assembly line sample count tooltip.
- Added preview of source code corresponding to assembly instruction in a
tooltip.
- Added tooltips with preview of source code in various places in the UI.
v0.7.6 (2021-02-06)

View File

@ -2,7 +2,7 @@
#define __TRACYIMGUI_HPP__
#ifdef _MSC_VER
# pragma warning( disable: 4244 ) // conversion from don't care to whatever, possible loss of data
# pragma warning( disable: 4244 ) // conversion from don't care to whatever, possible loss of data
#endif
#include <algorithm>
@ -22,6 +22,32 @@ static inline ImVec2 operator-( const ImVec2& l, const ImVec2& r ) { return ImVe
namespace tracy
{
static const ImVec4 SyntaxColors[] = {
{ 0.7f, 0.7f, 0.7f, 1 }, // default
{ 0.45f, 0.68f, 0.32f, 1 }, // comment
{ 0.72f, 0.37f, 0.12f, 1 }, // preprocessor
{ 0.64f, 0.64f, 1, 1 }, // string
{ 0.64f, 0.82f, 1, 1 }, // char literal
{ 1, 0.91f, 0.53f, 1 }, // keyword
{ 0.81f, 0.6f, 0.91f, 1 }, // number
{ 0.9f, 0.9f, 0.9f, 1 }, // punctuation
{ 0.78f, 0.46f, 0.75f, 1 }, // type
{ 0.21f, 0.69f, 0.89f, 1 }, // special
};
static const ImVec4 SyntaxColorsDimmed[] = {
{ 0.7f, 0.7f, 0.7f, 0.6f }, // default
{ 0.45f, 0.68f, 0.32f, 0.6f }, // comment
{ 0.72f, 0.37f, 0.12f, 0.6f }, // preprocessor
{ 0.64f, 0.64f, 1, 0.6f }, // string
{ 0.64f, 0.82f, 1, 0.6f }, // char literal
{ 1, 0.91f, 0.53f, 0.6f }, // keyword
{ 0.81f, 0.6f, 0.91f, 0.6f }, // number
{ 0.9f, 0.9f, 0.9f, 0.6f }, // punctuation
{ 0.78f, 0.46f, 0.75f, 0.6f }, // type
{ 0.21f, 0.69f, 0.89f, 0.6f }, // special
};
[[maybe_unused]] static inline void TextCentered( const char* text )
{
const auto tw = ImGui::CalcTextSize( text ).x;
@ -193,7 +219,7 @@ namespace tracy
const auto manhatten_distance = x0 + flipped_v0y;
const auto in_multiples_of_2_times_sw = int( manhatten_distance / ( sw*2 ) );
const auto floored_manhatten_distance = double( in_multiples_of_2_times_sw*sw*2 ); //floor in terms of 2 * stripe width
const auto corrected_flipped_v0y = ( floored_manhatten_distance - x0 ); //the corrected (floored) y respects the position of the stripes

View File

@ -72,15 +72,11 @@ public:
template<class Compare>
tracy_force_inline void push_back( const T& val, Compare comp )
{
if( sortedEnd != 0 || v.empty() || comp( v.back(), val ) )
{
v.push_back( val );
}
else
if( sortedEnd == 0 && !v.empty() && !comp( v.back(), val ) )
{
sortedEnd = (uint32_t)v.size();
v.push_back( val );
}
v.push_back( val );
}
tracy_force_inline void reserve( size_t cap ) { v.reserve( cap ); }

View File

@ -311,5 +311,4 @@ out:
return TokenColor::Default;
}
}

View File

@ -2171,32 +2171,6 @@ static bool PrintPercentage( float val, uint32_t col = 0xFFFFFFFF )
return ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect( wpos, wpos + ImVec2( stw * 7, ty ) );
}
static const ImVec4 SyntaxColors[] = {
{ 0.7f, 0.7f, 0.7f, 1 }, // default
{ 0.45f, 0.68f, 0.32f, 1 }, // comment
{ 0.72f, 0.37f, 0.12f, 1 }, // preprocessor
{ 0.64f, 0.64f, 1, 1 }, // string
{ 0.64f, 0.82f, 1, 1 }, // char literal
{ 1, 0.91f, 0.53f, 1 }, // keyword
{ 0.81f, 0.6f, 0.91f, 1 }, // number
{ 0.9f, 0.9f, 0.9f, 1 }, // punctuation
{ 0.78f, 0.46f, 0.75f, 1 }, // type
{ 0.21f, 0.69f, 0.89f, 1 }, // special
};
static const ImVec4 SyntaxColorsDimmed[] = {
{ 0.7f, 0.7f, 0.7f, 0.6f }, // default
{ 0.45f, 0.68f, 0.32f, 0.6f }, // comment
{ 0.72f, 0.37f, 0.12f, 0.6f }, // preprocessor
{ 0.64f, 0.64f, 1, 0.6f }, // string
{ 0.64f, 0.82f, 1, 0.6f }, // char literal
{ 1, 0.91f, 0.53f, 0.6f }, // keyword
{ 0.81f, 0.6f, 0.91f, 0.6f }, // number
{ 0.9f, 0.9f, 0.9f, 0.6f }, // punctuation
{ 0.78f, 0.46f, 0.75f, 0.6f }, // type
{ 0.21f, 0.69f, 0.89f, 0.6f }, // special
};
void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker* worker )
{
const auto ty = ImGui::GetFontSize();
@ -2580,15 +2554,24 @@ void SourceView::RenderAsmLine( AsmLine& line, uint32_t ipcnt, uint32_t iptotal,
auto& lines = m_sourceTooltip.get();
const int start = std::max( 0, (int)srcline - 4 );
const int end = std::min<int>( m_sourceTooltip.get().size(), srcline + 3 );
bool first = true;
int bottomEmpty = 0;
for( int i=start; i<end; i++ )
{
auto& line = lines[i];
if( line.begin == line.end )
{
ImGui::TextUnformatted( "" );
if( !first ) bottomEmpty++;
}
else
{
first = false;
while( bottomEmpty > 0 )
{
ImGui::TextUnformatted( "" );
bottomEmpty--;
}
auto ptr = line.begin;
auto it = line.tokens.begin();
while( ptr < line.end )

View File

@ -134,6 +134,7 @@ View::View( void(*cbMainThread)(std::function<void()>), const char* addr, uint16
, m_reactToLostConnection( true )
, m_smallFont( smallFont )
, m_bigFont( bigFont )
, m_fixedFont( fixedWidth )
, m_stcb( stcb )
, m_gwcb( gwcb )
, m_userData()
@ -155,6 +156,7 @@ View::View( void(*cbMainThread)(std::function<void()>), FileRead& f, ImFont* fix
, m_messagesScrollBottom( false )
, m_smallFont( smallFont )
, m_bigFont( bigFont )
, m_fixedFont( fixedWidth )
, m_stcb( stcb )
, m_gwcb( gwcb )
, m_userData( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() )
@ -8711,15 +8713,19 @@ void View::DrawOptions()
ImGui::SameLine();
}
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size() ), fileName, sl.line );
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( fileName, sl.line, 1, 1 );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSource( fileName, sl.line );
}
else
{
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSource( fileName, sl.line );
}
else
{
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
}
}
}
}
@ -8785,15 +8791,19 @@ void View::DrawOptions()
ImGui::SameLine();
}
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size() ), fileName, sl.line );
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( fileName, sl.line, 1, 1 );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSource( fileName, sl.line );
}
else
{
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSource( fileName, sl.line );
}
else
{
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
}
}
}
}
@ -8859,15 +8869,19 @@ void View::DrawOptions()
ImGui::SameLine();
}
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size() ), fileName, sl.line );
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( fileName, sl.line, 1, 1 );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSource( fileName, sl.line );
}
else
{
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSource( fileName, sl.line );
}
else
{
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
}
}
}
}
@ -9513,15 +9527,19 @@ void View::DrawFindZone()
}
const auto fileName = m_worker.GetString( srcloc.file );
ImGui::TextColored( ImVec4( 0.5, 0.5, 0.5, 1 ), "(%s) %s:%i", RealToString( zones.size() ), fileName, srcloc.line );
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( fileName, srcloc.line );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSource( fileName, srcloc.line );
}
else
{
m_findZoneBuzzAnim.Enable( idx, 0.5f );
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSource( fileName, srcloc.line );
}
else
{
m_findZoneBuzzAnim.Enable( idx, 0.5f );
}
}
}
ImGui::PopID();
@ -12474,15 +12492,19 @@ void View::DrawStatistics()
const auto file = m_worker.GetString( srcloc.file );
ImGui::TextDisabled( "%s:%i", file, srcloc.line );
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( file, srcloc.line );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSource( file, srcloc.line );
}
else
{
m_statBuzzAnim.Enable( v.srcloc, 0.5f );
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSource( file, srcloc.line );
}
else
{
m_statBuzzAnim.Enable( v.srcloc, 0.5f );
}
}
}
if( indentVal != 0.f )
@ -12916,30 +12938,34 @@ void View::DrawStatistics()
{
TextDisabledUnformatted( file );
}
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( file, line );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSymbol( file, line, codeAddr, v.symAddr );
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( false );
}
else if( symlen != 0 )
{
uint32_t len;
if( m_worker.GetSymbolCode( codeAddr, len ) )
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSymbol( nullptr, 0, codeAddr, v.symAddr );
ViewSymbol( file, line, codeAddr, v.symAddr );
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( false );
}
else if( symlen != 0 )
{
uint32_t len;
if( m_worker.GetSymbolCode( codeAddr, len ) )
{
ViewSymbol( nullptr, 0, codeAddr, v.symAddr );
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( false );
}
else
{
m_statBuzzAnim.Enable( v.symAddr, 0.5f );
}
}
else
{
m_statBuzzAnim.Enable( v.symAddr, 0.5f );
}
}
else
{
m_statBuzzAnim.Enable( v.symAddr, 0.5f );
}
}
if( indentVal != 0.f )
{
@ -13089,30 +13115,34 @@ void View::DrawStatistics()
{
TextDisabledUnformatted( file );
}
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
DrawSourceTooltip( file, line );
if( ImGui::IsItemClicked( 1 ) )
{
ViewSymbol( file, line, codeAddr, iv.symAddr );
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( true );
}
else if( symlen != 0 )
{
uint32_t len;
if( m_worker.GetSymbolCode( codeAddr, len ) )
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
{
ViewSymbol( nullptr, 0, codeAddr, iv.symAddr );
ViewSymbol( file, line, codeAddr, iv.symAddr );
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( true );
}
else if( symlen != 0 )
{
uint32_t len;
if( m_worker.GetSymbolCode( codeAddr, len ) )
{
ViewSymbol( nullptr, 0, codeAddr, iv.symAddr );
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( true );
}
else
{
m_statBuzzAnim.Enable( iv.symAddr, 0.5f );
}
}
else
{
m_statBuzzAnim.Enable( iv.symAddr, 0.5f );
}
}
else
{
m_statBuzzAnim.Enable( iv.symAddr, 0.5f );
}
}
if( indentVal != 0.f )
{
@ -13435,7 +13465,7 @@ void View::DrawCallstackWindow()
assert( false );
break;
}
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( m_showCallstackFrameAddress == 3 )
{
@ -13443,21 +13473,37 @@ void View::DrawCallstackWindow()
if( sym )
{
const auto symtxt = m_worker.GetString( sym->file );
if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) )
DrawSourceTooltip( symtxt, sym->line );
}
}
else
{
DrawSourceTooltip( txt, frame.line );
}
if( ImGui::IsItemClicked( 1 ) )
{
if( m_showCallstackFrameAddress == 3 )
{
const auto sym = m_worker.GetSymbolData( frame.symAddr );
if( sym )
{
const auto symtxt = m_worker.GetString( sym->file );
if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) )
{
m_callstackBuzzAnim.Enable( bidx, 0.5f );
}
}
else
{
m_callstackBuzzAnim.Enable( bidx, 0.5f );
}
}
else
{
m_callstackBuzzAnim.Enable( bidx, 0.5f );
}
}
else
{
if( !ViewDispatch( txt, frame.line, frame.symAddr ) )
{
m_callstackBuzzAnim.Enable( bidx, 0.5f );
if( !ViewDispatch( txt, frame.line, frame.symAddr ) )
{
m_callstackBuzzAnim.Enable( bidx, 0.5f );
}
}
}
}
@ -15514,7 +15560,7 @@ void View::DrawSampleParents()
assert( false );
break;
}
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( m_showCallstackFrameAddress == 3 )
{
@ -15522,21 +15568,37 @@ void View::DrawSampleParents()
if( sym )
{
const auto symtxt = m_worker.GetString( sym->file );
if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) )
DrawSourceTooltip( symtxt, sym->line );
}
}
else
{
DrawSourceTooltip( txt, frame.line );
}
if( ImGui::IsItemClicked( 1 ) )
{
if( m_showCallstackFrameAddress == 3 )
{
const auto sym = m_worker.GetSymbolData( frame.symAddr );
if( sym )
{
const auto symtxt = m_worker.GetString( sym->file );
if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) )
{
m_sampleParentBuzzAnim.Enable( bidx, 0.5f );
}
}
else
{
m_sampleParentBuzzAnim.Enable( bidx, 0.5f );
}
}
else
{
m_sampleParentBuzzAnim.Enable( bidx, 0.5f );
}
}
else
{
if( !ViewDispatch( txt, frame.line, frame.symAddr ) )
{
m_sampleParentBuzzAnim.Enable( bidx, 0.5f );
if( !ViewDispatch( txt, frame.line, frame.symAddr ) )
{
m_sampleParentBuzzAnim.Enable( bidx, 0.5f );
}
}
}
}
@ -16601,11 +16663,15 @@ void View::DrawFrameTreeLevel( const unordered_flat_map<uint64_t, CallstackFrame
fileName = m_worker.GetString( frame.file );
ImGui::TextDisabled( "%s:%i", fileName, frame.line );
}
if( ImGui::IsItemClicked( 1 ) )
if( ImGui::IsItemHovered() )
{
if( !ViewDispatch( fileName, frame.line, frame.symAddr ) )
DrawSourceTooltip( fileName, frame.line );
if( ImGui::IsItemClicked( 1 ) )
{
m_callstackTreeBuzzAnim.Enable( idx, 0.5f );
if( !ViewDispatch( fileName, frame.line, frame.symAddr ) )
{
m_callstackTreeBuzzAnim.Enable( idx, 0.5f );
}
}
}
@ -17799,4 +17865,60 @@ const char* View::SourceSubstitution( const char* srcFile ) const
return res.c_str();
}
void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before, int after, bool separateTooltip )
{
if( !filename ) return;
if( !SourceFileValid( filename, m_worker.GetCaptureTime(), *this, m_worker ) ) return;
m_srcHintCache.Parse( filename, m_worker, *this );
if( m_srcHintCache.empty() ) return;
if( separateTooltip ) ImGui::BeginTooltip();
if( m_fixedFont ) ImGui::PushFont( m_fixedFont );
auto& lines = m_srcHintCache.get();
const int start = std::max( 0, (int)srcline - ( before+1 ) );
const int end = std::min<int>( m_srcHintCache.get().size(), srcline + after );
bool first = true;
int bottomEmpty = 0;
for( int i=start; i<end; i++ )
{
auto& line = lines[i];
if( line.begin == line.end )
{
if( !first ) bottomEmpty++;
}
else
{
first = false;
while( bottomEmpty > 0 )
{
ImGui::TextUnformatted( "" );
bottomEmpty--;
}
auto ptr = line.begin;
auto it = line.tokens.begin();
while( ptr < line.end )
{
if( it == line.tokens.end() )
{
ImGui::TextUnformatted( ptr, line.end );
ImGui::SameLine( 0, 0 );
break;
}
if( ptr < it->begin )
{
ImGui::TextUnformatted( ptr, it->begin );
ImGui::SameLine( 0, 0 );
}
TextColoredUnformatted( i == srcline-1 ? SyntaxColors[(int)it->color] : SyntaxColorsDimmed[(int)it->color], it->begin, it->end );
ImGui::SameLine( 0, 0 );
ptr = it->end;
++it;
}
ImGui::ItemSize( ImVec2( 0, 0 ), 0 );
}
}
if( m_fixedFont ) ImGui::PopFont();
if( separateTooltip ) ImGui::EndTooltip();
}
}

View File

@ -14,6 +14,7 @@
#include "TracyDecayValue.hpp"
#include "TracyImGui.hpp"
#include "TracyShortPtr.hpp"
#include "TracySourceContents.hpp"
#include "TracyTexture.hpp"
#include "TracyUserData.hpp"
#include "TracyVector.hpp"
@ -28,10 +29,8 @@ namespace tracy
{
struct MemoryPage;
struct QueueItem;
class FileRead;
class SourceView;
struct ZoneTimeData;
class View
{
@ -195,6 +194,7 @@ private:
void DrawSampleParents();
void DrawRanges();
void DrawRangeEntry( Range& range, const char* label, uint32_t color, const char* popupLabel, int id );
void DrawSourceTooltip( const char* filename, uint32_t line, int before = 3, int after = 3, bool separateTooltip = true );
void ListMemData( std::vector<const MemEvent*>& vec, std::function<void(const MemEvent*)> DrawAddress, const char* id = nullptr, int64_t startTime = -1, uint64_t pool = 0 );
@ -416,12 +416,14 @@ private:
Vector<const ZoneEvent*> m_zoneInfoStack;
Vector<const GpuEvent*> m_gpuInfoStack;
SourceContents m_srcHintCache;
std::unique_ptr<SourceView> m_sourceView;
const char* m_sourceViewFile;
bool m_uarchSet = false;
ImFont* m_smallFont;
ImFont* m_bigFont;
ImFont* m_fixedFont;
float m_rootWidth, m_rootHeight;
SetTitleCallback m_stcb;