2020-04-01 23:02:42 +00:00
|
|
|
#ifndef __TRACYSOURCEVIEW_HPP__
|
|
|
|
#define __TRACYSOURCEVIEW_HPP__
|
|
|
|
|
2020-05-11 19:12:43 +00:00
|
|
|
#include <limits>
|
2020-03-25 21:37:34 +00:00
|
|
|
#include <string>
|
2020-03-22 19:53:59 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2020-04-04 00:25:12 +00:00
|
|
|
#include "tracy_robin_hood.h"
|
2020-04-26 20:26:17 +00:00
|
|
|
#include "TracyCharUtil.hpp"
|
2020-03-28 00:22:27 +00:00
|
|
|
#include "TracyDecayValue.hpp"
|
2021-03-26 01:21:53 +00:00
|
|
|
#include "TracySourceContents.hpp"
|
2021-03-26 00:53:49 +00:00
|
|
|
#include "TracySourceTokenizer.hpp"
|
2022-07-17 11:41:40 +00:00
|
|
|
#include "../public/common/TracyForceInline.hpp"
|
|
|
|
#include "../public/common/TracyProtocol.hpp"
|
2020-03-28 00:22:27 +00:00
|
|
|
|
2020-03-22 19:53:59 +00:00
|
|
|
struct ImFont;
|
2022-07-02 14:33:45 +00:00
|
|
|
struct ImVec2;
|
2020-03-22 19:53:59 +00:00
|
|
|
|
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2020-04-17 17:09:13 +00:00
|
|
|
class View;
|
2020-03-25 00:09:02 +00:00
|
|
|
class Worker;
|
2022-10-14 15:37:06 +00:00
|
|
|
struct CallstackFrameData;
|
2020-03-25 00:09:02 +00:00
|
|
|
|
2020-03-22 19:53:59 +00:00
|
|
|
class SourceView
|
|
|
|
{
|
2020-05-01 00:39:17 +00:00
|
|
|
public:
|
|
|
|
enum class RegsX86 : uint8_t
|
|
|
|
{
|
2020-05-01 14:14:27 +00:00
|
|
|
invalid, flags,
|
2020-05-01 00:39:17 +00:00
|
|
|
rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15,
|
|
|
|
mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7,
|
|
|
|
xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9,
|
|
|
|
xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm16, xmm17, xmm18, xmm19,
|
|
|
|
xmm20, xmm21, xmm22, xmm23, xmm24, xmm25, xmm26, xmm27, xmm28, xmm29,
|
2020-05-01 11:20:19 +00:00
|
|
|
xmm30, xmm31, k0, k1, k2, k3, k4, k5, k6, k7,
|
|
|
|
NUMBER_OF_ENTRIES
|
2020-05-01 00:39:17 +00:00
|
|
|
};
|
|
|
|
|
2021-06-19 22:45:16 +00:00
|
|
|
enum class CostType
|
|
|
|
{
|
|
|
|
SampleCount,
|
2021-06-20 10:50:13 +00:00
|
|
|
Cycles,
|
2021-06-19 22:45:16 +00:00
|
|
|
SlowBranches,
|
|
|
|
SlowCache,
|
|
|
|
Retirements,
|
|
|
|
BranchesTaken,
|
|
|
|
BranchMiss,
|
|
|
|
CacheAccess,
|
|
|
|
CacheMiss
|
|
|
|
};
|
|
|
|
|
2020-05-01 00:39:17 +00:00
|
|
|
private:
|
2020-04-26 20:26:17 +00:00
|
|
|
struct AsmOpParams
|
|
|
|
{
|
|
|
|
uint8_t type;
|
|
|
|
uint16_t width;
|
|
|
|
};
|
|
|
|
|
2020-04-26 22:49:37 +00:00
|
|
|
enum class LeaData : uint8_t
|
|
|
|
{
|
|
|
|
none,
|
|
|
|
b,
|
|
|
|
bd,
|
|
|
|
bi,
|
|
|
|
bid,
|
|
|
|
d,
|
|
|
|
i,
|
|
|
|
id,
|
|
|
|
r,
|
|
|
|
rd
|
|
|
|
};
|
|
|
|
|
2020-05-01 17:15:46 +00:00
|
|
|
enum { ReadBit = 0x100 };
|
|
|
|
enum { WriteBit = 0x200 };
|
|
|
|
enum { ReuseBit = 0x400 };
|
|
|
|
enum { RegMask = 0x0FF };
|
2020-05-01 22:05:58 +00:00
|
|
|
enum { FlagMask = 0xF00 };
|
2020-05-01 17:15:46 +00:00
|
|
|
|
2022-09-10 22:30:37 +00:00
|
|
|
enum class OpType : uint8_t
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Jump,
|
|
|
|
Branch,
|
|
|
|
Call,
|
|
|
|
Ret,
|
|
|
|
Privileged
|
|
|
|
};
|
|
|
|
|
2020-03-25 21:37:34 +00:00
|
|
|
struct AsmLine
|
|
|
|
{
|
|
|
|
uint64_t addr;
|
2020-03-27 23:53:48 +00:00
|
|
|
uint64_t jumpAddr;
|
2020-03-25 21:37:34 +00:00
|
|
|
std::string mnemonic;
|
|
|
|
std::string operands;
|
2020-04-19 13:54:43 +00:00
|
|
|
uint8_t len;
|
2020-04-26 22:49:37 +00:00
|
|
|
LeaData leaData;
|
2022-09-10 22:30:37 +00:00
|
|
|
OpType opType;
|
2020-05-01 18:09:21 +00:00
|
|
|
bool jumpConditional;
|
2020-04-26 20:26:17 +00:00
|
|
|
std::vector<AsmOpParams> params;
|
2022-09-15 22:30:29 +00:00
|
|
|
std::vector<Tokenizer::AsmToken> opTokens;
|
2020-05-01 11:01:19 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
RegsX86 readX86[12];
|
|
|
|
};
|
|
|
|
union
|
|
|
|
{
|
|
|
|
RegsX86 writeX86[20];
|
|
|
|
};
|
2020-05-01 14:33:09 +00:00
|
|
|
uint16_t regData[20];
|
2020-03-25 21:37:34 +00:00
|
|
|
};
|
|
|
|
|
2020-05-01 11:01:19 +00:00
|
|
|
enum { AsmLineSize = sizeof( AsmLine ) };
|
|
|
|
|
2020-04-04 00:25:12 +00:00
|
|
|
struct JumpData
|
|
|
|
{
|
|
|
|
uint64_t min;
|
|
|
|
uint64_t max;
|
2020-10-02 17:30:01 +00:00
|
|
|
size_t level;
|
2020-04-04 00:25:12 +00:00
|
|
|
std::vector<uint64_t> source;
|
|
|
|
};
|
|
|
|
|
2020-04-08 20:04:00 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DisplaySource,
|
|
|
|
DisplayAsm,
|
|
|
|
DisplayMixed
|
|
|
|
};
|
|
|
|
|
2021-04-09 19:21:57 +00:00
|
|
|
struct AddrStat
|
|
|
|
{
|
2021-06-19 22:08:25 +00:00
|
|
|
uint64_t local;
|
|
|
|
uint64_t ext;
|
2021-04-18 17:40:43 +00:00
|
|
|
|
|
|
|
AddrStat& operator+=( const AddrStat& other )
|
|
|
|
{
|
|
|
|
local += other.local;
|
|
|
|
ext += other.ext;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-09 19:21:57 +00:00
|
|
|
};
|
|
|
|
|
2021-07-18 12:36:44 +00:00
|
|
|
struct AddrStatData
|
|
|
|
{
|
|
|
|
AddrStat ipTotalSrc = {};
|
|
|
|
AddrStat ipTotalAsm = {};
|
|
|
|
AddrStat ipMaxSrc = {};
|
|
|
|
AddrStat ipMaxAsm = {};
|
2021-07-18 12:57:26 +00:00
|
|
|
AddrStat hwMaxSrc = {};
|
|
|
|
AddrStat hwMaxAsm = {};
|
2021-07-18 12:36:44 +00:00
|
|
|
unordered_flat_map<uint64_t, AddrStat> ipCountSrc, ipCountAsm;
|
2021-07-18 12:57:26 +00:00
|
|
|
unordered_flat_map<uint64_t, AddrStat> hwCountSrc, hwCountAsm;
|
2021-07-18 12:36:44 +00:00
|
|
|
};
|
|
|
|
|
2020-03-22 19:53:59 +00:00
|
|
|
public:
|
2022-08-12 19:44:24 +00:00
|
|
|
SourceView();
|
2020-03-22 19:53:59 +00:00
|
|
|
|
2022-08-15 20:48:00 +00:00
|
|
|
void UpdateFont( ImFont* fixed, ImFont* small, ImFont* big ) { m_font = fixed; m_smallFont = small; m_bigFont = big; }
|
2020-05-06 22:53:31 +00:00
|
|
|
void SetCpuId( uint32_t cpuid );
|
|
|
|
|
2020-05-23 13:14:57 +00:00
|
|
|
void OpenSource( const char* fileName, int line, const View& view, const Worker& worker );
|
2021-11-14 12:05:05 +00:00
|
|
|
void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, Worker& worker, const View& view );
|
2021-06-04 11:58:00 +00:00
|
|
|
void Render( Worker& worker, View& view );
|
2020-03-22 19:53:59 +00:00
|
|
|
|
2020-04-09 20:37:49 +00:00
|
|
|
void CalcInlineStats( bool val ) { m_calcInlineStats = val; }
|
2020-08-10 17:03:23 +00:00
|
|
|
bool IsSymbolView() const { return !m_asm.empty(); }
|
2020-04-09 20:37:49 +00:00
|
|
|
|
2020-03-22 19:53:59 +00:00
|
|
|
private:
|
2020-05-23 13:14:57 +00:00
|
|
|
void ParseSource( const char* fileName, const Worker& worker, const View& view );
|
2020-04-08 00:11:58 +00:00
|
|
|
bool Disassemble( uint64_t symAddr, const Worker& worker );
|
|
|
|
|
2020-08-12 17:05:02 +00:00
|
|
|
void SelectViewMode();
|
|
|
|
|
2020-04-07 23:58:23 +00:00
|
|
|
void RenderSimpleSourceView();
|
2021-06-04 11:58:00 +00:00
|
|
|
void RenderSymbolView( Worker& worker, View& view );
|
2020-04-07 23:58:23 +00:00
|
|
|
|
2021-07-18 12:36:44 +00:00
|
|
|
void RenderSymbolSourceView( const AddrStatData& as, Worker& worker, const View& view );
|
|
|
|
uint64_t RenderSymbolAsmView( const AddrStatData& as, Worker& worker, View& view );
|
2020-04-08 20:04:00 +00:00
|
|
|
|
2021-07-18 12:36:44 +00:00
|
|
|
void RenderLine( const Tokenizer::Line& line, int lineNum, const AddrStat& ipcnt, const AddrStatData& as, Worker* worker, const View* view );
|
2022-09-21 18:39:35 +00:00
|
|
|
void RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const AddrStatData& as, Worker& worker, uint64_t& jumpOut, int maxAddrLen, int maxAddrLenRel, View& view );
|
2021-07-18 13:35:31 +00:00
|
|
|
void RenderHwLinePart( size_t cycles, size_t retired, size_t branchRetired, size_t branchMiss, size_t cacheRef, size_t cacheMiss, size_t branchRel, size_t branchRelMax, size_t cacheRel, size_t cacheRelMax, const ImVec2& ts );
|
2020-03-25 21:53:05 +00:00
|
|
|
|
2021-11-13 16:35:02 +00:00
|
|
|
void SelectLine( uint32_t line, const Worker* worker, bool updateAsmLine = true, uint64_t targetAddr = 0, bool changeAsmLine = true );
|
|
|
|
void SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool updateAsmLine = true, uint64_t targetAddr = 0, bool changeAsmLine = true );
|
2020-04-09 19:57:28 +00:00
|
|
|
void SelectAsmLinesHover( uint32_t file, uint32_t line, const Worker& worker );
|
2020-04-08 20:57:42 +00:00
|
|
|
|
2021-07-18 12:36:44 +00:00
|
|
|
void GatherIpHwStats( AddrStatData& as, Worker& worker, const View& view, CostType cost );
|
|
|
|
void GatherIpStats( uint64_t baseAddr, AddrStatData& as, const Worker& worker, bool limitView, const View& view );
|
|
|
|
void GatherAdditionalIpStats( uint64_t baseAddr, AddrStatData& as, const Worker& worker, bool limitView, const View& view );
|
2021-11-27 13:42:23 +00:00
|
|
|
void GatherChildStats( uint64_t baseAddr, unordered_flat_map<uint64_t, uint32_t>& vec, Worker& worker, bool limitView, const View& view );
|
|
|
|
|
2021-04-18 18:27:47 +00:00
|
|
|
uint32_t CountAsmIpStats( uint64_t baseAddr, const Worker& worker, bool limitView, const View& view );
|
2021-07-18 12:57:26 +00:00
|
|
|
void CountHwStats( AddrStatData& as, Worker& worker, const View& view );
|
2020-04-09 20:23:57 +00:00
|
|
|
|
2020-04-26 20:26:17 +00:00
|
|
|
void SelectMicroArchitecture( const char* moniker );
|
|
|
|
|
2020-05-01 14:33:09 +00:00
|
|
|
void ResetAsm();
|
2020-10-02 17:30:01 +00:00
|
|
|
void FollowRead( size_t line, RegsX86 reg, size_t limit );
|
|
|
|
void FollowWrite( size_t line, RegsX86 reg, size_t limit );
|
|
|
|
void CheckRead( size_t line, RegsX86 reg, size_t limit );
|
|
|
|
void CheckWrite( size_t line, RegsX86 reg, size_t limit );
|
2020-05-01 14:33:09 +00:00
|
|
|
|
2021-11-13 15:15:09 +00:00
|
|
|
bool IsInContext( const Worker& worker, uint64_t addr ) const;
|
2022-10-14 22:27:54 +00:00
|
|
|
const std::vector<uint64_t>* GetAddressesForLocation( uint32_t fileStringIdx, uint32_t line, const Worker& worker );
|
2021-11-13 15:15:09 +00:00
|
|
|
|
2022-10-18 22:59:46 +00:00
|
|
|
tracy_force_inline float CalcJumpSeparation( float scale );
|
|
|
|
|
2020-05-11 20:13:07 +00:00
|
|
|
#ifndef TRACY_NO_FILESELECTOR
|
2020-05-11 19:12:43 +00:00
|
|
|
void Save( const Worker& worker, size_t start = 0, size_t stop = std::numeric_limits<size_t>::max() );
|
2020-05-11 20:13:07 +00:00
|
|
|
#endif
|
2020-05-11 19:08:50 +00:00
|
|
|
|
2021-11-19 20:06:07 +00:00
|
|
|
tracy_force_inline void SetFont();
|
|
|
|
tracy_force_inline void UnsetFont();
|
|
|
|
|
2020-03-22 19:53:59 +00:00
|
|
|
ImFont* m_font;
|
2021-11-20 13:47:13 +00:00
|
|
|
ImFont* m_smallFont;
|
2022-08-15 20:48:00 +00:00
|
|
|
ImFont* m_bigFont;
|
2020-03-24 23:07:31 +00:00
|
|
|
uint64_t m_symAddr;
|
2020-03-27 23:57:41 +00:00
|
|
|
uint64_t m_baseAddr;
|
2020-03-25 21:53:05 +00:00
|
|
|
uint64_t m_targetAddr;
|
2020-03-22 19:53:59 +00:00
|
|
|
int m_targetLine;
|
|
|
|
int m_selectedLine;
|
2020-05-01 14:33:24 +00:00
|
|
|
int m_asmSelected;
|
2020-04-09 20:02:06 +00:00
|
|
|
DecayValue<int> m_hoveredLine;
|
|
|
|
DecayValue<uint32_t> m_hoveredSource;
|
2020-04-08 20:04:00 +00:00
|
|
|
int m_displayMode;
|
2020-03-26 01:23:09 +00:00
|
|
|
uint32_t m_codeLen;
|
2020-04-19 12:40:36 +00:00
|
|
|
int32_t m_disasmFail;
|
2020-03-28 00:22:27 +00:00
|
|
|
DecayValue<uint64_t> m_highlightAddr;
|
2020-05-11 11:35:49 +00:00
|
|
|
int m_asmCountBase;
|
2020-03-28 13:33:35 +00:00
|
|
|
bool m_asmRelative;
|
2020-04-19 14:06:45 +00:00
|
|
|
bool m_asmBytes;
|
2020-04-01 23:37:56 +00:00
|
|
|
bool m_asmShowSourceLocation;
|
2020-04-09 20:23:57 +00:00
|
|
|
bool m_calcInlineStats;
|
2020-04-19 14:06:45 +00:00
|
|
|
uint8_t m_maxAsmBytes;
|
2020-05-09 10:58:09 +00:00
|
|
|
bool m_atnt;
|
2020-05-11 19:59:45 +00:00
|
|
|
uint64_t m_jumpPopupAddr;
|
2022-10-14 15:37:06 +00:00
|
|
|
const CallstackFrameData* m_localCallstackPopup;
|
2021-07-14 23:44:52 +00:00
|
|
|
bool m_hwSamples, m_hwSamplesRelative;
|
2021-04-09 19:22:25 +00:00
|
|
|
bool m_childCalls;
|
2021-11-27 13:43:31 +00:00
|
|
|
bool m_childCallList;
|
2022-10-09 18:52:14 +00:00
|
|
|
bool m_propagateInlines;
|
2021-06-19 22:37:55 +00:00
|
|
|
CostType m_cost;
|
2020-03-22 19:53:59 +00:00
|
|
|
|
2021-03-26 01:21:53 +00:00
|
|
|
SourceContents m_source;
|
2021-03-26 01:41:30 +00:00
|
|
|
SourceContents m_sourceTooltip;
|
2020-03-25 21:37:34 +00:00
|
|
|
std::vector<AsmLine> m_asm;
|
2020-04-04 00:25:12 +00:00
|
|
|
|
2020-05-09 12:58:06 +00:00
|
|
|
unordered_flat_map<uint64_t, uint32_t> m_locMap;
|
2020-04-04 00:25:12 +00:00
|
|
|
unordered_flat_map<uint64_t, JumpData> m_jumpTable;
|
2020-04-04 11:51:55 +00:00
|
|
|
unordered_flat_set<uint64_t> m_jumpOut;
|
2020-10-02 17:30:01 +00:00
|
|
|
size_t m_maxJumpLevel;
|
2020-04-04 01:34:54 +00:00
|
|
|
bool m_showJumps;
|
2020-04-08 20:18:00 +00:00
|
|
|
|
2022-10-11 21:59:07 +00:00
|
|
|
unordered_flat_map<uint64_t, std::vector<uint64_t>> m_locationAddress;
|
2022-10-14 22:27:54 +00:00
|
|
|
bool m_locAddrIsProp;
|
2022-10-11 21:59:07 +00:00
|
|
|
|
2020-04-08 20:25:36 +00:00
|
|
|
unordered_flat_map<uint32_t, uint32_t> m_sourceFiles;
|
2020-04-08 20:57:42 +00:00
|
|
|
unordered_flat_set<uint64_t> m_selectedAddresses;
|
2020-04-09 19:57:28 +00:00
|
|
|
unordered_flat_set<uint64_t> m_selectedAddressesHover;
|
2020-04-08 23:45:38 +00:00
|
|
|
|
2020-04-08 23:52:22 +00:00
|
|
|
uint32_t m_maxLine;
|
2020-04-08 23:45:38 +00:00
|
|
|
int m_maxMnemonicLen;
|
2020-04-24 21:48:18 +00:00
|
|
|
|
2020-04-26 20:26:17 +00:00
|
|
|
unordered_flat_map<const char*, int, charutil::Hasher, charutil::Comparator> m_microArchOpMap;
|
2020-04-26 12:23:16 +00:00
|
|
|
CpuArchitecture m_cpuArch;
|
2020-04-26 12:52:18 +00:00
|
|
|
int m_selMicroArch;
|
2020-11-13 16:37:53 +00:00
|
|
|
int m_idxMicroArch, m_profileMicroArch;
|
2020-04-27 14:10:47 +00:00
|
|
|
bool m_showLatency;
|
2020-05-07 00:33:37 +00:00
|
|
|
|
|
|
|
unordered_flat_set<uint32_t> m_asmSampleSelect;
|
|
|
|
unordered_flat_set<uint32_t> m_srcSampleSelect;
|
2020-10-02 17:30:01 +00:00
|
|
|
int32_t m_asmGroupSelect = -1;
|
|
|
|
int32_t m_srcGroupSelect = -1;
|
2020-06-06 10:31:47 +00:00
|
|
|
|
|
|
|
float m_srcWidth;
|
|
|
|
float m_asmWidth;
|
2021-12-29 12:41:55 +00:00
|
|
|
float m_jumpOffset;
|
2020-06-09 23:52:17 +00:00
|
|
|
|
2021-03-26 00:53:49 +00:00
|
|
|
Tokenizer m_tokenizer;
|
2021-07-25 23:21:58 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32_t file = 0;
|
|
|
|
uint32_t line = 0;
|
|
|
|
size_t sel;
|
|
|
|
std::vector<uint64_t> target;
|
|
|
|
} m_asmTarget;
|
2020-03-22 19:53:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2020-04-01 23:02:42 +00:00
|
|
|
|
|
|
|
#endif
|