From 5da60b53d0d6391c28b18e9a83fa38842d28ef56 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 26 Apr 2020 22:26:17 +0200 Subject: [PATCH] Add micro architecture tooltips. --- server/TracySourceView.cpp | 240 ++++++++++++++++++++++++++++++++++++- server/TracySourceView.hpp | 12 ++ 2 files changed, 249 insertions(+), 3 deletions(-) diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 167c3bb1..e16321d0 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -9,6 +9,7 @@ #include "TracyColor.hpp" #include "TracyFilesystem.hpp" #include "TracyImGui.hpp" +#include "TracyMicroArchitecture.hpp" #include "TracyPrint.hpp" #include "TracySort.hpp" #include "TracySourceView.hpp" @@ -70,8 +71,14 @@ SourceView::SourceView( ImFont* font ) , m_calcInlineStats( true ) , m_showJumps( true ) , m_cpuArch( CpuArchUnknown ) - , m_selMicroArch( sizeof( s_uArchUx ) / sizeof( *s_uArchUx ) - 1 ) { + SelectMicroArchitecture( "ZEN2" ); + + m_microArchOpMap.reserve( OpsNum ); + for( int i=0; i params; + switch( m_cpuArch ) + { + case CpuArchX86: + case CpuArchX64: + for( uint8_t i=0; i mLenMax ) mLenMax = mLen; if( op.size > bytesMax ) bytesMax = op.size; @@ -1061,7 +1142,7 @@ uint64_t SourceView::RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map= 'a' && c <= 'z' ) c = c - 'a' + 'A'; + tmp[i] = c; + } + tmp[line.mnemonic.size()] = '\0'; + auto it = m_microArchOpMap.find( tmp ); + if( it != m_microArchOpMap.end() ) + { + const auto opid = it->second; + auto oit = std::lower_bound( uarch->ops, uarch->ops + uarch->numOps, opid, []( const auto& l, const auto& r ) { return l->id < r; } ); + if( oit != uarch->ops + uarch->numOps && (*oit)->id == opid ) + { + int selVar = -1; + const auto& op = *oit; + for( int i=0; inumVariants; i++ ) + { + const auto& var = *op->variant[i]; + if( var.descNum == line.params.size() ) + { + bool match = true; + for( int j=0; jvariant[selVar]; + if( m_font ) ImGui::PopFont(); + ImGui::BeginTooltip(); + TextFocused( "Throughput:", RealToString( var.tp ) ); + ImGui::SameLine(); + TextDisabledUnformatted( "(cycles per instruction, lower is better)" ); + if( var.maxlat >= 0 ) + { + TextDisabledUnformatted( "Latency:" ); + ImGui::SameLine(); + if( var.minlat == var.maxlat && var.minbound == var.maxbound ) + { + if( var.minbound ) + { + ImGui::Text( "\xe2\x89\xa4%s", RealToString( var.minlat ) ); + } + else + { + ImGui::TextUnformatted( RealToString( var.minlat ) ); + } + } + else + { + if( var.minbound ) + { + ImGui::Text( "[\xe2\x89\xa4%s", RealToString( var.minlat ) ); + } + else + { + ImGui::Text( "[%s", RealToString( var.minlat ) ); + } + ImGui::SameLine( 0, 0 ); + if( var.maxbound ) + { + ImGui::Text( " \xE2\x80\x93 \xe2\x89\xa4%s]", RealToString( var.maxlat ) ); + } + else + { + ImGui::Text( " \xE2\x80\x93 %s]", RealToString( var.maxlat ) ); + } + } + ImGui::SameLine(); + TextDisabledUnformatted( "(cycles in execution, may vary by used output)" ); + } + TextFocused( "\xce\xbcops:", RealToString( var.uops ) ); + if( var.port != -1 ) TextFocused( "Ports:", PortList[var.port] ); + ImGui::Separator(); + TextFocused( "ISA set:", IsaList[var.isaSet] ); + TextDisabledUnformatted( "Operands:" ); + ImGui::SameLine(); + bool first = true; + for( auto& v : line.params ) + { + char t = '?'; + switch( v.type ) + { + case 0: + t = 'I'; + break; + case 1: + t = 'R'; + break; + case 2: + t = 'M'; + break; + default: + assert( false ); + break; + } + if( first ) + { + first = false; + ImGui::Text( "%c%i", t, v.width ); + } + else + { + ImGui::SameLine( 0, 0 ); + ImGui::Text( ", %c%i", t, v.width ); + } + } + ImGui::EndTooltip(); + if( m_font ) ImGui::PushFont( m_font ); + } + } + } + } if( line.jumpAddr != 0 ) { @@ -2096,4 +2307,27 @@ std::vector SourceView::Tokenize( const char* begin, const ch return ret; } +void SourceView::SelectMicroArchitecture( const char* moniker ) +{ + int idx = 0; + for( auto& v : s_uArchUx ) + { + if( strcmp( v.moniker, moniker ) == 0 ) + { + m_selMicroArch = idx; + break; + } + idx++; + } + for( idx=0; idx #include "tracy_robin_hood.h" +#include "TracyCharUtil.hpp" #include "TracyDecayValue.hpp" #include "../common/TracyProtocol.hpp" @@ -46,6 +47,12 @@ class SourceView std::vector tokens; }; + struct AsmOpParams + { + uint8_t type; + uint16_t width; + }; + struct AsmLine { uint64_t addr; @@ -53,6 +60,7 @@ class SourceView std::string mnemonic; std::string operands; uint8_t len; + std::vector params; }; struct JumpData @@ -99,6 +107,8 @@ private: void GatherIpStats( uint64_t addr, uint32_t& iptotalSrc, uint32_t& iptotalAsm, unordered_flat_map& ipcountSrc, unordered_flat_map& ipcountAsm, uint32_t& ipmaxSrc, uint32_t& ipmaxAsm, const Worker& worker ); + void SelectMicroArchitecture( const char* moniker ); + TokenColor IdentifyToken( const char*& begin, const char* end ); std::vector Tokenize( const char* begin, const char* end ); @@ -153,8 +163,10 @@ private: TokenizerState m_tokenizer; + unordered_flat_map m_microArchOpMap; CpuArchitecture m_cpuArch; int m_selMicroArch; + int m_idxMicroArch; }; }