mirror of
https://github.com/wolfpld/tracy
synced 2025-05-01 05:03:53 +00:00
Check if there's data to read from kernel.
Reading from kernel pipe, while being a blocking operation, spin locks the thread.
This commit is contained in:
parent
8f6e94d75c
commit
1e74a89924
@ -320,6 +320,8 @@ void SysTraceSendExternalName( uint64_t thread )
|
|||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <inttypes.h>
|
# include <inttypes.h>
|
||||||
|
# include <limits>
|
||||||
|
# include <poll.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
@ -674,24 +676,43 @@ void SysTraceWorker( void* ptr )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void ProcessTraceLines( FILE* f )
|
static void ProcessTraceLines( int fd )
|
||||||
{
|
{
|
||||||
size_t lsz = 1024;
|
char* buf = (char*)tracy_malloc( 64*1024 );
|
||||||
auto line = (char*)malloc( lsz );
|
|
||||||
|
struct pollfd pfd;
|
||||||
|
pfd.fd = fd;
|
||||||
|
pfd.events = POLLIN | POLLERR;
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
auto rd = getline( &line, &lsz, f );
|
while( poll( &pfd, 1, 0 ) <= 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
||||||
if( rd < 0 ) break;
|
|
||||||
|
const auto rd = read( fd, buf, 64*1024 );
|
||||||
|
if( rd <= 0 ) break;
|
||||||
|
|
||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
if( !GetProfiler().IsConnected() ) continue;
|
if( !GetProfiler().IsConnected() ) continue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HandleTraceLine( line );
|
auto line = buf;
|
||||||
|
const auto end = buf + rd;
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
auto next = line;
|
||||||
|
while( next < end && *next != '\n' ) next++;
|
||||||
|
next++;
|
||||||
|
if( next >= end )
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( line );
|
HandleTraceLine( line );
|
||||||
|
line = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tracy_free( buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SysTraceWorker( void* ptr )
|
void SysTraceWorker( void* ptr )
|
||||||
@ -701,10 +722,10 @@ void SysTraceWorker( void* ptr )
|
|||||||
memcpy( tmp, BasePath, sizeof( BasePath ) - 1 );
|
memcpy( tmp, BasePath, sizeof( BasePath ) - 1 );
|
||||||
memcpy( tmp + sizeof( BasePath ) - 1, TracePipe, sizeof( TracePipe ) );
|
memcpy( tmp + sizeof( BasePath ) - 1, TracePipe, sizeof( TracePipe ) );
|
||||||
|
|
||||||
FILE* f = fopen( tmp, "rb" );
|
int fd = open( tmp, O_RDONLY );
|
||||||
if( !f ) return;
|
if( fd < 0 ) return;
|
||||||
ProcessTraceLines( f );
|
ProcessTraceLines( fd );
|
||||||
fclose( f );
|
close( fd );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user