mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-21 10:38:24 +00:00
Retrieve tracefs mount path.
This commit is contained in:
@@ -757,6 +757,64 @@ static const char* ReadFile( const char* path )
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static const char* ReadFile( const char* base, const char* path )
|
||||
{
|
||||
const auto blen = strlen( base );
|
||||
const auto plen = strlen( path );
|
||||
|
||||
auto tmp = (char*)tracy_malloc( blen + plen + 1 );
|
||||
memcpy( tmp, base, blen );
|
||||
memcpy( tmp + blen, path, plen );
|
||||
tmp[blen+plen] = '\0';
|
||||
|
||||
auto res = ReadFile( tmp );
|
||||
tracy_free( tmp );
|
||||
return res;
|
||||
}
|
||||
|
||||
static char* GetTraceFsPath()
|
||||
{
|
||||
int fd = open( "/proc/mounts", O_RDONLY );
|
||||
if( fd < 0 ) return nullptr;
|
||||
|
||||
constexpr size_t BufSize = 64 * 1024;
|
||||
auto tmp = (char*)tracy_malloc( BufSize );
|
||||
const auto cnt = read( fd, tmp, BufSize-1 );
|
||||
close( fd );
|
||||
if( cnt < 0 )
|
||||
{
|
||||
tracy_free( tmp );
|
||||
return nullptr;
|
||||
}
|
||||
tmp[cnt] = '\0';
|
||||
|
||||
auto ptr = tmp;
|
||||
while( *ptr )
|
||||
{
|
||||
if( strncmp( ptr, "tracefs ", 8 ) == 0 )
|
||||
{
|
||||
ptr += 8;
|
||||
auto end = ptr;
|
||||
while( *end && *end != ' ' ) end++;
|
||||
if( !*end )
|
||||
{
|
||||
tracy_free( tmp );
|
||||
return nullptr;
|
||||
}
|
||||
const auto len = end - ptr;
|
||||
auto ret = (char*)tracy_malloc( len+1 );
|
||||
memcpy( ret, ptr, len );
|
||||
ret[len] = '\0';
|
||||
return ret;
|
||||
}
|
||||
while( *ptr && *ptr != '\n' ) ptr++;
|
||||
if( *ptr ) ptr++;
|
||||
}
|
||||
|
||||
tracy_free( tmp );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SysTraceStart( int64_t& samplingPeriod )
|
||||
{
|
||||
#ifndef CLOCK_MONOTONIC_RAW
|
||||
@@ -771,14 +829,20 @@ bool SysTraceStart( int64_t& samplingPeriod )
|
||||
TracyDebug( "perf_event_paranoid: %i\n", paranoidLevel );
|
||||
#endif
|
||||
|
||||
auto traceFsPath = GetTraceFsPath();
|
||||
if( !traceFsPath ) return false;
|
||||
TracyDebug( "tracefs path: %s\n", traceFsPath );
|
||||
|
||||
int switchId = -1, wakingId = -1, vsyncId = -1;
|
||||
const auto switchIdStr = ReadFile( "/sys/kernel/debug/tracing/events/sched/sched_switch/id" );
|
||||
const auto switchIdStr = ReadFile( traceFsPath, "/events/sched/sched_switch/id" );
|
||||
if( switchIdStr ) switchId = atoi( switchIdStr );
|
||||
const auto wakingIdStr = ReadFile( "/sys/kernel/debug/tracing/events/sched/sched_waking/id" );
|
||||
const auto wakingIdStr = ReadFile( traceFsPath, "/events/sched/sched_waking/id" );
|
||||
if( wakingIdStr ) wakingId = atoi( wakingIdStr );
|
||||
const auto vsyncIdStr = ReadFile( "/sys/kernel/debug/tracing/events/drm/drm_vblank_event/id" );
|
||||
const auto vsyncIdStr = ReadFile( traceFsPath, "/events/drm/drm_vblank_event/id" );
|
||||
if( vsyncIdStr ) vsyncId = atoi( vsyncIdStr );
|
||||
|
||||
tracy_free( traceFsPath );
|
||||
|
||||
TracyDebug( "sched_switch id: %i\n", switchId );
|
||||
TracyDebug( "sched_waking id: %i\n", wakingId );
|
||||
TracyDebug( "drm_vblank_event id: %i\n", vsyncId );
|
||||
|
||||
Reference in New Issue
Block a user