mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 12:23:53 +00:00
Query source location of each assembly instruction.
This commit is contained in:
parent
0ba0125eb5
commit
b2a8b53efa
@ -1,8 +1,8 @@
|
|||||||
CFLAGS +=
|
CFLAGS +=
|
||||||
CXXFLAGS := $(CFLAGS) -std=gnu++17
|
CXXFLAGS := $(CFLAGS) -std=gnu++17
|
||||||
DEFINES += -DTRACY_NO_STATISTICS
|
DEFINES += -DTRACY_NO_STATISTICS
|
||||||
INCLUDES :=
|
INCLUDES := $(shell pkg-config --cflags capstone)
|
||||||
LIBS := -lpthread
|
LIBS := $(shell pkg-config --libs capstone) -lpthread
|
||||||
PROJECT := capture
|
PROJECT := capture
|
||||||
IMAGE := $(PROJECT)-$(BUILD)
|
IMAGE := $(PROJECT)-$(BUILD)
|
||||||
|
|
||||||
|
@ -2373,6 +2373,9 @@ bool Profiler::HandleServerQuery()
|
|||||||
case ServerQuerySymbolCode:
|
case ServerQuerySymbolCode:
|
||||||
HandleSymbolCodeQuery( ptr, extra );
|
HandleSymbolCodeQuery( ptr, extra );
|
||||||
break;
|
break;
|
||||||
|
case ServerQueryCodeLocation:
|
||||||
|
SendCodeLocation( ptr );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert( false );
|
assert( false );
|
||||||
break;
|
break;
|
||||||
@ -2773,6 +2776,25 @@ void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size )
|
|||||||
SendLongString( symbol, (const char*)symbol, size, QueueType::SymbolCode );
|
SendLongString( symbol, (const char*)symbol, size, QueueType::SymbolCode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Profiler::SendCodeLocation( uint64_t ptr )
|
||||||
|
{
|
||||||
|
#ifdef TRACY_HAS_CALLSTACK
|
||||||
|
const auto sym = DecodeCodeAddress( ptr );
|
||||||
|
|
||||||
|
SendString( uint64_t( sym.file ), sym.file, QueueType::CustomStringData );
|
||||||
|
|
||||||
|
QueueItem item;
|
||||||
|
MemWrite( &item.hdr.type, QueueType::CodeInformation );
|
||||||
|
MemWrite( &item.codeInformation.ptr, ptr );
|
||||||
|
MemWrite( &item.codeInformation.file, uint64_t( sym.file ) );
|
||||||
|
MemWrite( &item.codeInformation.line, sym.line );
|
||||||
|
|
||||||
|
AppendData( &item, QueueDataSize[(int)QueueType::CodeInformation] );
|
||||||
|
|
||||||
|
if( sym.needFree ) tracy_free( (void*)sym.file );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -553,6 +553,7 @@ private:
|
|||||||
void SendCallstackPayload64( uint64_t ptr );
|
void SendCallstackPayload64( uint64_t ptr );
|
||||||
void SendCallstackAlloc( uint64_t ptr );
|
void SendCallstackAlloc( uint64_t ptr );
|
||||||
void SendCallstackFrame( uint64_t ptr );
|
void SendCallstackFrame( uint64_t ptr );
|
||||||
|
void SendCodeLocation( uint64_t ptr );
|
||||||
|
|
||||||
bool HandleServerQuery();
|
bool HandleServerQuery();
|
||||||
void HandleDisconnect();
|
void HandleDisconnect();
|
||||||
|
@ -9,7 +9,7 @@ namespace tracy
|
|||||||
|
|
||||||
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
||||||
|
|
||||||
enum : uint32_t { ProtocolVersion = 29 };
|
enum : uint32_t { ProtocolVersion = 30 };
|
||||||
enum : uint32_t { BroadcastVersion = 1 };
|
enum : uint32_t { BroadcastVersion = 1 };
|
||||||
|
|
||||||
using lz4sz_t = uint32_t;
|
using lz4sz_t = uint32_t;
|
||||||
@ -50,7 +50,8 @@ enum ServerQuery : uint8_t
|
|||||||
ServerQueryExternalName,
|
ServerQueryExternalName,
|
||||||
ServerQueryParameter,
|
ServerQueryParameter,
|
||||||
ServerQuerySymbol,
|
ServerQuerySymbol,
|
||||||
ServerQuerySymbolCode
|
ServerQuerySymbolCode,
|
||||||
|
ServerQueryCodeLocation
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ServerQueryPacket
|
struct ServerQueryPacket
|
||||||
|
@ -21,7 +21,6 @@ enum class QueueType : uint8_t
|
|||||||
Callstack,
|
Callstack,
|
||||||
CallstackAlloc,
|
CallstackAlloc,
|
||||||
CallstackSample,
|
CallstackSample,
|
||||||
SymbolInformation,
|
|
||||||
FrameImage,
|
FrameImage,
|
||||||
ZoneBegin,
|
ZoneBegin,
|
||||||
ZoneBeginCallstack,
|
ZoneBeginCallstack,
|
||||||
@ -67,6 +66,8 @@ enum class QueueType : uint8_t
|
|||||||
GpuNewContext,
|
GpuNewContext,
|
||||||
CallstackFrameSize,
|
CallstackFrameSize,
|
||||||
CallstackFrame,
|
CallstackFrame,
|
||||||
|
SymbolInformation,
|
||||||
|
CodeInformation,
|
||||||
SysTimeReport,
|
SysTimeReport,
|
||||||
TidToPid,
|
TidToPid,
|
||||||
PlotConfig,
|
PlotConfig,
|
||||||
@ -331,6 +332,13 @@ struct QueueSymbolInformation
|
|||||||
uint64_t symAddr;
|
uint64_t symAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct QueueCodeInformation
|
||||||
|
{
|
||||||
|
uint64_t ptr;
|
||||||
|
uint64_t file;
|
||||||
|
uint32_t line;
|
||||||
|
};
|
||||||
|
|
||||||
struct QueueCrashReport
|
struct QueueCrashReport
|
||||||
{
|
{
|
||||||
int64_t time;
|
int64_t time;
|
||||||
@ -439,6 +447,7 @@ struct QueueItem
|
|||||||
QueueCallstackFrameSize callstackFrameSize;
|
QueueCallstackFrameSize callstackFrameSize;
|
||||||
QueueCallstackFrame callstackFrame;
|
QueueCallstackFrame callstackFrame;
|
||||||
QueueSymbolInformation symbolInformation;
|
QueueSymbolInformation symbolInformation;
|
||||||
|
QueueCodeInformation codeInformation;
|
||||||
QueueCrashReport crashReport;
|
QueueCrashReport crashReport;
|
||||||
QueueSysTime sysTime;
|
QueueSysTime sysTime;
|
||||||
QueueContextSwitch contextSwitch;
|
QueueContextSwitch contextSwitch;
|
||||||
@ -468,7 +477,6 @@ static constexpr size_t QueueDataSize[] = {
|
|||||||
sizeof( QueueHeader ) + sizeof( QueueCallstack ),
|
sizeof( QueueHeader ) + sizeof( QueueCallstack ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueCallstackAlloc ),
|
sizeof( QueueHeader ) + sizeof( QueueCallstackAlloc ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueCallstackSample ),
|
sizeof( QueueHeader ) + sizeof( QueueCallstackSample ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueSymbolInformation ),
|
|
||||||
sizeof( QueueHeader ) + sizeof( QueueFrameImage ),
|
sizeof( QueueHeader ) + sizeof( QueueFrameImage ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),
|
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // callstack
|
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // callstack
|
||||||
@ -515,6 +523,8 @@ static constexpr size_t QueueDataSize[] = {
|
|||||||
sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ),
|
sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ),
|
sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueCallstackFrame ),
|
sizeof( QueueHeader ) + sizeof( QueueCallstackFrame ),
|
||||||
|
sizeof( QueueHeader ) + sizeof( QueueSymbolInformation ),
|
||||||
|
sizeof( QueueHeader ) + sizeof( QueueCodeInformation ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
|
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
|
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueuePlotConfig ),
|
sizeof( QueueHeader ) + sizeof( QueuePlotConfig ),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
CFLAGS +=
|
CFLAGS +=
|
||||||
CXXFLAGS := $(CFLAGS) -std=gnu++17
|
CXXFLAGS := $(CFLAGS) -std=gnu++17
|
||||||
DEFINES += -DTRACY_NO_STATISTICS
|
DEFINES += -DTRACY_NO_STATISTICS
|
||||||
INCLUDES :=
|
INCLUDES := $(shell pkg-config --cflags capstone)
|
||||||
LIBS := -lpthread
|
LIBS := $(shell pkg-config --libs capstone) -lpthread
|
||||||
PROJECT := import-chrome
|
PROJECT := import-chrome
|
||||||
IMAGE := $(PROJECT)-$(BUILD)
|
IMAGE := $(PROJECT)-$(BUILD)
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include <capstone/capstone.h>
|
||||||
|
|
||||||
#include "../common/TracyProtocol.hpp"
|
#include "../common/TracyProtocol.hpp"
|
||||||
#include "../common/TracySystem.hpp"
|
#include "../common/TracySystem.hpp"
|
||||||
#include "TracyFileRead.hpp"
|
#include "TracyFileRead.hpp"
|
||||||
@ -3559,6 +3561,40 @@ void Worker::AddSymbolCode( uint64_t ptr, const char* data, size_t sz )
|
|||||||
memcpy( code, data, sz );
|
memcpy( code, data, sz );
|
||||||
m_data.symbolCode.emplace( ptr, SymbolCodeData{ code, uint32_t( sz ) } );
|
m_data.symbolCode.emplace( ptr, SymbolCodeData{ code, uint32_t( sz ) } );
|
||||||
m_data.symbolCodeSize += sz;
|
m_data.symbolCodeSize += sz;
|
||||||
|
|
||||||
|
if( m_data.cpuArch == CpuArchUnknown ) return;
|
||||||
|
csh handle;
|
||||||
|
cs_err rval = CS_ERR_ARCH;
|
||||||
|
switch( m_data.cpuArch )
|
||||||
|
{
|
||||||
|
case CpuArchX86:
|
||||||
|
rval = cs_open( CS_ARCH_X86, CS_MODE_32, &handle );
|
||||||
|
break;
|
||||||
|
case CpuArchX64:
|
||||||
|
rval = cs_open( CS_ARCH_X86, CS_MODE_64, &handle );
|
||||||
|
break;
|
||||||
|
case CpuArchArm32:
|
||||||
|
rval = cs_open( CS_ARCH_ARM, CS_MODE_ARM, &handle );
|
||||||
|
break;
|
||||||
|
case CpuArchArm64:
|
||||||
|
rval = cs_open( CS_ARCH_ARM64, CS_MODE_ARM, &handle );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert( false );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( rval != CS_ERR_OK ) return;
|
||||||
|
cs_insn* insn;
|
||||||
|
size_t cnt = cs_disasm( handle, (const uint8_t*)code, sz, ptr, 0, &insn );
|
||||||
|
if( cnt > 0 )
|
||||||
|
{
|
||||||
|
for( size_t i=0; i<cnt; i++ )
|
||||||
|
{
|
||||||
|
Query( ServerQueryCodeLocation, insn[i].address );
|
||||||
|
}
|
||||||
|
cs_free( insn, cnt );
|
||||||
|
}
|
||||||
|
cs_close( &handle );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Worker::GetCanonicalPointer( const CallstackFrameId& id ) const
|
uint64_t Worker::GetCanonicalPointer( const CallstackFrameId& id ) const
|
||||||
@ -3987,6 +4023,10 @@ bool Worker::Process( const QueueItem& ev )
|
|||||||
ProcessSymbolInformation( ev.symbolInformation );
|
ProcessSymbolInformation( ev.symbolInformation );
|
||||||
m_serverQuerySpaceLeft++;
|
m_serverQuerySpaceLeft++;
|
||||||
break;
|
break;
|
||||||
|
case QueueType::CodeInformation:
|
||||||
|
// TODO
|
||||||
|
m_serverQuerySpaceLeft++;
|
||||||
|
break;
|
||||||
case QueueType::Terminate:
|
case QueueType::Terminate:
|
||||||
m_terminate = true;
|
m_terminate = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
CFLAGS +=
|
CFLAGS +=
|
||||||
CXXFLAGS := $(CFLAGS) -std=gnu++17
|
CXXFLAGS := $(CFLAGS) -std=gnu++17
|
||||||
DEFINES += -DTRACY_NO_STATISTICS
|
DEFINES += -DTRACY_NO_STATISTICS
|
||||||
INCLUDES :=
|
INCLUDES := $(shell pkg-config --cflags capstone)
|
||||||
LIBS := -lpthread
|
LIBS := $(shell pkg-config --libs capstone) -lpthread
|
||||||
PROJECT := update
|
PROJECT := update
|
||||||
IMAGE := $(PROJECT)-$(BUILD)
|
IMAGE := $(PROJECT)-$(BUILD)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user