mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Implement retrieval of external process names.
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
#include "TracyProfiler.hpp"
|
||||
#include "TracyThread.hpp"
|
||||
#include "TracyArmCpuTable.hpp"
|
||||
#include "TracySysTrace.hpp"
|
||||
#include "../TracyC.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
@@ -1851,7 +1852,7 @@ bool Profiler::SendData( const char* data, size_t len )
|
||||
|
||||
void Profiler::SendString( uint64_t str, const char* ptr, QueueType type )
|
||||
{
|
||||
assert( type == QueueType::StringData || type == QueueType::ThreadName || type == QueueType::CustomStringData || type == QueueType::PlotName || type == QueueType::FrameName );
|
||||
assert( type == QueueType::StringData || type == QueueType::ThreadName || type == QueueType::CustomStringData || type == QueueType::PlotName || type == QueueType::FrameName || type == QueueType::ExternalName );
|
||||
|
||||
QueueItem item;
|
||||
MemWrite( &item.hdr.type, type );
|
||||
@@ -2050,6 +2051,9 @@ bool Profiler::HandleServerQuery()
|
||||
case ServerQueryDisconnect:
|
||||
HandleDisconnect();
|
||||
return false;
|
||||
case ServerQueryExternalName:
|
||||
SysTraceSendExternalName( ptr );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
|
||||
@@ -442,6 +442,8 @@ public:
|
||||
void RequestShutdown() { m_shutdown.store( true, std::memory_order_relaxed ); m_shutdownManual.store( true, std::memory_order_relaxed ); }
|
||||
bool HasShutdownFinished() const { return m_shutdownFinished.load( std::memory_order_relaxed ); }
|
||||
|
||||
void SendString( uint64_t ptr, const char* str, QueueType type );
|
||||
|
||||
private:
|
||||
enum class DequeueStatus { Success, ConnectionLost, QueueEmpty };
|
||||
|
||||
@@ -467,7 +469,6 @@ private:
|
||||
}
|
||||
|
||||
bool SendData( const char* data, size_t len );
|
||||
void SendString( uint64_t ptr, const char* str, QueueType type );
|
||||
void SendLongString( uint64_t ptr, const char* str, size_t len, QueueType type );
|
||||
void SendSourceLocation( uint64_t ptr );
|
||||
void SendSourceLocationPayload( uint64_t ptr );
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
# define INITGUID
|
||||
# include <assert.h>
|
||||
# include <stdint.h>
|
||||
# include <string.h>
|
||||
# include <windows.h>
|
||||
# include <evntrace.h>
|
||||
# include <evntcons.h>
|
||||
# include <psapi.h>
|
||||
|
||||
# include "../common/TracyAlloc.hpp"
|
||||
# include "../common/TracySystem.hpp"
|
||||
@@ -156,6 +156,36 @@ void SysTraceWorker( void* ptr )
|
||||
tracy_free( s_prop );
|
||||
}
|
||||
|
||||
void SysTraceSendExternalName( uint64_t thread )
|
||||
{
|
||||
const auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, thread );
|
||||
if( hnd != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
const auto pid = GetProcessIdOfThread( hnd );
|
||||
CloseHandle( hnd );
|
||||
if( pid != 0 )
|
||||
{
|
||||
const auto phnd = OpenProcess( PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid );
|
||||
if( phnd != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
char buf[1024];
|
||||
const auto sz = GetProcessImageFileNameA( phnd, buf, 1024 );
|
||||
CloseHandle( phnd );
|
||||
if( sz != 0 )
|
||||
{
|
||||
auto ptr = buf + sz - 1;
|
||||
while( ptr > buf && *ptr != '\\' ) ptr--;
|
||||
if( *ptr == '\\' ) ptr++;
|
||||
GetProfiler().SendString( thread, ptr, QueueType::ExternalName );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GetProfiler().SendString( thread, "???", QueueType::ExternalName );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# elif defined __linux__
|
||||
@@ -163,7 +193,6 @@ void SysTraceWorker( void* ptr )
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
# include <stdint.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
@@ -342,6 +371,12 @@ void SysTraceWorker( void* ptr )
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
void SysTraceSendExternalName( uint64_t thread )
|
||||
{
|
||||
// TODO
|
||||
GetProfiler().SendString( thread, "???", QueueType::ExternalName );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#ifdef TRACY_HAS_SYSTEM_TRACING
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
@@ -14,6 +16,8 @@ bool SysTraceStart();
|
||||
void SysTraceStop();
|
||||
void SysTraceWorker( void* ptr );
|
||||
|
||||
void SysTraceSendExternalName( uint64_t thread );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user