Skip to content

Commit 217bdcf

Browse files
authored
Merge pull request #1343 from siliceum/fix/better-tracefs-detection
Better tracefs detection
2 parents 25f09be + 4aac9e6 commit 217bdcf

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

public/client/TracySysTrace.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,27 @@ static char* GetTraceFsPath()
558558
char* ret = nullptr;
559559
while( auto ent = getmntent( f ) )
560560
{
561-
if( strcmp( ent->mnt_fsname, "tracefs" ) == 0 )
561+
if( strcmp( ent->mnt_type, "tracefs" ) == 0 )
562562
{
563563
auto len = strlen( ent->mnt_dir );
564-
ret = (char*)tracy_malloc( len + 1 );
564+
// ret may be != nullptr if we already saw a debugfs entry
565+
ret = (char*)tracy_realloc( ret, len + 1 );
565566
memcpy( ret, ent->mnt_dir, len );
566567
ret[len] = '\0';
567568
break;
568569
}
570+
else if( !ret && strcmp( ent->mnt_type, "debugfs" ) == 0 )
571+
{
572+
const char* tracingDirName = "tracing";
573+
const size_t tracingDirNameLen = strlen( tracingDirName );
574+
auto debugFsPathLen = strlen( ent->mnt_dir );
575+
ret = (char*)tracy_malloc( debugFsPathLen + 1 + tracingDirNameLen + 1 );
576+
memcpy( ret, ent->mnt_dir, debugFsPathLen );
577+
ret[debugFsPathLen] = '/';
578+
memcpy( ret + debugFsPathLen + 1, tracingDirName, tracingDirNameLen );
579+
ret[debugFsPathLen + 1 + tracingDirNameLen] = '\0';
580+
// Don't break to allow for tracefs to be found later as it is the preferred path
581+
}
569582
}
570583
endmntent( f );
571584
return ret;
@@ -578,15 +591,21 @@ bool SysTraceStart( int64_t& samplingPeriod )
578591
#endif
579592

580593
const auto paranoidLevelStr = ReadFile( "/proc/sys/kernel/perf_event_paranoid" );
581-
if( !paranoidLevelStr ) return false;
582-
#ifdef TRACY_VERBOSE
583-
int paranoidLevel = 2;
584-
paranoidLevel = atoi( paranoidLevelStr );
594+
if( !paranoidLevelStr )
595+
{
596+
TracyDebug( "Failed to read perf_event_paranoid, cannot setup system tracing." );
597+
return false;
598+
}
599+
600+
const int paranoidLevel = atoi( paranoidLevelStr );
585601
TracyDebug( "perf_event_paranoid: %i", paranoidLevel );
586-
#endif
587602

588603
auto traceFsPath = GetTraceFsPath();
589-
if( !traceFsPath ) return false;
604+
if( !traceFsPath )
605+
{
606+
TracyDebug( "Failed to get tracefs path, cannot setup system tracing." );
607+
return false;
608+
}
590609
TracyDebug( "tracefs path: %s", traceFsPath );
591610

592611
int switchId = -1, wakingId = -1, vsyncId = -1;

0 commit comments

Comments
 (0)